Skip to content

Commit f38e361

Browse files
authored
Merge branch 'feat/otel-span-strongref' into feat/close-backpressure-monitor
2 parents 6eac0cc + f3056ff commit f38e361

File tree

9 files changed

+51
-17
lines changed

9 files changed

+51
-17
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@
99
- To enable the auto configuration of it, please set `-Dotel.java.global-autoconfigure.enabled=true` on the `java` command, when starting your application.
1010
- 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.
1111
- `OpenTelemetryUtil.applyOpenTelemetryOptions` now takes an enum instead of a boolean for its mode
12-
- Use `AGENT` when using `sentry-opentelemetry-agent`
13-
- Use `AGENTLESS` when using `sentry-opentelemetry-agentless`
14-
- Use `AGENTLESS_SPRING` when using `sentry-opentelemetry-agentless-spring`
12+
- Add `openTelemetryMode` option ([#3994](https://github.com/getsentry/sentry-java/pull/3994))
13+
- It defaults to `AUTO` meaning the SDK will figure out how to best configure itself for use with OpenTelemetry
14+
- Use of OpenTelemetry can also be disabled completely by setting it to `OFF` ([#3995](https://github.com/getsentry/sentry-java/pull/3995))
15+
- In this case even if OpenTelemetry is present, the Sentry SDK will not use it
16+
- Use `AGENT` when using `sentry-opentelemetry-agent`
17+
- Use `AGENTLESS` when using `sentry-opentelemetry-agentless`
18+
- Use `AGENTLESS_SPRING` when using `sentry-opentelemetry-agentless-spring`
1519

1620
### Fixes
1721

1822
- Replace deprecated `SimpleInstrumentation` with `SimplePerformantInstrumentation` for graphql 22 ([#3974](https://github.com/getsentry/sentry-java/pull/3974))
1923
- 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))
2024
- Previously only the body was cached which could lead to problems in the FilterChain as Request parameters were not available
25+
- 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))
26+
- This keeps it from being garbage collected too early
2127

2228
## 8.0.0-rc.2
2329

sentry-android-core/src/test/java/io/sentry/android/core/EnvelopeFileObserverIntegrationTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ class EnvelopeFileObserverIntegrationTest {
5252

5353
@AfterTest
5454
fun shutdown() {
55-
Files.delete(file.toPath())
55+
delete(file)
56+
}
57+
58+
private fun delete(f: File) {
59+
f.listFiles()?.forEach { delete(it) }
60+
Files.delete(f.toPath())
5661
}
5762

5863
@Test

sentry-samples/sentry-samples-console-opentelemetry-noagent/src/main/java/io/sentry/samples/console/Main.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import io.sentry.Sentry;
1414
import io.sentry.SentryEvent;
1515
import io.sentry.SentryLevel;
16-
import io.sentry.SentryOpenTelemetryMode;
1716
import io.sentry.SpanStatus;
18-
import io.sentry.opentelemetry.OpenTelemetryUtil;
1917
import io.sentry.protocol.Message;
2018
import io.sentry.protocol.User;
2119
import java.util.Collections;
@@ -30,8 +28,6 @@ public static void main(String[] args) throws InterruptedException {
3028
options.setDsn(
3129
"https://[email protected]/5428563");
3230

33-
OpenTelemetryUtil.applyOpenTelemetryOptions(options, SentryOpenTelemetryMode.AGENTLESS);
34-
3531
// All events get assigned to the release. See more at
3632
// https://docs.sentry.io/workflow/releases/
3733
options.setRelease("[email protected]+1");

sentry-test-support/src/main/kotlin/io/sentry/test/Mocks.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.sentry.ISentryClient
66
import io.sentry.ISentryExecutorService
77
import io.sentry.Scope
88
import io.sentry.Scopes
9+
import io.sentry.Sentry
910
import io.sentry.SentryOptions
1011
import io.sentry.backpressure.IBackpressureMonitor
1112
import org.mockito.kotlin.any
@@ -83,6 +84,7 @@ fun createSentryClientMock(enabled: Boolean = true) = mock<ISentryClient>().also
8384

8485
fun createTestScopes(options: SentryOptions? = null, enabled: Boolean = true, scope: IScope? = null, isolationScope: IScope? = null, globalScope: IScope? = null): Scopes {
8586
val optionsToUse = options ?: SentryOptions().also { it.dsn = "https://[email protected]/proj" }
87+
Sentry.init(optionsToUse)
8688
val scopeToUse = scope ?: Scope(optionsToUse)
8789
val isolationScopeToUse = isolationScope ?: Scope(optionsToUse)
8890
val globalScopeToUse = globalScope ?: Scope(optionsToUse)

sentry/src/main/java/io/sentry/Sentry.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
322322
final IScope rootIsolationScope = new Scope(options);
323323
rootScopes = new Scopes(rootScope, rootIsolationScope, globalScope, "Sentry.init");
324324

325-
initScopesStorage(options);
325+
initForOpenTelemetryMaybe(options);
326326
getScopesStorage().set(rootScopes);
327327

328328
initConfigurations(options);
@@ -358,6 +358,19 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
358358
}
359359
}
360360

361+
private static void initForOpenTelemetryMaybe(SentryOptions options) {
362+
if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
363+
options.setSpanFactory(new DefaultSpanFactory());
364+
// } else {
365+
// enabling this causes issues with agentless where OTel spans seem to be randomly ended
366+
// options.setSpanFactory(SpanFactoryFactory.create(new LoadClass(),
367+
// NoOpLogger.getInstance()));
368+
}
369+
initScopesStorage(options);
370+
OpenTelemetryUtil.applyIgnoredSpanOrigins(options, new LoadClass());
371+
}
372+
373+
@SuppressWarnings("UnusedMethod")
361374
private static void initScopesStorage(SentryOptions options) {
362375
getScopesStorage().close();
363376
if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
@@ -501,13 +514,6 @@ private static void initConfigurations(final @NotNull SentryOptions options) {
501514
}
502515
logger.log(SentryLevel.INFO, "Initializing SDK with DSN: '%s'", options.getDsn());
503516

504-
OpenTelemetryUtil.applyIgnoredSpanOrigins(options, new LoadClass());
505-
if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
506-
options.setSpanFactory(new DefaultSpanFactory());
507-
} else {
508-
options.setSpanFactory(SpanFactoryFactory.create(new LoadClass(), NoOpLogger.getInstance()));
509-
}
510-
511517
// TODO: read values from conf file, Build conf or system envs
512518
// eg release, distinctId, sentryClientName
513519

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.sentry.transport.NoOpTransportGate;
2222
import io.sentry.util.AutoClosableReentrantLock;
2323
import io.sentry.util.LazyEvaluator;
24+
import io.sentry.util.LoadClass;
2425
import io.sentry.util.Platform;
2526
import io.sentry.util.SampleRateUtils;
2627
import io.sentry.util.StringUtils;
@@ -2636,6 +2637,7 @@ public SentryOptions() {
26362637
private SentryOptions(final boolean empty) {
26372638
experimental = new ExperimentalOptions(empty);
26382639
if (!empty) {
2640+
setSpanFactory(SpanFactoryFactory.create(new LoadClass(), NoOpLogger.getInstance()));
26392641
// SentryExecutorService should be initialized before any
26402642
// SendCachedEventFireAndForgetIntegration
26412643
executorService = new SentryExecutorService();

sentry/src/test/java/io/sentry/HubAdapterTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class HubAdapterTest {
1919

2020
@BeforeTest
2121
fun `set up`() {
22+
Sentry.init { options ->
23+
options.dsn = "https://key@host/proj"
24+
options.shutdownTimeoutMillis = 20
25+
}
2226
Sentry.setCurrentScopes(scopes)
2327
}
2428

sentry/src/test/java/io/sentry/ScopesAdapterTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class ScopesAdapterTest {
1919

2020
@BeforeTest
2121
fun `set up`() {
22+
Sentry.init { options ->
23+
options.dsn = "https://key@host/proj"
24+
options.shutdownTimeoutMillis = 20
25+
}
2226
Sentry.setCurrentScopes(scopes)
2327
}
2428

sentry/src/test/java/io/sentry/ScopesTest.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.mockito.kotlin.doThrow
2727
import org.mockito.kotlin.eq
2828
import org.mockito.kotlin.mock
2929
import org.mockito.kotlin.never
30+
import org.mockito.kotlin.reset
3031
import org.mockito.kotlin.spy
3132
import org.mockito.kotlin.times
3233
import org.mockito.kotlin.verify
@@ -78,7 +79,13 @@ class ScopesTest {
7879

7980
@Test
8081
fun `when no dsn available, ctor throws illegal arg`() {
81-
val ex = assertFailsWith<IllegalArgumentException> { createScopes(SentryOptions()) }
82+
val ex = assertFailsWith<IllegalArgumentException> {
83+
val options = SentryOptions()
84+
val scopeToUse = Scope(options)
85+
val isolationScopeToUse = Scope(options)
86+
val globalScopeToUse = Scope(options)
87+
Scopes(scopeToUse, isolationScopeToUse, globalScopeToUse, "test")
88+
}
8289
assertEquals("Scopes requires a DSN to be instantiated. Considering using the NoOpScopes if no DSN is available.", ex.message)
8390
}
8491

@@ -91,6 +98,7 @@ class ScopesTest {
9198
options.setSerializer(mock())
9299
options.addIntegration(integrationMock)
93100
val scopes = createScopes(options)
101+
reset(integrationMock)
94102
scopes.forkedScopes("test")
95103
verifyNoMoreInteractions(integrationMock)
96104
}
@@ -104,6 +112,7 @@ class ScopesTest {
104112
options.setSerializer(mock())
105113
options.addIntegration(integrationMock)
106114
val scopes = createScopes(options)
115+
reset(integrationMock)
107116
scopes.forkedCurrentScope("test")
108117
verifyNoMoreInteractions(integrationMock)
109118
}

0 commit comments

Comments
 (0)