Skip to content

Commit

Permalink
POTEL 69 - Hold a strong reference to OpenTelemetry span if created v…
Browse files Browse the repository at this point in the history
…ia Sentry API (#3997)

* add agentless module for OpenTelemetry setup without any agent

* Replace bool with enum for OpenTelemetryUtil mode

* Move OpenTelemetryUtil into core sentry

* Add openTelemetryMode option

* Add SentryOpenTelemetryMode.OFF

* fix HubAdapter and ScopeAdapter tests by calling Sentry.init so that the ScopesStorage is initialized

* Hold a strong reference to OTel span if created via Sentry API

* fix tests

* fix build

* changelog

* fix agentless due to late call to SpanFactoryFactory

* Format code

* changelog

* fix order of scope storage close vs scopes close

* changelog

* use initForTest

* use initForTest

* Update sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry/OtelStrongRefSpanWrapper.java

Co-authored-by: Lukas Bloder <[email protected]>

---------

Co-authored-by: Lukas Bloder <[email protected]>
Co-authored-by: Sentry Github Bot <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2024
1 parent 5a15f74 commit d91b2d7
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
- 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 @@ -39,6 +39,58 @@ public final class io/sentry/opentelemetry/OtelSpanFactory : io/sentry/ISpanFact
public fun createTransaction (Lio/sentry/TransactionContext;Lio/sentry/IScopes;Lio/sentry/TransactionOptions;Lio/sentry/TransactionPerformanceCollector;)Lio/sentry/ITransaction;
}

public final class io/sentry/opentelemetry/OtelStrongRefSpanWrapper : io/sentry/opentelemetry/IOtelSpanWrapper {
public fun <init> (Lio/opentelemetry/api/trace/Span;Lio/sentry/opentelemetry/IOtelSpanWrapper;)V
public fun finish ()V
public fun finish (Lio/sentry/SpanStatus;)V
public fun finish (Lio/sentry/SpanStatus;Lio/sentry/SentryDate;)V
public fun getContexts ()Lio/sentry/protocol/Contexts;
public fun getData ()Ljava/util/Map;
public fun getData (Ljava/lang/String;)Ljava/lang/Object;
public fun getDescription ()Ljava/lang/String;
public fun getFinishDate ()Lio/sentry/SentryDate;
public fun getMeasurements ()Ljava/util/Map;
public fun getOperation ()Ljava/lang/String;
public fun getSamplingDecision ()Lio/sentry/TracesSamplingDecision;
public fun getScopes ()Lio/sentry/IScopes;
public fun getSpanContext ()Lio/sentry/SpanContext;
public fun getStartDate ()Lio/sentry/SentryDate;
public fun getStatus ()Lio/sentry/SpanStatus;
public fun getTag (Ljava/lang/String;)Ljava/lang/String;
public fun getTags ()Ljava/util/Map;
public fun getThrowable ()Ljava/lang/Throwable;
public fun getTraceId ()Lio/sentry/protocol/SentryId;
public fun getTransactionName ()Ljava/lang/String;
public fun getTransactionNameSource ()Lio/sentry/protocol/TransactionNameSource;
public fun isFinished ()Z
public fun isNoOp ()Z
public fun isProfileSampled ()Ljava/lang/Boolean;
public fun isSampled ()Ljava/lang/Boolean;
public fun makeCurrent ()Lio/sentry/ISentryLifecycleToken;
public fun setContext (Ljava/lang/String;Ljava/lang/Object;)V
public fun setData (Ljava/lang/String;Ljava/lang/Object;)V
public fun setDescription (Ljava/lang/String;)V
public fun setMeasurement (Ljava/lang/String;Ljava/lang/Number;)V
public fun setMeasurement (Ljava/lang/String;Ljava/lang/Number;Lio/sentry/MeasurementUnit;)V
public fun setOperation (Ljava/lang/String;)V
public fun setStatus (Lio/sentry/SpanStatus;)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setThrowable (Ljava/lang/Throwable;)V
public fun setTransactionName (Ljava/lang/String;)V
public fun setTransactionName (Ljava/lang/String;Lio/sentry/protocol/TransactionNameSource;)V
public fun startChild (Lio/sentry/SpanContext;Lio/sentry/SpanOptions;)Lio/sentry/ISpan;
public fun startChild (Ljava/lang/String;)Lio/sentry/ISpan;
public fun startChild (Ljava/lang/String;Ljava/lang/String;)Lio/sentry/ISpan;
public fun startChild (Ljava/lang/String;Ljava/lang/String;Lio/sentry/SentryDate;Lio/sentry/Instrumenter;)Lio/sentry/ISpan;
public fun startChild (Ljava/lang/String;Ljava/lang/String;Lio/sentry/SentryDate;Lio/sentry/Instrumenter;Lio/sentry/SpanOptions;)Lio/sentry/ISpan;
public fun startChild (Ljava/lang/String;Ljava/lang/String;Lio/sentry/SpanOptions;)Lio/sentry/ISpan;
public fun storeInContext (Lio/opentelemetry/context/Context;)Lio/opentelemetry/context/Context;
public fun toBaggageHeader (Ljava/util/List;)Lio/sentry/BaggageHeader;
public fun toSentryTrace ()Lio/sentry/SentryTraceHeader;
public fun traceContext ()Lio/sentry/TraceContext;
public fun updateEndDate (Lio/sentry/SentryDate;)Z
}

public final class io/sentry/opentelemetry/OtelTransactionSpanForwarder : io/sentry/ITransaction {
public fun <init> (Lio/sentry/opentelemetry/IOtelSpanWrapper;)V
public fun finish ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ public OtelSpanFactory() {
sentrySpan.getSpanContext().setOrigin(spanOptions.getOrigin());
}

return sentrySpan;
if (sentrySpan == null) {
return null;
} else {
return new OtelStrongRefSpanWrapper(otelSpan, sentrySpan);
}
}

private @NotNull Tracer getTracer() {
Expand Down
Loading

0 comments on commit d91b2d7

Please sign in to comment.