Skip to content

Commit b3cddf5

Browse files
authored
Merge 46930d1 into 68019c1
2 parents 68019c1 + 46930d1 commit b3cddf5

File tree

9 files changed

+45
-17
lines changed

9 files changed

+45
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
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
1212
- 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
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
1416
- Use `AGENT` when using `sentry-opentelemetry-agent`
1517
- Use `AGENTLESS` when using `sentry-opentelemetry-agentless`
1618
- Use `AGENTLESS_SPRING` when using `sentry-opentelemetry-agentless-spring`

sentry-android-core/src/main/java/io/sentry/android/core/AndroidOptionsInitializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.sentry.SendFireAndForgetEnvelopeSender;
1616
import io.sentry.SendFireAndForgetOutboxSender;
1717
import io.sentry.SentryLevel;
18+
import io.sentry.SentryOpenTelemetryMode;
1819
import io.sentry.android.core.cache.AndroidEnvelopeCache;
1920
import io.sentry.android.core.internal.debugmeta.AssetsDebugMetaLoader;
2021
import io.sentry.android.core.internal.gestures.AndroidViewGestureTargetLocator;
@@ -101,7 +102,7 @@ static void loadDefaultAndMetadataOptions(
101102
options.setLogger(logger);
102103

103104
options.setDefaultScopeType(ScopeType.CURRENT);
104-
105+
options.setOpenTelemetryMode(SentryOpenTelemetryMode.OFF);
105106
options.setDateProvider(new SentryAndroidDateProvider());
106107

107108
// set a lower flush timeout on Android to avoid ANRs

sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/it/SentrySpringIntegrationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ open class App {
250250
open fun optionsCallback() = Sentry.OptionsConfiguration<SentryOptions> { options ->
251251
// due to OTel being on the classpath we need to set the default again
252252
options.spanFactory = DefaultSpanFactory()
253-
options.openTelemetryMode = SentryOpenTelemetryMode.ALL_ORIGINS
253+
options.openTelemetryMode = SentryOpenTelemetryMode.OFF
254254
}
255255
}
256256

sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/it/SentrySpringIntegrationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ open class App {
251251
// due to OTel being on the classpath we need to set the default again
252252
options.spanFactory = DefaultSpanFactory()
253253
// to test the actual spring implementation
254-
options.openTelemetryMode = SentryOpenTelemetryMode.ALL_ORIGINS
254+
options.openTelemetryMode = SentryOpenTelemetryMode.OFF
255255
}
256256
}
257257

sentry/api/sentry.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2785,8 +2785,8 @@ public final class io/sentry/SentryOpenTelemetryMode : java/lang/Enum {
27852785
public static final field AGENT Lio/sentry/SentryOpenTelemetryMode;
27862786
public static final field AGENTLESS Lio/sentry/SentryOpenTelemetryMode;
27872787
public static final field AGENTLESS_SPRING Lio/sentry/SentryOpenTelemetryMode;
2788-
public static final field ALL_ORIGINS Lio/sentry/SentryOpenTelemetryMode;
27892788
public static final field AUTO Lio/sentry/SentryOpenTelemetryMode;
2789+
public static final field OFF Lio/sentry/SentryOpenTelemetryMode;
27902790
public static fun valueOf (Ljava/lang/String;)Lio/sentry/SentryOpenTelemetryMode;
27912791
public static fun values ()[Lio/sentry/SentryOpenTelemetryMode;
27922792
}

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public final class Sentry {
4747
private Sentry() {}
4848

4949
// TODO logger?
50-
private static volatile @NotNull IScopesStorage scopesStorage =
51-
ScopesStorageFactory.create(new LoadClass(), NoOpLogger.getInstance());
50+
private static volatile @NotNull IScopesStorage scopesStorage = NoOpScopesStorage.getInstance();
5251

5352
/** The root Scopes or NoOp if Sentry is disabled. */
5453
private static volatile @NotNull IScopes rootScopes = NoOpScopes.getInstance();
@@ -322,6 +321,7 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
322321
final IScope rootIsolationScope = new Scope(options);
323322
rootScopes = new Scopes(rootScope, rootIsolationScope, globalScope, "Sentry.init");
324323

324+
initForOpenTelemetryMaybe(options);
325325
getScopesStorage().set(rootScopes);
326326

327327
initConfigurations(options);
@@ -357,6 +357,28 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
357357
}
358358
}
359359

360+
private static void initForOpenTelemetryMaybe(SentryOptions options) {
361+
if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
362+
options.setSpanFactory(new DefaultSpanFactory());
363+
// } else {
364+
// enabling this causes issues with agentless where OTel spans seem to be randomly ended
365+
// options.setSpanFactory(SpanFactoryFactory.create(new LoadClass(),
366+
// NoOpLogger.getInstance()));
367+
}
368+
initScopesStorage(options);
369+
OpenTelemetryUtil.applyIgnoredSpanOrigins(options, new LoadClass());
370+
}
371+
372+
@SuppressWarnings("UnusedMethod")
373+
private static void initScopesStorage(SentryOptions options) {
374+
getScopesStorage().close();
375+
if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
376+
scopesStorage = new DefaultScopesStorage();
377+
} else {
378+
scopesStorage = ScopesStorageFactory.create(new LoadClass(), options.getLogger());
379+
}
380+
}
381+
360382
@SuppressWarnings("FutureReturnValueIgnored")
361383
private static void handleAppStartProfilingConfig(
362384
final @NotNull SentryOptions options,
@@ -491,8 +513,6 @@ private static void initConfigurations(final @NotNull SentryOptions options) {
491513
}
492514
logger.log(SentryLevel.INFO, "Initializing SDK with DSN: '%s'", options.getDsn());
493515

494-
OpenTelemetryUtil.applyIgnoredSpanOrigins(options, new LoadClass());
495-
496516
// TODO: read values from conf file, Build conf or system envs
497517
// eg release, distinctId, sentryClientName
498518

sentry/src/main/java/io/sentry/SentryOpenTelemetryMode.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
* use it and what way to use it in.
66
*/
77
public enum SentryOpenTelemetryMode {
8-
/** Let the SDK figure out what mode OpenTelemetry is in and whether to even use OpenTelemetry */
9-
AUTO,
108
/**
11-
* For now this only means no span origins will be ignored. This does however not mean, the SDK
12-
* won't try tro use OpenTelemetry if available.
13-
*
14-
* <p>Due to some parts of the SDK being initialized before any config mechanism is available, we
15-
* cannot completely disable the OpenTelemetry parts with this setting.
9+
* Let the SDK figure out what mode OpenTelemetry is in and whether to even use OpenTelemetry This
10+
* is the default for non Android.
1611
*/
17-
ALL_ORIGINS,
12+
AUTO,
13+
/** Do not try to use OpenTelemetry, even if it is available. This is the default for Android. */
14+
OFF,
1815
/** The `sentry-opentelemetry-agent` is used */
1916
AGENT,
2017
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.sentry
33
import io.sentry.protocol.SentryTransaction
44
import io.sentry.protocol.User
55
import io.sentry.test.createSentryClientMock
6+
import io.sentry.test.initForTest
67
import org.mockito.kotlin.any
78
import org.mockito.kotlin.anyOrNull
89
import org.mockito.kotlin.eq
@@ -19,6 +20,9 @@ class HubAdapterTest {
1920

2021
@BeforeTest
2122
fun `set up`() {
23+
initForTest {
24+
it.dsn = "https://key@localhost/proj"
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
@@ -3,6 +3,7 @@ package io.sentry
33
import io.sentry.protocol.SentryTransaction
44
import io.sentry.protocol.User
55
import io.sentry.test.createSentryClientMock
6+
import io.sentry.test.initForTest
67
import org.mockito.kotlin.any
78
import org.mockito.kotlin.anyOrNull
89
import org.mockito.kotlin.eq
@@ -19,6 +20,9 @@ class ScopesAdapterTest {
1920

2021
@BeforeTest
2122
fun `set up`() {
23+
initForTest {
24+
it.dsn = "https://key@localhost/proj"
25+
}
2226
Sentry.setCurrentScopes(scopes)
2327
}
2428

0 commit comments

Comments
 (0)