Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.sentry.Sentry;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SentryOptions;
import io.sentry.SentrySpanFactoryHolder;
import io.sentry.protocol.SdkVersion;
import io.sentry.protocol.SentryPackage;
import io.sentry.util.SpanUtils;
Expand All @@ -32,13 +33,15 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
final @Nullable VersionInfoHolder versionInfoHolder = createVersionInfo();

ContextStorage.addWrapper((storage) -> new SentryContextStorage(storage));
final @NotNull OtelSpanFactory spanFactory = new OtelSpanFactory();
SentrySpanFactoryHolder.setSpanFactory(spanFactory);

if (isSentryAutoInitEnabled()) {
Sentry.init(
options -> {
options.setEnableExternalConfiguration(true);
options.setIgnoredSpanOrigins(SpanUtils.ignoredSpanOriginsForOpenTelemetry());
options.setSpanFactory(new OtelSpanFactory());
options.setSpanFactory(spanFactory);
final @Nullable SdkVersion sdkVersion = createSdkVersion(options, versionInfoHolder);
// TODO [POTEL] is detecting a version mismatch between application and agent possible?
if (sdkVersion != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public final class io/sentry/opentelemetry/InternalSemanticAttributes {
public fun <init> ()V
}

public final class io/sentry/opentelemetry/OpenTelemetryUtil {
public fun <init> ()V
public static fun applyOpenTelemetryOptions (Lio/sentry/SentryOptions;)V
}

public final class io/sentry/opentelemetry/OtelContextScopesStorage : io/sentry/IScopesStorage {
public fun <init> ()V
public fun close ()V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.sentry.opentelemetry;

import io.sentry.SentryOptions;
import io.sentry.SentrySpanFactoryHolder;
import io.sentry.util.SpanUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

@ApiStatus.Experimental
public final class OpenTelemetryUtil {

public static void applyOpenTelemetryOptions(final @Nullable SentryOptions options) {
if (options != null) {
options.setSpanFactory(SentrySpanFactoryHolder.getSpanFactory());
options.setIgnoredSpanOrigins(SpanUtils.ignoredSpanOriginsForOpenTelemetry());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final class OtelSpanWrapper implements ISpan {
* OtelSpanWrapper} and indirectly back to {@link io.opentelemetry.sdk.trace.data.SpanData} via
* {@link Span}. Also see {@link SentryWeakSpanStorage}.
*/
private final @NotNull WeakReference<ReadWriteSpan> span;
private final @NotNull WeakReference<ReadWriteSpan> span; // TODO [POTEL] bootstrap proxy

private final @NotNull SpanContext context;
// private final @NotNull SpanOptions options;
Expand Down
6 changes: 6 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -2936,6 +2936,12 @@ public abstract interface class io/sentry/SentryOptions$TracesSamplerCallback {
public abstract fun sample (Lio/sentry/SamplingContext;)Ljava/lang/Double;
}

public final class io/sentry/SentrySpanFactoryHolder {
public fun <init> ()V
public static fun getSpanFactory ()Lio/sentry/ISpanFactory;
public static fun setSpanFactory (Lio/sentry/ISpanFactory;)V
}

public final class io/sentry/SentrySpanStorage {
public fun get (Ljava/lang/String;)Lio/sentry/ISpan;
public static fun getInstance ()Lio/sentry/SentrySpanStorage;
Expand Down
29 changes: 29 additions & 0 deletions sentry/src/main/java/io/sentry/SentrySpanFactoryHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.sentry;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/**
* NOTE: This just exists as a workaround for a bug.
*
* <p>What bug? When using sentry-opentelemetry-agent with SENTRY_AUTO_INIT=false a global storage
* for spans does not work correctly since it's loaded multiple times. Once for bootstrap
* classloader (a.k.a null) and once for the agent classloader. Since the agent is currently loading
* these classes into the agent classloader, there should not be a noticable problem, when using the
* default of SENTRY_AUTO_INIT=true. In the future we plan to have the agent also load the classes
* into the bootstrap classloader, then this hack should no longer be necessary.
*/
@ApiStatus.Experimental
public final class SentrySpanFactoryHolder {

private static ISpanFactory spanFactory = new DefaultSpanFactory();

public static ISpanFactory getSpanFactory() {
return spanFactory;
}

@ApiStatus.Internal
public static void setSpanFactory(final @NotNull ISpanFactory factory) {
spanFactory = factory;
}
}
1 change: 1 addition & 0 deletions sentry/src/main/java/io/sentry/SentryTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ private ISpan createChild(
finish(finishStatus.spanStatus);
}
});
// TODO [POTEL] missing features
// final Span span =
// new Span(
// root.getTraceId(),
Expand Down