Skip to content

Commit

Permalink
Merge branch 'feat/otel-span-strongref' into feat/close-backpressure-…
Browse files Browse the repository at this point in the history
…monitor
  • Loading branch information
adinauer authored Dec 19, 2024
2 parents 6eac0cc + f3056ff commit f38e361
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 17 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@
- To enable the auto configuration of it, please set `-Dotel.java.global-autoconfigure.enabled=true` on the `java` command, when starting your application.
- You may also want to set `OTEL_LOGS_EXPORTER=none;OTEL_METRICS_EXPORTER=none;OTEL_TRACES_EXPORTER=none` env vars to not have the log flooded with error messages regarding OpenTelemetry features we don't use.
- `OpenTelemetryUtil.applyOpenTelemetryOptions` now takes an enum instead of a boolean for its mode
- Use `AGENT` when using `sentry-opentelemetry-agent`
- Use `AGENTLESS` when using `sentry-opentelemetry-agentless`
- Use `AGENTLESS_SPRING` when using `sentry-opentelemetry-agentless-spring`
- Add `openTelemetryMode` option ([#3994](https://github.com/getsentry/sentry-java/pull/3994))
- It defaults to `AUTO` meaning the SDK will figure out how to best configure itself for use with OpenTelemetry
- Use of OpenTelemetry can also be disabled completely by setting it to `OFF` ([#3995](https://github.com/getsentry/sentry-java/pull/3995))
- In this case even if OpenTelemetry is present, the Sentry SDK will not use it
- Use `AGENT` when using `sentry-opentelemetry-agent`
- Use `AGENTLESS` when using `sentry-opentelemetry-agentless`
- Use `AGENTLESS_SPRING` when using `sentry-opentelemetry-agentless-spring`

### Fixes

- Replace deprecated `SimpleInstrumentation` with `SimplePerformantInstrumentation` for graphql 22 ([#3974](https://github.com/getsentry/sentry-java/pull/3974))
- Cache requests for Spring using Springs `ContentCachingRequestWrapper` instead of our own Wrapper to also cache parameters ([#3641](https://github.com/getsentry/sentry-java/pull/3641))
- Previously only the body was cached which could lead to problems in the FilterChain as Request parameters were not available
- We now hold a strong reference to the underlying OpenTelemetry span when it is created through Sentry API ([#3997](https://github.com/getsentry/sentry-java/pull/3997))
- This keeps it from being garbage collected too early

## 8.0.0-rc.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ class EnvelopeFileObserverIntegrationTest {

@AfterTest
fun shutdown() {
Files.delete(file.toPath())
delete(file)
}

private fun delete(f: File) {
f.listFiles()?.forEach { delete(it) }
Files.delete(f.toPath())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import io.sentry.Sentry;
import io.sentry.SentryEvent;
import io.sentry.SentryLevel;
import io.sentry.SentryOpenTelemetryMode;
import io.sentry.SpanStatus;
import io.sentry.opentelemetry.OpenTelemetryUtil;
import io.sentry.protocol.Message;
import io.sentry.protocol.User;
import java.util.Collections;
Expand All @@ -30,8 +28,6 @@ public static void main(String[] args) throws InterruptedException {
options.setDsn(
"https://[email protected]/5428563");

OpenTelemetryUtil.applyOpenTelemetryOptions(options, SentryOpenTelemetryMode.AGENTLESS);

// All events get assigned to the release. See more at
// https://docs.sentry.io/workflow/releases/
options.setRelease("[email protected]+1");
Expand Down
2 changes: 2 additions & 0 deletions sentry-test-support/src/main/kotlin/io/sentry/test/Mocks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.sentry.ISentryClient
import io.sentry.ISentryExecutorService
import io.sentry.Scope
import io.sentry.Scopes
import io.sentry.Sentry
import io.sentry.SentryOptions
import io.sentry.backpressure.IBackpressureMonitor
import org.mockito.kotlin.any
Expand Down Expand Up @@ -83,6 +84,7 @@ fun createSentryClientMock(enabled: Boolean = true) = mock<ISentryClient>().also

fun createTestScopes(options: SentryOptions? = null, enabled: Boolean = true, scope: IScope? = null, isolationScope: IScope? = null, globalScope: IScope? = null): Scopes {
val optionsToUse = options ?: SentryOptions().also { it.dsn = "https://[email protected]/proj" }
Sentry.init(optionsToUse)
val scopeToUse = scope ?: Scope(optionsToUse)
val isolationScopeToUse = isolationScope ?: Scope(optionsToUse)
val globalScopeToUse = globalScope ?: Scope(optionsToUse)
Expand Down
22 changes: 14 additions & 8 deletions sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
final IScope rootIsolationScope = new Scope(options);
rootScopes = new Scopes(rootScope, rootIsolationScope, globalScope, "Sentry.init");

initScopesStorage(options);
initForOpenTelemetryMaybe(options);
getScopesStorage().set(rootScopes);

initConfigurations(options);
Expand Down Expand Up @@ -358,6 +358,19 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
}
}

private static void initForOpenTelemetryMaybe(SentryOptions options) {
if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
options.setSpanFactory(new DefaultSpanFactory());
// } else {
// enabling this causes issues with agentless where OTel spans seem to be randomly ended
// options.setSpanFactory(SpanFactoryFactory.create(new LoadClass(),
// NoOpLogger.getInstance()));
}
initScopesStorage(options);
OpenTelemetryUtil.applyIgnoredSpanOrigins(options, new LoadClass());
}

@SuppressWarnings("UnusedMethod")
private static void initScopesStorage(SentryOptions options) {
getScopesStorage().close();
if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
Expand Down Expand Up @@ -501,13 +514,6 @@ private static void initConfigurations(final @NotNull SentryOptions options) {
}
logger.log(SentryLevel.INFO, "Initializing SDK with DSN: '%s'", options.getDsn());

OpenTelemetryUtil.applyIgnoredSpanOrigins(options, new LoadClass());
if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
options.setSpanFactory(new DefaultSpanFactory());
} else {
options.setSpanFactory(SpanFactoryFactory.create(new LoadClass(), NoOpLogger.getInstance()));
}

// TODO: read values from conf file, Build conf or system envs
// eg release, distinctId, sentryClientName

Expand Down
2 changes: 2 additions & 0 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.sentry.transport.NoOpTransportGate;
import io.sentry.util.AutoClosableReentrantLock;
import io.sentry.util.LazyEvaluator;
import io.sentry.util.LoadClass;
import io.sentry.util.Platform;
import io.sentry.util.SampleRateUtils;
import io.sentry.util.StringUtils;
Expand Down Expand Up @@ -2636,6 +2637,7 @@ public SentryOptions() {
private SentryOptions(final boolean empty) {
experimental = new ExperimentalOptions(empty);
if (!empty) {
setSpanFactory(SpanFactoryFactory.create(new LoadClass(), NoOpLogger.getInstance()));
// SentryExecutorService should be initialized before any
// SendCachedEventFireAndForgetIntegration
executorService = new SentryExecutorService();
Expand Down
4 changes: 4 additions & 0 deletions sentry/src/test/java/io/sentry/HubAdapterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class HubAdapterTest {

@BeforeTest
fun `set up`() {
Sentry.init { options ->
options.dsn = "https://key@host/proj"
options.shutdownTimeoutMillis = 20
}
Sentry.setCurrentScopes(scopes)
}

Expand Down
4 changes: 4 additions & 0 deletions sentry/src/test/java/io/sentry/ScopesAdapterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class ScopesAdapterTest {

@BeforeTest
fun `set up`() {
Sentry.init { options ->
options.dsn = "https://key@host/proj"
options.shutdownTimeoutMillis = 20
}
Sentry.setCurrentScopes(scopes)
}

Expand Down
11 changes: 10 additions & 1 deletion sentry/src/test/java/io/sentry/ScopesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.mockito.kotlin.doThrow
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.reset
import org.mockito.kotlin.spy
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
Expand Down Expand Up @@ -78,7 +79,13 @@ class ScopesTest {

@Test
fun `when no dsn available, ctor throws illegal arg`() {
val ex = assertFailsWith<IllegalArgumentException> { createScopes(SentryOptions()) }
val ex = assertFailsWith<IllegalArgumentException> {
val options = SentryOptions()
val scopeToUse = Scope(options)
val isolationScopeToUse = Scope(options)
val globalScopeToUse = Scope(options)
Scopes(scopeToUse, isolationScopeToUse, globalScopeToUse, "test")
}
assertEquals("Scopes requires a DSN to be instantiated. Considering using the NoOpScopes if no DSN is available.", ex.message)
}

Expand All @@ -91,6 +98,7 @@ class ScopesTest {
options.setSerializer(mock())
options.addIntegration(integrationMock)
val scopes = createScopes(options)
reset(integrationMock)
scopes.forkedScopes("test")
verifyNoMoreInteractions(integrationMock)
}
Expand All @@ -104,6 +112,7 @@ class ScopesTest {
options.setSerializer(mock())
options.addIntegration(integrationMock)
val scopes = createScopes(options)
reset(integrationMock)
scopes.forkedCurrentScope("test")
verifyNoMoreInteractions(integrationMock)
}
Expand Down

0 comments on commit f38e361

Please sign in to comment.