Skip to content

Commit d90e0f9

Browse files
authored
POTEL 20 - Use SpanOptions.startTimestamp in Span constructor (#3498)
* replace hub with scopes * Add Scopes * Introduce `IScopes` interface. * Replace `IHub` with `IScopes` in core * Replace `IHub` with `IScopes` in android core * Replace `IHub` with `IScopes` in android integrations * Replace `IHub` with `IScopes` in apollo integrations * Replace `IHub` with `IScopes` in okhttp integration * Replace `IHub` with `IScopes` in graphql integration * Replace `IHub` with `IScopes` in logging integrations * Replace `IHub` with `IScopes` in more integrations * Replace `IHub` with `IScopes` in OTel integration * Replace `IHub` with `IScopes` in Spring 5 / Spring Boot 2 integrations * Replace `IHub` with `IScopes` in Spring 6 / Spring Boot 3 integrations * Replace `IHub` with `IScopes` in samples * gitscopes -> github * Replace ThreadLocal with ScopesStorage * Move client and throwable to span map to scope * Add global scope * use global scope in Scopes * Implement pushScope popScope and withScope for Scopes * Add pushIsolationScope; add fork methods to ISCope * Use separate scopes for current, isolation and global scope; rename mainScopes to rootScopes * Allow controlling which scope configureScope uses * Combine scopes * Use new API for CRONS integrations * Add lifecycle helper * Change spring integrations to use new API * Use new API in servlet integrations * Use new API for kotlin coroutines and wrapers for Supplier/Callable * Discussion TODOs * Fix breadcrumb ordering * Mark TODOS with [HSM] * Add getGlobalScope and forkedRootScopes to IScopes * Fix EventProcessor ordering on scopes * Reuse code in Scopes * No longer replace global scope * Replace hub occurrences in comments, var names etc. * Implement ScopesTest * Implement CombinedScopeViewTest * Fix combined contexts * Use combined scopes for cross platform * Changes according to reviews of previous PRs * more * even more * isEnabled checks client instead of having a property on Scopes * Use SentryOptions.empty * Remove Hub * Use OpenTelemetry for Performance and Scopes propagation * Promote certain span attributes * Use OTel in Sentry API * Deduplicate SpanInfo extraction * Forward Sentry API to Sentry through OTel * Use OTel status for Sentry span API * POTel Tracing * fix root span detection (remote flag), and scope closing * Inherit OTel span IDs when sending to sentry * Fix tracing; parse incoming baggage; add baggage to outgoing * Cleanup * Move sampling logic to OTel Sampler * Remove internal span attributes so they are not sent to Sentry * Use transaction name * remove obsolete comment * Keep OTel and Sentry span name/op in sync * more cleanup * Make it possible to ignore span origins * Reuse TracesSampler instance * Catch exceptions thrown by integration.close * Set NoOpSpanFactory as property default * Use correct SentryOptions for SentryClient ctor * PR review feedback * more * Use SpanOptions.startTimestamp in Span ctor
1 parent 54e6568 commit d90e0f9

File tree

8 files changed

+6
-14
lines changed

8 files changed

+6
-14
lines changed

sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class SentryOkHttpEventTest {
6767
TransactionContext("name", "op", TracesSamplingDecision(true)),
6868
SentryTracer(TransactionContext("name", "op", TracesSamplingDecision(true)), scopes),
6969
scopes,
70-
null,
7170
SpanOptions()
7271
)
7372

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SentrySampler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public SamplingResult shouldSample(
4444
final @NotNull SpanKind spanKind,
4545
final @NotNull Attributes attributes,
4646
final @NotNull List<LinkData> parentLinks) {
47+
// TODO [POTEL] use SamplingDecision.DROP sentry internal spans
4748
// note: parentLinks seems to usually be empty
4849
final @Nullable Span parentOtelSpan = Span.fromContextOrNull(parentContext);
4950
final @Nullable OtelSpanWrapper parentSentrySpan =
@@ -65,6 +66,7 @@ public SamplingResult shouldSample(
6566
private @NotNull SamplingResult handleRootOtelSpan(
6667
final @NotNull String traceId, final @NotNull Context parentContext) {
6768
if (!options.isTraceSampling()) {
69+
// TODO [POTEL] should this return RECORD_ONLY to allow tracing without performance
6870
return SamplingResult.create(SamplingDecision.DROP);
6971
}
7072
@Nullable Baggage baggage = null;

sentry/api/sentry.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3104,7 +3104,7 @@ public final class io/sentry/ShutdownHookIntegration : io/sentry/Integration, ja
31043104
}
31053105

31063106
public final class io/sentry/Span : io/sentry/ISpan {
3107-
public fun <init> (Lio/sentry/TransactionContext;Lio/sentry/SentryTracer;Lio/sentry/IScopes;Lio/sentry/SentryDate;Lio/sentry/SpanOptions;)V
3107+
public fun <init> (Lio/sentry/TransactionContext;Lio/sentry/SentryTracer;Lio/sentry/IScopes;Lio/sentry/SpanOptions;)V
31083108
public fun finish ()V
31093109
public fun finish (Lio/sentry/SpanStatus;)V
31103110
public fun finish (Lio/sentry/SpanStatus;Lio/sentry/SentryDate;)V

sentry/src/main/java/io/sentry/SentryTracer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public SentryTracer(
7171
Objects.requireNonNull(context, "context is required");
7272
Objects.requireNonNull(scopes, "scopes are required");
7373

74-
this.root =
75-
new Span(context, this, scopes, transactionOptions.getStartTimestamp(), transactionOptions);
74+
this.root = new Span(context, this, scopes, transactionOptions);
7675

7776
this.name = context.getName();
7877
this.instrumenter = context.getInstrumenter();

sentry/src/main/java/io/sentry/Span.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ public Span(
7979
final @NotNull TransactionContext context,
8080
final @NotNull SentryTracer sentryTracer,
8181
final @NotNull IScopes scopes,
82-
final @Nullable SentryDate startTimestamp,
8382
final @NotNull SpanOptions options) {
8483
this.context = Objects.requireNonNull(context, "context is required");
8584
this.context.setOrigin(options.getOrigin());
8685
this.transaction = Objects.requireNonNull(sentryTracer, "sentryTracer is required");
8786
this.scopes = Objects.requireNonNull(scopes, "scopes are required");
8887
this.spanFinishedCallback = null;
88+
final @Nullable SentryDate startTimestamp = options.getStartTimestamp();
8989
if (startTimestamp != null) {
9090
this.startTimestamp = startTimestamp;
9191
} else {
@@ -311,11 +311,6 @@ public boolean isFinished() {
311311
// return new SentryId(UUID.nameUUIDFromBytes(getSpanId().toString().getBytes()));
312312
// }
313313

314-
@Override
315-
public @NotNull SentryId getEventId() {
316-
return new SentryId(getSpanId().toString());
317-
}
318-
319314
@Override
320315
public void setThrowable(final @Nullable Throwable throwable) {
321316
this.throwable = throwable;

sentry/src/main/java/io/sentry/SpanOptions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class SpanOptions {
1313
/** The start timestamp of the transaction */
1414
private @Nullable SentryDate startTimestamp = null;
1515

16-
// TODO [POTEL] this should also work for non OTel spans
1716
/**
1817
* Gets the startTimestamp
1918
*

sentry/src/test/java/io/sentry/protocol/SentrySpanTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class SentrySpanTest {
2020
TransactionContext("name", "op"),
2121
mock<SentryTracer>(),
2222
mock<IScopes>(),
23-
SentryLongDate(1000000),
24-
SpanOptions()
23+
SpanOptions().also { it.startTimestamp = SentryLongDate(1000000) }
2524
)
2625

2726
val sentrySpan = SentrySpan(span)

sentry/src/test/java/io/sentry/util/TracingUtilsTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class TracingUtilsTest {
4141
TransactionContext("name", "op", TracesSamplingDecision(true)),
4242
SentryTracer(TransactionContext("name", "op", TracesSamplingDecision(true)), scopes),
4343
scopes,
44-
null,
4544
SpanOptions()
4645
)
4746
}

0 commit comments

Comments
 (0)