Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POTEL 11 - Move sampling logic into OTel Sampler #3462

Merged
merged 65 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
305baf5
replace hub with scopes
adinauer Mar 27, 2024
95f5e1b
Add Scopes
adinauer Apr 2, 2024
27f2398
Introduce `IScopes` interface.
adinauer Apr 2, 2024
ce3c14f
Replace `IHub` with `IScopes` in core
adinauer Apr 2, 2024
ce615f4
Replace `IHub` with `IScopes` in android core
adinauer Apr 2, 2024
22ddc00
Replace `IHub` with `IScopes` in android integrations
adinauer Apr 2, 2024
305c217
Replace `IHub` with `IScopes` in apollo integrations
adinauer Apr 2, 2024
da927bc
Replace `IHub` with `IScopes` in okhttp integration
adinauer Apr 2, 2024
8279276
Replace `IHub` with `IScopes` in graphql integration
adinauer Apr 2, 2024
9bfc086
Replace `IHub` with `IScopes` in logging integrations
adinauer Apr 2, 2024
b998e50
Replace `IHub` with `IScopes` in more integrations
adinauer Apr 2, 2024
739827a
Replace `IHub` with `IScopes` in OTel integration
adinauer Apr 2, 2024
69f2d63
Replace `IHub` with `IScopes` in Spring 5 / Spring Boot 2 integrations
adinauer Apr 2, 2024
792d482
Replace `IHub` with `IScopes` in Spring 6 / Spring Boot 3 integrations
adinauer Apr 2, 2024
9bcbce6
Replace `IHub` with `IScopes` in samples
adinauer Apr 2, 2024
3f25a4b
Merge branch 'feat/hsm-13-replacements-in-samples' into feat/hubs-sco…
adinauer Apr 2, 2024
d6fb40a
gitscopes -> github
adinauer Apr 2, 2024
7752bcc
Replace ThreadLocal with ScopesStorage
adinauer Apr 4, 2024
1e329c5
Move client and throwable to span map to scope
adinauer Apr 4, 2024
b0d89ae
Add global scope
adinauer Apr 4, 2024
cdd414a
use global scope in Scopes
adinauer Apr 4, 2024
98da9ff
Implement pushScope popScope and withScope for Scopes
adinauer Apr 4, 2024
2d26033
Add pushIsolationScope; add fork methods to ISCope
adinauer Apr 12, 2024
bbb6700
Use separate scopes for current, isolation and global scope; rename m…
adinauer Apr 12, 2024
c714b21
Allow controlling which scope configureScope uses
adinauer Apr 12, 2024
a474402
Combine scopes
adinauer Apr 12, 2024
ae93e33
Use new API for CRONS integrations
adinauer Apr 12, 2024
b01298b
Add lifecycle helper
adinauer Apr 12, 2024
b64e688
Change spring integrations to use new API
adinauer Apr 12, 2024
d06fc50
Use new API in servlet integrations
adinauer Apr 12, 2024
f0af5c3
Use new API for kotlin coroutines and wrapers for Supplier/Callable
adinauer Apr 12, 2024
2f02001
Discussion TODOs
adinauer Apr 12, 2024
bf4a7bf
Fix breadcrumb ordering
adinauer Apr 15, 2024
62cb91a
Mark TODOS with [HSM]
adinauer Apr 15, 2024
b1630ea
Add getGlobalScope and forkedRootScopes to IScopes
adinauer Apr 16, 2024
136b9ce
Fix EventProcessor ordering on scopes
adinauer Apr 16, 2024
94d54ef
Reuse code in Scopes
adinauer Apr 16, 2024
017599d
No longer replace global scope
adinauer Apr 16, 2024
f4c2b3c
Replace hub occurrences in comments, var names etc.
adinauer Apr 16, 2024
61c9d4a
Implement ScopesTest
adinauer Apr 18, 2024
04f3892
Implement CombinedScopeViewTest
adinauer Apr 18, 2024
840c194
Fix combined contexts
adinauer Apr 19, 2024
ab1c3a6
Use combined scopes for cross platform
adinauer Apr 19, 2024
23506c5
Changes according to reviews of previous PRs
adinauer Apr 23, 2024
c9b6f8b
more
adinauer Apr 23, 2024
696a809
even more
adinauer Apr 23, 2024
847200d
isEnabled checks client instead of having a property on Scopes
adinauer Apr 24, 2024
8e86d3b
Use SentryOptions.empty
adinauer Apr 25, 2024
06db228
Remove Hub
adinauer Apr 25, 2024
37ab4d0
Use OpenTelemetry for Performance and Scopes propagation
adinauer Apr 30, 2024
faef2f8
Promote certain span attributes
adinauer May 2, 2024
c57b2d3
Merge branch '8.x.x' into feat/potel-1-context-forking-and-basics
adinauer May 3, 2024
5b15128
Merge branch '8.x.x' into feat/potel-1-context-forking-and-basics
adinauer May 7, 2024
9d48538
Merge branch 'feat/potel-1-context-forking-and-basics' into feat/pote…
adinauer May 7, 2024
9b900c7
Use OTel in Sentry API
adinauer May 13, 2024
b3919bd
Deduplicate SpanInfo extraction
adinauer May 15, 2024
36ed84a
Forward Sentry API to Sentry through OTel
adinauer May 22, 2024
8f56e3f
Use OTel status for Sentry span API
adinauer May 23, 2024
81982bc
POTel Tracing
adinauer May 28, 2024
fba451c
fix root span detection (remote flag), and scope closing
adinauer May 29, 2024
c787e91
Inherit OTel span IDs when sending to sentry
adinauer May 31, 2024
8c25d81
Fix tracing; parse incoming baggage; add baggage to outgoing
adinauer Jun 3, 2024
ffe1bef
Cleanup
adinauer Jun 5, 2024
a31fc08
Move sampling logic to OTel Sampler
adinauer Jun 6, 2024
ee540fd
Merge branch '8.x.x' into feat/potel-11-otel-sampler
adinauer Jun 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ object Config {
val apolloKotlin = "com.apollographql.apollo3:apollo-runtime:3.8.2"

object OpenTelemetry {
val otelVersion = "1.33.0"
val otelVersion = "1.37.0"
val otelAlphaVersion = "$otelVersion-alpha"
val otelJavaagentVersion = "1.32.0"
val otelJavaagentVersion = "2.3.0"
val otelJavaagentAlphaVersion = "$otelJavaagentVersion-alpha"
val otelSemanticConvetionsVersion = "1.23.1-alpha"

Expand Down Expand Up @@ -199,7 +199,9 @@ object Config {
object QualityPlugins {
object Jacoco {
val version = "0.8.7"
val minimumCoverage = BigDecimal.valueOf(0.6)

// TODO [POTEL] add tests and restore
val minimumCoverage = BigDecimal.valueOf(0.1)
}
val spotless = "com.diffplug.spotless"
val spotlessVersion = "6.11.0"
Expand Down
8 changes: 4 additions & 4 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public final class io/sentry/android/core/ActivityBreadcrumbsIntegration : andro
}

public final class io/sentry/android/core/ActivityFramesTracker {
public fun <init> (Lio/sentry/android/core/LoadClass;Lio/sentry/android/core/SentryAndroidOptions;)V
public fun <init> (Lio/sentry/android/core/LoadClass;Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/core/MainLooperHandler;)V
public fun <init> (Lio/sentry/util/LoadClass;Lio/sentry/android/core/SentryAndroidOptions;)V
public fun <init> (Lio/sentry/util/LoadClass;Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/core/MainLooperHandler;)V
public fun addActivity (Landroid/app/Activity;)V
public fun isFrameMetricsAggregatorAvailable ()Z
public fun setMetrics (Landroid/app/Activity;Lio/sentry/protocol/SentryId;)V
Expand Down Expand Up @@ -209,7 +209,7 @@ public final class io/sentry/android/core/InternalSentrySdk {
public static fun serializeScope (Landroid/content/Context;Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/IScope;)Ljava/util/Map;
}

public final class io/sentry/android/core/LoadClass {
public final class io/sentry/android/core/LoadClass : io/sentry/util/LoadClass {
public fun <init> ()V
public fun isClassAvailable (Ljava/lang/String;Lio/sentry/ILogger;)Z
public fun isClassAvailable (Ljava/lang/String;Lio/sentry/SentryOptions;)Z
Expand Down Expand Up @@ -374,7 +374,7 @@ public final class io/sentry/android/core/TempSensorBreadcrumbsIntegration : and
}

public final class io/sentry/android/core/UserInteractionIntegration : android/app/Application$ActivityLifecycleCallbacks, io/sentry/Integration, java/io/Closeable {
public fun <init> (Landroid/app/Application;Lio/sentry/android/core/LoadClass;)V
public fun <init> (Landroid/app/Application;Lio/sentry/util/LoadClass;)V
public fun close ()V
public fun onActivityCreated (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityDestroyed (Landroid/app/Activity;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class ActivityFramesTracker {
private final @NotNull MainLooperHandler handler;

public ActivityFramesTracker(
final @NotNull LoadClass loadClass,
final @NotNull io.sentry.util.LoadClass loadClass,
final @NotNull SentryAndroidOptions options,
final @NotNull MainLooperHandler handler) {

Expand All @@ -54,13 +54,14 @@ public ActivityFramesTracker(
}

public ActivityFramesTracker(
final @NotNull LoadClass loadClass, final @NotNull SentryAndroidOptions options) {
final @NotNull io.sentry.util.LoadClass loadClass,
final @NotNull SentryAndroidOptions options) {
this(loadClass, options, new MainLooperHandler());
}

@TestOnly
ActivityFramesTracker(
final @NotNull LoadClass loadClass,
final @NotNull io.sentry.util.LoadClass loadClass,
final @NotNull SentryAndroidOptions options,
final @NotNull MainLooperHandler handler,
final @Nullable FrameMetricsAggregator frameMetricsAggregator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static void loadDefaultAndMetadataOptions(
static void initializeIntegrationsAndProcessors(
final @NotNull SentryAndroidOptions options,
final @NotNull Context context,
final @NotNull LoadClass loadClass,
final @NotNull io.sentry.util.LoadClass loadClass,
final @NotNull ActivityFramesTracker activityFramesTracker) {
initializeIntegrationsAndProcessors(
options,
Expand All @@ -133,7 +133,7 @@ static void initializeIntegrationsAndProcessors(
final @NotNull SentryAndroidOptions options,
final @NotNull Context context,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull LoadClass loadClass,
final @NotNull io.sentry.util.LoadClass loadClass,
final @NotNull ActivityFramesTracker activityFramesTracker) {

if (options.getCacheDirPath() != null
Expand Down Expand Up @@ -237,7 +237,7 @@ static void installDefaultIntegrations(
final @NotNull Context context,
final @NotNull SentryAndroidOptions options,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull LoadClass loadClass,
final @NotNull io.sentry.util.LoadClass loadClass,
final @NotNull ActivityFramesTracker activityFramesTracker,
final boolean isFragmentAvailable,
final boolean isTimberAvailable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package io.sentry.android.core;

import io.sentry.ILogger;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/** An Adapter for making Class.forName testable */
public final class LoadClass {
/**
* An Adapter for making Class.forName testable
*
* @deprecated please use {@link io.sentry.util.LoadClass} instead.
*/
@Deprecated
public final class LoadClass extends io.sentry.util.LoadClass {

private final io.sentry.util.LoadClass delegate;

public LoadClass() {
delegate = new io.sentry.util.LoadClass();
}

/**
* Try to load a class via reflection
Expand All @@ -17,30 +27,15 @@ public final class LoadClass {
* @return a Class<?> if it's available, or null
*/
public @Nullable Class<?> loadClass(final @NotNull String clazz, final @Nullable ILogger logger) {
try {
return Class.forName(clazz);
} catch (ClassNotFoundException e) {
if (logger != null) {
logger.log(SentryLevel.DEBUG, "Class not available:" + clazz, e);
}
} catch (UnsatisfiedLinkError e) {
if (logger != null) {
logger.log(SentryLevel.ERROR, "Failed to load (UnsatisfiedLinkError) " + clazz, e);
}
} catch (Throwable e) {
if (logger != null) {
logger.log(SentryLevel.ERROR, "Failed to initialize " + clazz, e);
}
}
return null;
return delegate.loadClass(clazz, logger);
}

public boolean isClassAvailable(final @NotNull String clazz, final @Nullable ILogger logger) {
return loadClass(clazz, logger) != null;
return delegate.isClassAvailable(clazz, logger);
}

public boolean isClassAvailable(
final @NotNull String clazz, final @Nullable SentryOptions options) {
return isClassAvailable(clazz, options != null ? options.getLogger() : null);
return delegate.isClassAvailable(clazz, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static synchronized void init(
Sentry.init(
OptionsContainer.create(SentryAndroidOptions.class),
options -> {
final LoadClass classLoader = new LoadClass();
final io.sentry.util.LoadClass classLoader = new io.sentry.util.LoadClass();
final boolean isTimberUpstreamAvailable =
classLoader.isClassAvailable(TIMBER_CLASS_NAME, options);
final boolean isFragmentUpstreamAvailable =
Expand All @@ -101,7 +101,7 @@ public static synchronized void init(
&& classLoader.isClassAvailable(SENTRY_TIMBER_INTEGRATION_CLASS_NAME, options));

final BuildInfoProvider buildInfoProvider = new BuildInfoProvider(logger);
final LoadClass loadClass = new LoadClass();
final io.sentry.util.LoadClass loadClass = new io.sentry.util.LoadClass();
final ActivityFramesTracker activityFramesTracker =
new ActivityFramesTracker(loadClass, options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class UserInteractionIntegration
private final boolean isAndroidXAvailable;

public UserInteractionIntegration(
final @NotNull Application application, final @NotNull LoadClass classLoader) {
final @NotNull Application application, final @NotNull io.sentry.util.LoadClass classLoader) {
this.application = Objects.requireNonNull(application, "Application is required");
isAndroidXAvailable =
classLoader.isClassAvailable("androidx.core.view.GestureDetectorCompat", options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SentryFragmentLifecycleCallbacksTest {
whenever(span.spanContext).thenReturn(
SpanContext(SentryId.EMPTY_ID, SpanId.EMPTY_ID, "op", null, null)
)
whenever(transaction.startChild(any(), any())).thenReturn(span)
whenever(transaction.startChild(any<String>(), any<String>())).thenReturn(span)
whenever(scope.transaction).thenReturn(transaction)
whenever(scopes.configureScope(any())).thenAnswer {
(it.arguments[0] as ScopeCallback).run(scope)
Expand Down Expand Up @@ -190,7 +190,7 @@ class SentryFragmentLifecycleCallbacksTest {

sut.onFragmentCreated(fixture.fragmentManager, fixture.fragment, savedInstanceState = null)

verify(fixture.transaction, never()).startChild(any(), any())
verify(fixture.transaction, never()).startChild(any<String>(), any<String>())
}

@Test
Expand All @@ -200,10 +200,10 @@ class SentryFragmentLifecycleCallbacksTest {
sut.onFragmentCreated(fixture.fragmentManager, fixture.fragment, savedInstanceState = null)

verify(fixture.transaction).startChild(
check {
check<String> {
assertEquals(SentryFragmentLifecycleCallbacks.FRAGMENT_LOAD_OP, it)
},
check {
check<String> {
assertEquals("androidx.fragment.app.Fragment", it)
}
)
Expand All @@ -215,7 +215,7 @@ class SentryFragmentLifecycleCallbacksTest {

sut.onFragmentCreated(fixture.fragmentManager, fixture.fragment, savedInstanceState = null)

verify(fixture.transaction, never()).startChild(any(), any())
verify(fixture.transaction, never()).startChild(any<String>(), any<String>())
}

@Test
Expand All @@ -225,7 +225,7 @@ class SentryFragmentLifecycleCallbacksTest {
sut.onFragmentCreated(fixture.fragmentManager, fixture.fragment, savedInstanceState = null)
sut.onFragmentCreated(fixture.fragmentManager, fixture.fragment, savedInstanceState = null)

verify(fixture.transaction).startChild(any(), any())
verify(fixture.transaction).startChild(any<String>(), any<String>())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ val upstreamAgent = configurations.create("upstreamAgent") {

dependencies {
bootstrapLibs(projects.sentry)
bootstrapLibs(projects.sentryOpentelemetry.sentryOpentelemetryBootstrap)
javaagentLibs(projects.sentryOpentelemetry.sentryOpentelemetryAgentcustomization)
upstreamAgent(Config.Libs.OpenTelemetry.otelJavaAgent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
exclude(group = "io.opentelemetry")
exclude(group = "io.opentelemetry.javaagent")
}
implementation(projects.sentryOpentelemetry.sentryOpentelemetryBootstrap)

compileOnly(Config.Libs.OpenTelemetry.otelSdk)
compileOnly(Config.Libs.OpenTelemetry.otelExtensionAutoconfigureSpi)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.sentry.opentelemetry;

import io.opentelemetry.context.ContextStorage;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.sentry.Instrumenter;
import io.sentry.Sentry;
import io.sentry.SentryIntegrationPackageStorage;
Expand All @@ -28,12 +30,16 @@ public final class SentryAutoConfigurationCustomizerProvider
@Override
public void customize(AutoConfigurationCustomizer autoConfiguration) {
final @Nullable VersionInfoHolder versionInfoHolder = createVersionInfo();

ContextStorage.addWrapper((storage) -> new SentryContextStorage(storage));

if (isSentryAutoInitEnabled()) {
Sentry.init(
options -> {
options.setEnableExternalConfiguration(true);
options.setInstrumenter(Instrumenter.OTEL);
options.addEventProcessor(new OpenTelemetryLinkErrorEventProcessor());
options.setSpanFactory(new OtelSpanFactory());
final @Nullable SdkVersion sdkVersion = createSdkVersion(options, versionInfoHolder);
if (sdkVersion != null) {
options.setSdkVersion(sdkVersion);
Expand Down Expand Up @@ -140,7 +146,12 @@ private static class VersionInfoHolder {

private SdkTracerProviderBuilder configureSdkTracerProvider(
SdkTracerProviderBuilder tracerProvider, ConfigProperties config) {
return tracerProvider.addSpanProcessor(new SentrySpanProcessor());
// TODO [POTEL] configurable or separate packages for old vs new way
// return tracerProvider.addSpanProcessor(new SentrySpanProcessor());
return tracerProvider
.setSampler(new SentrySampler())
.addSpanProcessor(new PotelSentrySpanProcessor())
.addSpanProcessor(BatchSpanProcessor.builder(new SentrySpanExporter()).build());
}

private Map<String, String> getDefaultProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public final class SentryPropagatorProvider implements ConfigurablePropagatorProvider {
@Override
public TextMapPropagator getPropagator(ConfigProperties config) {
return new SentryPropagator();
// return new SentryPropagator();
return new PotelSentryPropagator();
}

@Override
Expand Down
Loading
Loading