Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 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
05fcc6f
Merge branch '8.x.x' into feat/potel-9-tracing-fixes
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
public final class io/sentry/opentelemetry/InternalSemanticAttributes {
public static final field BAGGAGE Lio/opentelemetry/api/common/AttributeKey;
public static final field BAGGAGE_MUTABLE Lio/opentelemetry/api/common/AttributeKey;
public static final field IS_REMOTE_PARENT Lio/opentelemetry/api/common/AttributeKey;
public static final field PARENT_SAMPLED Lio/opentelemetry/api/common/AttributeKey;
public static final field PROFILE_SAMPLED Lio/opentelemetry/api/common/AttributeKey;
Expand All @@ -16,7 +18,7 @@ public final class io/sentry/opentelemetry/OtelContextScopesStorage : io/sentry/
}

public final class io/sentry/opentelemetry/OtelSpanContext : io/sentry/SpanContext {
public fun <init> (Lio/opentelemetry/sdk/trace/ReadWriteSpan;Lio/sentry/TracesSamplingDecision;Lio/sentry/opentelemetry/OtelSpanWrapper;)V
public fun <init> (Lio/opentelemetry/sdk/trace/ReadWriteSpan;Lio/sentry/TracesSamplingDecision;Lio/sentry/opentelemetry/OtelSpanWrapper;Lio/sentry/Baggage;)V
public fun getStatus ()Lio/sentry/SpanStatus;
public fun setStatus (Lio/sentry/SpanStatus;)V
}
Expand All @@ -30,7 +32,7 @@ public final class io/sentry/opentelemetry/OtelSpanFactory : io/sentry/ISpanFact
}

public final class io/sentry/opentelemetry/OtelSpanWrapper : io/sentry/ISpan {
public fun <init> (Lio/opentelemetry/sdk/trace/ReadWriteSpan;Lio/sentry/IScopes;Lio/sentry/SentryDate;Lio/sentry/TracesSamplingDecision;Lio/sentry/opentelemetry/OtelSpanWrapper;)V
public fun <init> (Lio/opentelemetry/sdk/trace/ReadWriteSpan;Lio/sentry/IScopes;Lio/sentry/SentryDate;Lio/sentry/TracesSamplingDecision;Lio/sentry/opentelemetry/OtelSpanWrapper;Lio/sentry/Baggage;)V
public fun finish ()V
public fun finish (Lio/sentry/SpanStatus;)V
public fun finish (Lio/sentry/SpanStatus;Lio/sentry/SentryDate;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public final class InternalSemanticAttributes {
AttributeKey.doubleKey("sentry.profile_sample_rate");
public static final AttributeKey<Boolean> IS_REMOTE_PARENT =
AttributeKey.booleanKey("sentry.is_remote_parent");
public static final AttributeKey<String> BAGGAGE = AttributeKey.stringKey("sentry.baggage");
public static final AttributeKey<Boolean> BAGGAGE_MUTABLE =
AttributeKey.booleanKey("sentry.baggage_mutable");
// public static final AttributeKey<String> BREADCRUMB_TYPE =
// AttributeKey.stringKey("sentry.breadcrumb.type");
// public static final AttributeKey<SentryLevel> BREADCRUMB_TYPE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.opentelemetry.sdk.trace.data.StatusData;
import io.sentry.Baggage;
import io.sentry.SpanContext;
import io.sentry.SpanId;
import io.sentry.SpanStatus;
Expand All @@ -26,7 +27,8 @@ public final class OtelSpanContext extends SpanContext {
public OtelSpanContext(
final @NotNull ReadWriteSpan span,
final @Nullable TracesSamplingDecision samplingDecision,
final @Nullable OtelSpanWrapper parentSpan) {
final @Nullable OtelSpanWrapper parentSpan,
final @Nullable Baggage baggage) {
super(
new SentryId(span.getSpanContext().getTraceId()),
new SpanId(span.getSpanContext().getSpanId()),
Expand All @@ -39,6 +41,7 @@ public OtelSpanContext(
null,
null);
this.span = new WeakReference<>(span);
this.baggage = baggage;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.sentry.Baggage;
import io.sentry.IScope;
import io.sentry.IScopes;
import io.sentry.ISpan;
Expand Down Expand Up @@ -104,7 +105,12 @@ public final class OtelSpanFactory implements ISpanFactory {
}
}

// TODO [POTEL] send baggage in (note: won't go through propagators)
// note: won't go through propagators
final @Nullable Baggage baggage = spanContext.getBaggage();
if (baggage != null) {
spanBuilder.setAttribute(InternalSemanticAttributes.BAGGAGE_MUTABLE, baggage.isMutable());
spanBuilder.setAttribute(InternalSemanticAttributes.BAGGAGE, baggage.toHeaderString(null));
}

final @Nullable SentryDate startTimestampFromOptions = spanOptions.getStartTimestamp();
final @NotNull SentryDate startTimestamp =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Scope;
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.sentry.Baggage;
import io.sentry.BaggageHeader;
import io.sentry.IScopes;
import io.sentry.ISentryLifecycleToken;
Expand All @@ -25,6 +26,7 @@
import io.sentry.protocol.MeasurementValue;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.TransactionNameSource;
import io.sentry.protocol.User;
import io.sentry.util.LazyEvaluator;
import io.sentry.util.Objects;
import java.lang.ref.WeakReference;
Expand All @@ -34,6 +36,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -62,6 +65,7 @@ public final class OtelSpanWrapper implements ISpan {
private final @NotNull Contexts contexts = new Contexts();
private @Nullable String transactionName;
private @Nullable TransactionNameSource transactionNameSource;
private final @Nullable Baggage baggage;

// TODO [POTEL]
// private @Nullable SpanFinishedCallback spanFinishedCallback;
Expand All @@ -78,16 +82,28 @@ public final class OtelSpanWrapper implements ISpan {

private @NotNull Deque<ISentryLifecycleToken> tokensToCleanup = new ArrayDeque<>(1);

// TODO [POTEL] reference root span? for getting root baggage
public OtelSpanWrapper(
final @NotNull ReadWriteSpan span,
final @NotNull IScopes scopes,
final @NotNull SentryDate startTimestamp,
final @Nullable TracesSamplingDecision samplingDecision,
final @Nullable OtelSpanWrapper parentSpan) {
final @Nullable OtelSpanWrapper parentSpan,
final @Nullable Baggage baggage) {
this.scopes = Objects.requireNonNull(scopes, "scopes are required");
this.span = new WeakReference<>(span);
this.startTimestamp = startTimestamp;
this.context = new OtelSpanContext(span, samplingDecision, parentSpan);

if (parentSpan != null) {
this.baggage = parentSpan.getSpanContext().getBaggage();
} else if (baggage != null) {
this.baggage = baggage;
} else {
this.baggage = null;
// this.baggage = new Baggage(scopes.getOptions().getLogger());
}

this.context = new OtelSpanContext(span, samplingDecision, parentSpan, this.baggage);
}

@Override
Expand Down Expand Up @@ -178,15 +194,43 @@ public OtelSpanWrapper(

@Override
public @Nullable TraceContext traceContext() {
// return transaction.traceContext();
// TODO [POTEL]
if (scopes.getOptions().isTraceSampling()) {
if (baggage != null) {
updateBaggageValues();
return baggage.toTraceContext();
}
}
return null;
}

private void updateBaggageValues() {
synchronized (this) {
if (baggage != null && baggage.isMutable()) {
final AtomicReference<User> userAtomicReference = new AtomicReference<>();
scopes.configureScope(
scope -> {
userAtomicReference.set(scope.getUser());
});
baggage.setValuesFromTransaction(
getSpanContext().getTraceId(),
userAtomicReference.get(),
scopes.getOptions(),
this.getSamplingDecision(),
getTransactionName(),
getTransactionNameSource());
baggage.freeze();
}
}
}

@Override
public @Nullable BaggageHeader toBaggageHeader(@Nullable List<String> thirdPartyBaggageHeaders) {
// return transaction.toBaggageHeader(thirdPartyBaggageHeaders);
// TODO [POTEL]
if (scopes.getOptions().isTraceSampling()) {
if (baggage != null) {
updateBaggageValues();
return BaggageHeader.fromBaggageAndOutgoingHeader(baggage, thirdPartyBaggageHeaders);
}
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,16 @@ public OtelTransactionSpanForwarder(final @NotNull OtelSpanWrapper rootSpan) {

@Override
public @NotNull SentryTraceHeader toSentryTrace() {
// TODO [POTEL] root span?
return rootSpan.toSentryTrace();
}

@Override
public @Nullable TraceContext traceContext() {
// TODO [POTEL] root span?
return rootSpan.traceContext();
}

@Override
public @Nullable BaggageHeader toBaggageHeader(@Nullable List<String> thirdPartyBaggageHeaders) {
// TODO [POTEL] root span?
return rootSpan.toBaggageHeader(thirdPartyBaggageHeaders);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.opentelemetry.context.propagation.TextMapGetter;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.sentry.Baggage;
import io.sentry.BaggageHeader;
import io.sentry.IScopes;
import io.sentry.PropagationContext;
Expand Down Expand Up @@ -100,6 +101,7 @@ public <C> Context extract(
SentryTraceHeader sentryTraceHeader = new SentryTraceHeader(sentryTraceString);

final @Nullable String baggageString = getter.get(carrier, BaggageHeader.BAGGAGE_HEADER);
final Baggage baggage = Baggage.fromHeader(baggageString);
final @NotNull TraceState traceState = TraceState.getDefault();

SpanContext otelSpanContext =
Expand All @@ -112,7 +114,11 @@ public <C> Context extract(
Span wrappedSpan = Span.wrap(otelSpanContext);

final @NotNull Context modifiedContext =
context.with(wrappedSpan).with(SENTRY_SCOPES_KEY, scopesToUse);
context
.with(wrappedSpan)
.with(SENTRY_SCOPES_KEY, scopesToUse)
.with(SentryOtelKeys.SENTRY_TRACE_KEY, sentryTraceHeader)
.with(SentryOtelKeys.SENTRY_BAGGAGE_KEY, baggage);

scopes
.getOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.sentry.Baggage;
import io.sentry.IScopes;
import io.sentry.PropagationContext;
import io.sentry.SamplingContext;
Expand All @@ -16,6 +17,7 @@
import io.sentry.SentryDate;
import io.sentry.SentryLevel;
import io.sentry.SentryLongDate;
import io.sentry.SentryTraceHeader;
import io.sentry.SpanId;
import io.sentry.TracesSampler;
import io.sentry.TracesSamplingDecision;
Expand Down Expand Up @@ -54,8 +56,20 @@ public void onStart(final @NotNull Context parentContext, final @NotNull ReadWri
final @Nullable OtelSpanWrapper sentryParentSpan =
spanStorage.getSentrySpan(otelSpan.getParentSpanContext());
@Nullable TracesSamplingDecision samplingDecision = null;
// TODO [POTEL] baggage from propagator should be honored
@Nullable Baggage baggage = null;
otelSpan.setAttribute(IS_REMOTE_PARENT, otelSpan.getParentSpanContext().isRemote());
if (sentryParentSpan == null) {
final @Nullable Boolean baggageMutable =
otelSpan.getAttribute(InternalSemanticAttributes.BAGGAGE_MUTABLE);
final @Nullable String baggageString =
otelSpan.getAttribute(InternalSemanticAttributes.BAGGAGE);
if (baggageString != null) {
baggage = Baggage.fromHeader(baggageString);
if (baggageMutable == true) {
baggage.freeze();
}
}
final @Nullable Boolean sampled = otelSpan.getAttribute(InternalSemanticAttributes.SAMPLED);
final @Nullable Double sampleRate =
otelSpan.getAttribute(InternalSemanticAttributes.SAMPLE_RATE);
Expand All @@ -73,7 +87,11 @@ public void onStart(final @NotNull Context parentContext, final @NotNull ReadWri

final @NotNull PropagationContext propagationContext =
new PropagationContext(
new SentryId(traceId), new SpanId(spanId), new SpanId(parentSpanId), null, sampled);
new SentryId(traceId),
new SpanId(spanId),
new SpanId(parentSpanId),
baggage,
sampled);

scopes.configureScope(
scope -> {
Expand All @@ -96,9 +114,19 @@ public void onStart(final @NotNull Context parentContext, final @NotNull ReadWri

final @NotNull String traceId = otelSpan.getSpanContext().getTraceId();
final @NotNull String spanId = otelSpan.getSpanContext().getSpanId();
final @NotNull SpanId sentrySpanId = new SpanId(spanId);

@Nullable
SentryTraceHeader sentryTraceHeader = parentContext.get(SentryOtelKeys.SENTRY_TRACE_KEY);
@Nullable Baggage baggageFromContext = parentContext.get(SentryOtelKeys.SENTRY_BAGGAGE_KEY);
if (sentryTraceHeader != null) {
baggage = baggageFromContext;
}

final @NotNull PropagationContext propagationContext =
new PropagationContext(new SentryId(traceId), new SpanId(spanId), null, null, null);
sentryTraceHeader == null
? new PropagationContext(new SentryId(traceId), sentrySpanId, null, baggage, null)
: PropagationContext.fromHeaders(sentryTraceHeader, baggage, sentrySpanId);

scopes.configureScope(
scope -> {
Expand All @@ -118,7 +146,8 @@ public void onStart(final @NotNull Context parentContext, final @NotNull ReadWri
new SentryLongDate(otelSpan.toSpanData().getStartEpochNanos());
spanStorage.storeSentrySpan(
spanContext,
new OtelSpanWrapper(otelSpan, scopes, startTimestamp, samplingDecision, sentryParentSpan));
new OtelSpanWrapper(
otelSpan, scopes, startTimestamp, samplingDecision, sentryParentSpan, baggage));
}

@Override
Expand Down
Loading