Skip to content

Commit

Permalink
added cpu architecture and default environment in profiles envelope (#…
Browse files Browse the repository at this point in the history
…2207)

* added cpu architecture in profiles envelope payload
* profiles environment defaults to "production"
  • Loading branch information
stefanosiano committed Aug 5, 2022
1 parent 24d5c4f commit fc6c136
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Weakly reference Activity for transaction finished callback ([#2203](https://github.com/getsentry/sentry-java/pull/2203))
- `attach-screenshot` set on Manual init. didn't work ([#2186](https://github.com/getsentry/sentry-java/pull/2186))
- Remove extra space from `spring.factories` causing issues in old versions of Spring Boot ([#2181](https://github.com/getsentry/sentry-java/pull/2181))
- Added cpu architecture and default environment in profiles envelope ([#2207](https://github.com/getsentry/sentry-java/pull/2207))


### Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public synchronized void onTransactionStart(@NotNull ITransaction transaction) {
if (memInfo != null) {
totalMem = Long.toString(memInfo.totalMem);
}
String[] abis = Build.SUPPORTED_ABIS;

// cpu max frequencies are read with a lambda because reading files is involved, so it will be
// done in the background when the trace file is read
Expand All @@ -235,6 +236,7 @@ public synchronized void onTransactionStart(@NotNull ITransaction transaction) {
transaction,
Long.toString(transactionDurationNanos),
buildInfoProvider.getSdkInfoVersion(),
abis != null && abis.length > 0 ? abis[0] : "",
() -> CpuInfoUtils.getInstance().readMaxFrequencies(),
buildInfoProvider.getManufacturer(),
buildInfoProvider.getModel(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class EnvelopeTests : BaseUiTest() {
assertTrue(transactionItem.transaction == "e2etests")
assertEquals(profilingTraceData.transactionId, transactionItem.eventId.toString())
assertTrue(profilingTraceData.transactionName == "e2etests")
assertTrue(profilingTraceData.environment.isNotEmpty())
assertTrue(profilingTraceData.cpuArchitecture.isNotEmpty())
}
assertNoOtherEnvelopes()
assertNoOtherRequests()
Expand Down
5 changes: 4 additions & 1 deletion sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,10 @@ public final class io/sentry/OutboxSender : io/sentry/IEnvelopeSender {

public final class io/sentry/ProfilingTraceData : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
public fun <init> (Ljava/io/File;Lio/sentry/ITransaction;)V
public fun <init> (Ljava/io/File;Lio/sentry/ITransaction;Ljava/lang/String;ILjava/util/concurrent/Callable;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Ljava/io/File;Lio/sentry/ITransaction;Ljava/lang/String;ILjava/lang/String;Ljava/util/concurrent/Callable;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public fun getAndroidApiLevel ()I
public fun getBuildId ()Ljava/lang/String;
public fun getCpuArchitecture ()Ljava/lang/String;
public fun getDeviceCpuFrequencies ()Ljava/util/List;
public fun getDeviceLocale ()Ljava/lang/String;
public fun getDeviceManufacturer ()Ljava/lang/String;
Expand All @@ -742,6 +743,7 @@ public final class io/sentry/ProfilingTraceData : io/sentry/JsonSerializable, io
public fun serialize (Lio/sentry/JsonObjectWriter;Lio/sentry/ILogger;)V
public fun setAndroidApiLevel (I)V
public fun setBuildId (Ljava/lang/String;)V
public fun setCpuArchitecture (Ljava/lang/String;)V
public fun setDeviceCpuFrequencies (Ljava/util/List;)V
public fun setDeviceIsEmulator (Z)V
public fun setDeviceLocale (Ljava/lang/String;)V
Expand Down Expand Up @@ -770,6 +772,7 @@ public final class io/sentry/ProfilingTraceData$Deserializer : io/sentry/JsonDes

public final class io/sentry/ProfilingTraceData$JsonKeys {
public static final field ANDROID_API_LEVEL Ljava/lang/String;
public static final field ARCHITECTURE Ljava/lang/String;
public static final field BUILD_ID Ljava/lang/String;
public static final field DEVICE_CPU_FREQUENCIES Ljava/lang/String;
public static final field DEVICE_IS_EMULATOR Ljava/lang/String;
Expand Down
28 changes: 27 additions & 1 deletion sentry/src/main/java/io/sentry/ProfilingTraceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
@ApiStatus.Internal
public final class ProfilingTraceData implements JsonUnknown, JsonSerializable {

/**
* Default value for {@link SentryEvent#getEnvironment()} set when both event and {@link
* SentryOptions} do not have the environment field set.
*/
private static final String DEFAULT_ENVIRONMENT = "production";

private @NotNull File traceFile;
private @Nullable Callable<List<Integer>> deviceCpuFrequenciesReader;

Expand All @@ -29,6 +35,7 @@ public final class ProfilingTraceData implements JsonUnknown, JsonSerializable {
private @NotNull String deviceOsName;
private @NotNull String deviceOsVersion;
private boolean deviceIsEmulator;
private @NotNull String cpuArchitecture;
private @NotNull List<Integer> deviceCpuFrequencies = new ArrayList<>();
private @NotNull String devicePhysicalMemoryBytes;
private @NotNull String platform;
Expand Down Expand Up @@ -63,6 +70,7 @@ public ProfilingTraceData(@NotNull File traceFile, @NotNull ITransaction transac
transaction,
"0",
0,
"",
// Don't use method reference. This can cause issues on Android
() -> new ArrayList<>(),
null,
Expand All @@ -81,6 +89,7 @@ public ProfilingTraceData(
@NotNull ITransaction transaction,
@NotNull String durationNanos,
int sdkInt,
@NotNull String cpuArchitecture,
@NotNull Callable<List<Integer>> deviceCpuFrequenciesReader,
@Nullable String deviceManufacturer,
@Nullable String deviceModel,
Expand All @@ -92,6 +101,7 @@ public ProfilingTraceData(
@Nullable String versionCode,
@Nullable String environment) {
this.traceFile = traceFile;
this.cpuArchitecture = cpuArchitecture;
this.deviceCpuFrequenciesReader = deviceCpuFrequenciesReader;

// Device metadata
Expand Down Expand Up @@ -120,7 +130,7 @@ public ProfilingTraceData(
this.transactionId = transaction.getEventId().toString();
this.traceId = transaction.getSpanContext().getTraceId().toString();
this.profileId = UUID.randomUUID().toString();
this.environment = environment != null ? environment : "";
this.environment = environment != null ? environment : DEFAULT_ENVIRONMENT;
}

private @Nullable Map<String, Object> unknown;
Expand All @@ -133,6 +143,10 @@ public int getAndroidApiLevel() {
return androidApiLevel;
}

public @NotNull String getCpuArchitecture() {
return cpuArchitecture;
}

public @NotNull String getDeviceLocale() {
return deviceLocale;
}
Expand Down Expand Up @@ -217,6 +231,10 @@ public void setAndroidApiLevel(int androidApiLevel) {
this.androidApiLevel = androidApiLevel;
}

public void setCpuArchitecture(@NotNull String cpuArchitecture) {
this.cpuArchitecture = cpuArchitecture;
}

public void setDeviceLocale(@NotNull String deviceLocale) {
this.deviceLocale = deviceLocale;
}
Expand Down Expand Up @@ -310,6 +328,7 @@ public static final class JsonKeys {
public static final String DEVICE_OS_NAME = "device_os_name";
public static final String DEVICE_OS_VERSION = "device_os_version";
public static final String DEVICE_IS_EMULATOR = "device_is_emulator";
public static final String ARCHITECTURE = "architecture";
public static final String DEVICE_CPU_FREQUENCIES = "device_cpu_frequencies";
public static final String DEVICE_PHYSICAL_MEMORY_BYTES = "device_physical_memory_bytes";
public static final String PLATFORM = "platform";
Expand Down Expand Up @@ -337,6 +356,7 @@ public void serialize(@NotNull JsonObjectWriter writer, @NotNull ILogger logger)
writer.name(JsonKeys.DEVICE_OS_NAME).value(deviceOsName);
writer.name(JsonKeys.DEVICE_OS_VERSION).value(deviceOsVersion);
writer.name(JsonKeys.DEVICE_IS_EMULATOR).value(deviceIsEmulator);
writer.name(JsonKeys.ARCHITECTURE).value(logger, cpuArchitecture);
// Backend expects the list of frequencies, even if empty
writer.name(JsonKeys.DEVICE_CPU_FREQUENCIES).value(logger, deviceCpuFrequencies);
writer.name(JsonKeys.DEVICE_PHYSICAL_MEMORY_BYTES).value(devicePhysicalMemoryBytes);
Expand Down Expand Up @@ -435,6 +455,12 @@ public static final class Deserializer implements JsonDeserializer<ProfilingTrac
data.deviceIsEmulator = deviceIsEmulator;
}
break;
case JsonKeys.ARCHITECTURE:
String cpuArchitecture = reader.nextStringOrNull();
if (cpuArchitecture != null) {
data.cpuArchitecture = cpuArchitecture;
}
break;
case JsonKeys.DEVICE_CPU_FREQUENCIES:
List<Integer> deviceCpuFrequencies = (List<Integer>) reader.nextObjectOrNull();
if (deviceCpuFrequencies != null) {
Expand Down

0 comments on commit fc6c136

Please sign in to comment.