Skip to content

Commit

Permalink
Merge branch 'main' into fix/profile-measurement-types
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanosiano authored Dec 5, 2022
2 parents 1b726ae + f122116 commit 97634f7
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 71 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Fixes

- Updated ProfileMeasurementValue types ([#2412](https://github.com/getsentry/sentry-java/pull/2412))
- No longer disable OpenTelemetry exporters in default Java Agent config ([#2408](https://github.com/getsentry/sentry-java/pull/2408))
- Fix `ClassNotFoundException` for `io.sentry.spring.SentrySpringServletContainerInitializer` in `sentry-spring-jakarta` ([#2411](https://github.com/getsentry/sentry-java/issues/2411))
- Fix `sentry-samples-spring-jakarta` ([#2411](https://github.com/getsentry/sentry-java/issues/2411))

## 6.9.1

Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ object Config {
val androidxRecylerView = "androidx.recyclerview:recyclerview:1.2.1"

val slf4jApi = "org.slf4j:slf4j-api:1.7.30"
val slf4jApi2 = "org.slf4j:slf4j-api:2.0.5"
val slf4jJdk14 = "org.slf4j:slf4j-jdk14:1.7.30"
val logbackVersion = "1.2.9"
val logbackClassic = "ch.qos.logback:logback-classic:$logbackVersion"
Expand All @@ -67,6 +68,8 @@ object Config {
val log4j2Api = "org.apache.logging.log4j:log4j-api:$log4j2Version"
val log4j2Core = "org.apache.logging.log4j:log4j-core:$log4j2Version"

val jacksonDatabind = "com.fasterxml.jackson.core:jackson-databind"

val springBootStarter = "org.springframework.boot:spring-boot-starter:$springBootVersion"
val springBootStarterTest = "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
val springBootStarterWeb = "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.os.Debug;
import android.os.Process;
Expand Down Expand Up @@ -61,7 +60,6 @@ final class AndroidTransactionProfiler implements ITransactionProfiler {
private final @NotNull SentryAndroidOptions options;
private final @NotNull IHub hub;
private final @NotNull BuildInfoProvider buildInfoProvider;
private final @Nullable PackageInfo packageInfo;
private long transactionStartNanos = 0;
private long profileStartCpuMillis = 0;
private boolean isInitialized = false;
Expand Down Expand Up @@ -103,7 +101,6 @@ public AndroidTransactionProfiler(
Objects.requireNonNull(frameMetricsCollector, "SentryFrameMetricsCollector is required");
this.buildInfoProvider =
Objects.requireNonNull(buildInfoProvider, "The BuildInfoProvider is required.");
this.packageInfo = ContextUtils.getPackageInfo(context, options.getLogger(), buildInfoProvider);
}

private void init() {
Expand Down Expand Up @@ -322,14 +319,8 @@ private void onLastTransactionFinished(final ITransaction transaction, final boo
return;
}

String versionName = "";
String versionCode = "";
String totalMem = "0";
ActivityManager.MemoryInfo memInfo = getMemInfo();
if (packageInfo != null) {
versionName = ContextUtils.getVersionName(packageInfo);
versionCode = ContextUtils.getVersionCode(packageInfo, buildInfoProvider);
}
if (memInfo != null) {
totalMem = Long.toString(memInfo.totalMem);
}
Expand Down Expand Up @@ -379,8 +370,7 @@ private void onLastTransactionFinished(final ITransaction transaction, final boo
buildInfoProvider.isEmulator(),
totalMem,
options.getProguardUuid(),
versionName,
versionCode,
options.getRelease(),
options.getEnvironment(),
isTimeout
? ProfilingTraceData.TRUNCATION_REASON_TIMEOUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,20 @@ class AndroidTransactionProfilerTest {
}

@Test
fun `profiling trace data contains release field`() {
val profiler = fixture.getSut(context)
profiler.onTransactionStart(fixture.transaction1)
profiler.onTransactionFinish(fixture.transaction1)
verify(fixture.hub).captureEnvelope(
check {
assertEnvelopeItem<ProfilingTraceData>(it.items.toList()) { _, item ->
assertEquals(fixture.options.release, item.release)
assertNotNull(item.release)
}
}
)
}

fun `profiler starts collecting frame metrics when the first transaction starts`() {
val profiler = fixture.getSut(context)
profiler.onTransactionStart(fixture.transaction1)
Expand Down
22 changes: 22 additions & 0 deletions sentry-opentelemetry/sentry-opentelemetry-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,25 @@ To enable debug logging for Sentry, please provide `SENTRY_DEBUG=true` as enviro
add `debug=true` to your `sentry.properties`.

To also show debug output for OpenTelemetry please add `-Dotel.javaagent.debug=true` to the command.

## Getting rid of exporter error messages

In case you are using this agent without needing to use any OpenTelemetry exporters you can add
the following environment variables to turn off exporters and stop seeing error messages about
servers not being reachable in the logs.

Example log message:
```
ERROR io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter - Failed to export spans. The request could not be executed. Full error message: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:4317
ERROR io.opentelemetry.exporter.internal.grpc.OkHttpGrpcExporter - Failed to export metrics. The request could not be executed. Full error message: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:4317
```

### Traces

To turn off exporting of traces you can set `OTEL_TRACES_EXPORTER=none`
see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters)

### Metrics

To turn off exporting of metrics you can set `OTEL_METRICS_EXPORTER=none`
see [OpenTelemetry GitHub](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure#otlp-exporter-span-metric-and-log-exporters)
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ private SdkTracerProviderBuilder configureSdkTracerProvider(

private Map<String, String> getDefaultProperties() {
Map<String, String> properties = new HashMap<>();
properties.put("otel.traces.exporter", "none");
properties.put("otel.metrics.exporter", "none");
properties.put("otel.propagators", "sentry");
return properties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ dependencies {
jakartaTransform("org.eclipse.transformer:org.eclipse.transformer.cli:0.5.0")
jakartaTransform("org.eclipse.transformer:org.eclipse.transformer.jakarta:0.5.0")

implementation(Config.Libs.servletApi)
implementation(Config.Libs.servletApiJakarta)
implementation(Config.Libs.springWeb)
implementation(Config.Libs.springAop)
implementation(Config.Libs.aspectj)
implementation(Config.Libs.springSecurityWeb)
implementation(Config.Libs.springSecurityConfig)
implementation(Config.Libs.logbackClassic)
implementation(Config.Libs.slf4jApi2)
implementation(Config.Libs.jacksonDatabind)
implementation(Config.Libs.kotlinReflect)
implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))
implementation(projects.sentrySpringJakarta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
Expand All @@ -12,6 +13,7 @@
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration {

// this API is meant to be consumed by non-browser clients thus the CSRF protection is not needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ComponentScan("io.sentry.samples.spring.web")
@ComponentScan("io.sentry.samples.spring.jakarta")
@EnableWebMvc
public class WebConfig {

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.sentry.spring.SentrySpringServletContainerInitializer
io.sentry.spring.jakarta.SentrySpringServletContainerInitializer
10 changes: 4 additions & 6 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ public final class io/sentry/ProfilingTraceData : io/sentry/JsonSerializable, io
public static final field TRUNCATION_REASON_NORMAL Ljava/lang/String;
public static final field TRUNCATION_REASON_TIMEOUT Ljava/lang/String;
public fun <init> (Ljava/io/File;Lio/sentry/ITransaction;)V
public fun <init> (Ljava/io/File;Ljava/util/List;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;Ljava/lang/String;Ljava/util/Map;)V
public fun <init> (Ljava/io/File;Ljava/util/List;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;Ljava/util/Map;)V
public fun getAndroidApiLevel ()I
public fun getBuildId ()Ljava/lang/String;
public fun getCpuArchitecture ()Ljava/lang/String;
Expand All @@ -853,6 +853,7 @@ public final class io/sentry/ProfilingTraceData : io/sentry/JsonSerializable, io
public fun getMeasurementsMap ()Ljava/util/Map;
public fun getPlatform ()Ljava/lang/String;
public fun getProfileId ()Ljava/lang/String;
public fun getRelease ()Ljava/lang/String;
public fun getSampledProfile ()Ljava/lang/String;
public fun getTraceFile ()Ljava/io/File;
public fun getTraceId ()Ljava/lang/String;
Expand All @@ -861,8 +862,6 @@ public final class io/sentry/ProfilingTraceData : io/sentry/JsonSerializable, io
public fun getTransactions ()Ljava/util/List;
public fun getTruncationReason ()Ljava/lang/String;
public fun getUnknown ()Ljava/util/Map;
public fun getVersionCode ()Ljava/lang/String;
public fun getVersionName ()Ljava/lang/String;
public fun isDeviceIsEmulator ()Z
public fun readDeviceCpuFrequencies ()V
public fun serialize (Lio/sentry/JsonObjectWriter;Lio/sentry/ILogger;)V
Expand All @@ -880,15 +879,14 @@ public final class io/sentry/ProfilingTraceData : io/sentry/JsonSerializable, io
public fun setDurationNs (Ljava/lang/String;)V
public fun setEnvironment (Ljava/lang/String;)V
public fun setProfileId (Ljava/lang/String;)V
public fun setRelease (Ljava/lang/String;)V
public fun setSampledProfile (Ljava/lang/String;)V
public fun setTraceId (Ljava/lang/String;)V
public fun setTransactionId (Ljava/lang/String;)V
public fun setTransactionName (Ljava/lang/String;)V
public fun setTransactions (Ljava/util/List;)V
public fun setTruncationReason (Ljava/lang/String;)V
public fun setUnknown (Ljava/util/Map;)V
public fun setVersionCode (Ljava/lang/String;)V
public fun setVersionName (Ljava/lang/String;)V
}

public final class io/sentry/ProfilingTraceData$Deserializer : io/sentry/JsonDeserializer {
Expand All @@ -915,14 +913,14 @@ public final class io/sentry/ProfilingTraceData$JsonKeys {
public static final field MEASUREMENTS Ljava/lang/String;
public static final field PLATFORM Ljava/lang/String;
public static final field PROFILE_ID Ljava/lang/String;
public static final field RELEASE Ljava/lang/String;
public static final field SAMPLED_PROFILE Ljava/lang/String;
public static final field TRACE_ID Ljava/lang/String;
public static final field TRANSACTION_ID Ljava/lang/String;
public static final field TRANSACTION_LIST Ljava/lang/String;
public static final field TRANSACTION_NAME Ljava/lang/String;
public static final field TRUNCATION_REASON Ljava/lang/String;
public static final field VERSION_CODE Ljava/lang/String;
public static final field VERSION_NAME Ljava/lang/String;
public fun <init> ()V
}

Expand Down
72 changes: 31 additions & 41 deletions sentry/src/main/java/io/sentry/ProfilingTraceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public final class ProfilingTraceData implements JsonUnknown, JsonSerializable {
private @NotNull String durationNs;

// App info
private @NotNull String versionName;
private @NotNull String versionCode;
private @NotNull String release;

// Stacktrace context
private @NotNull String transactionId;
Expand Down Expand Up @@ -93,29 +93,27 @@ public ProfilingTraceData(
null,
null,
null,
null,
TRUNCATION_REASON_NORMAL,
new HashMap<>());
}

public ProfilingTraceData(
final @NotNull File traceFile,
final @NotNull List<ProfilingTransactionData> transactions,
final @NotNull ITransaction transaction,
final @NotNull String durationNanos,
final int sdkInt,
final @NotNull String cpuArchitecture,
final @NotNull Callable<List<Integer>> deviceCpuFrequenciesReader,
final @Nullable String deviceManufacturer,
final @Nullable String deviceModel,
final @Nullable String deviceOsVersion,
final @Nullable Boolean deviceIsEmulator,
final @Nullable String devicePhysicalMemoryBytes,
final @Nullable String buildId,
final @Nullable String versionName,
final @Nullable String versionCode,
final @Nullable String environment,
final @NotNull String truncationReason,
@NotNull File traceFile,
@NotNull List<ProfilingTransactionData> transactions,
@NotNull ITransaction transaction,
@NotNull String durationNanos,
int sdkInt,
@NotNull String cpuArchitecture,
@NotNull Callable<List<Integer>> deviceCpuFrequenciesReader,
@Nullable String deviceManufacturer,
@Nullable String deviceModel,
@Nullable String deviceOsVersion,
@Nullable Boolean deviceIsEmulator,
@Nullable String devicePhysicalMemoryBytes,
@Nullable String buildId,
@Nullable String release,
@Nullable String environment,
@NotNull String truncationReason,
final @NotNull Map<String, ProfileMeasurement> measurementsMap) {
this.traceFile = traceFile;
this.cpuArchitecture = cpuArchitecture;
Expand All @@ -141,8 +139,8 @@ public ProfilingTraceData(
this.durationNs = durationNanos;

// App info
this.versionName = versionName != null ? versionName : "";
this.versionCode = versionCode != null ? versionCode : "";
this.versionCode = "";
this.release = release != null ? release : "";

// Stacktrace context
this.transactionId = transaction.getEventId().toString();
Expand Down Expand Up @@ -216,12 +214,8 @@ public boolean isDeviceIsEmulator() {
return transactionName;
}

public @NotNull String getVersionName() {
return versionName;
}

public @NotNull String getVersionCode() {
return versionCode;
public @NotNull String getRelease() {
return release;
}

public @NotNull String getTransactionId() {
Expand Down Expand Up @@ -328,12 +322,8 @@ public void setDurationNs(final @NotNull String durationNs) {
this.durationNs = durationNs;
}

public void setVersionName(final @NotNull String versionName) {
this.versionName = versionName;
}

public void setVersionCode(final @NotNull String versionCode) {
this.versionCode = versionCode;
public void setRelease(@NotNull String release) {
this.release = release;
}

public void setTransactionId(final @NotNull String transactionId) {
Expand Down Expand Up @@ -382,7 +372,7 @@ public static final class JsonKeys {
public static final String BUILD_ID = "build_id";
public static final String TRANSACTION_NAME = "transaction_name";
public static final String DURATION_NS = "duration_ns";
public static final String VERSION_NAME = "version_name";
public static final String RELEASE = "version_name";
public static final String VERSION_CODE = "version_code";
public static final String TRANSACTION_LIST = "transactions";
public static final String TRANSACTION_ID = "transaction_id";
Expand Down Expand Up @@ -414,7 +404,7 @@ public void serialize(final @NotNull JsonObjectWriter writer, final @NotNull ILo
writer.name(JsonKeys.BUILD_ID).value(buildId);
writer.name(JsonKeys.TRANSACTION_NAME).value(transactionName);
writer.name(JsonKeys.DURATION_NS).value(durationNs);
writer.name(JsonKeys.VERSION_NAME).value(versionName);
writer.name(JsonKeys.RELEASE).value(release);
writer.name(JsonKeys.VERSION_CODE).value(versionCode);
if (!transactions.isEmpty()) {
writer.name(JsonKeys.TRANSACTION_LIST).value(logger, transactions);
Expand Down Expand Up @@ -552,18 +542,18 @@ public static final class Deserializer implements JsonDeserializer<ProfilingTrac
data.durationNs = durationNs;
}
break;
case JsonKeys.VERSION_NAME:
String versionName = reader.nextStringOrNull();
if (versionName != null) {
data.versionName = versionName;
}
break;
case JsonKeys.VERSION_CODE:
String versionCode = reader.nextStringOrNull();
if (versionCode != null) {
data.versionCode = versionCode;
}
break;
case JsonKeys.RELEASE:
String versionName = reader.nextStringOrNull();
if (versionName != null) {
data.release = versionName;
}
break;
case JsonKeys.TRANSACTION_LIST:
List<ProfilingTransactionData> transactions =
reader.nextList(logger, new ProfilingTransactionData.Deserializer());
Expand Down
Loading

0 comments on commit 97634f7

Please sign in to comment.