Skip to content

Commit

Permalink
POTEL 45 - Set span origin in ActivityLifecycleIntegration on span …
Browse files Browse the repository at this point in the history
…options instead of after creating the span / transaction (#3702)

* merge

* move from hub to scopes

* restore instrumenter code, do not use otel as instrumenter for potel

* changelog

* reword changelog

* restore multi init tests

* Set origin on span options instead of setting after transaction/span has been created

* changelog
  • Loading branch information
adinauer authored Sep 23, 2024
1 parent 846baeb commit e34b8a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
- redact/ignore `View`s of a certain type by adding fully-qualified classname to one of the lists `options.experimental.sessionReplay.addRedactViewClass()` or `options.experimental.sessionReplay.addIgnoreViewClass()`. Note, that all of the view subclasses/subtypes will be redacted/ignored as well
- For example, (this is already a default behavior) to redact all `TextView`s and their subclasses (`RadioButton`, `EditText`, etc.): `options.experimental.sessionReplay.addRedactViewClass("android.widget.TextView")`
- If you're using code obfuscation, adjust your proguard-rules accordingly, so your custom view class name is not minified
- Set span origin in `ActivityLifecycleIntegration` on span options instead of after creating the span / transaction ([#3702](https://github.com/getsentry/sentry-java/pull/3702))
- This allows spans to be filtered by span origin on creation

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.sentry.SentryLevel;
import io.sentry.SentryNanotimeDate;
import io.sentry.SentryOptions;
import io.sentry.SpanOptions;
import io.sentry.SpanStatus;
import io.sentry.TracesSamplingDecision;
import io.sentry.TransactionContext;
Expand Down Expand Up @@ -224,6 +225,7 @@ private void startTracing(final @NotNull Activity activity) {
}
transactionOptions.setStartTimestamp(ttidStartTime);
transactionOptions.setAppStartTransaction(appStartSamplingDecision != null);
setSpanOrigin(transactionOptions);

// we can only bind to the scope if there's no running transaction
ITransaction transaction =
Expand All @@ -234,7 +236,9 @@ private void startTracing(final @NotNull Activity activity) {
UI_LOAD_OP,
appStartSamplingDecision),
transactionOptions);
setSpanOrigin(transaction);

final SpanOptions spanOptions = new SpanOptions();
setSpanOrigin(spanOptions);

// in case appStartTime isn't available, we don't create a span for it.
if (!(firstActivityCreated || appStartTime == null || coldStart == null)) {
Expand All @@ -244,24 +248,30 @@ private void startTracing(final @NotNull Activity activity) {
getAppStartOp(coldStart),
getAppStartDesc(coldStart),
appStartTime,
Instrumenter.SENTRY);
setSpanOrigin(appStartSpan);
Instrumenter.SENTRY,
spanOptions);

// in case there's already an end time (e.g. due to deferred SDK init)
// we can finish the app-start span
finishAppStartSpan();
}
final @NotNull ISpan ttidSpan =
transaction.startChild(
TTID_OP, getTtidDesc(activityName), ttidStartTime, Instrumenter.SENTRY);
TTID_OP,
getTtidDesc(activityName),
ttidStartTime,
Instrumenter.SENTRY,
spanOptions);
ttidSpanMap.put(activity, ttidSpan);
setSpanOrigin(ttidSpan);

if (timeToFullDisplaySpanEnabled && fullyDisplayedReporter != null && options != null) {
final @NotNull ISpan ttfdSpan =
transaction.startChild(
TTFD_OP, getTtfdDesc(activityName), ttidStartTime, Instrumenter.SENTRY);
setSpanOrigin(ttfdSpan);
TTFD_OP,
getTtfdDesc(activityName),
ttidStartTime,
Instrumenter.SENTRY,
spanOptions);
try {
ttfdSpanMap.put(activity, ttfdSpan);
ttfdAutoCloseFuture =
Expand Down Expand Up @@ -290,11 +300,8 @@ private void startTracing(final @NotNull Activity activity) {
}
}

private void setSpanOrigin(ISpan span) {
if (span != null) {
// TODO [POTEL] replace with transactionOptions.setOrigin
span.getSpanContext().setOrigin(TRACE_ORIGIN);
}
private void setSpanOrigin(final @NotNull SpanOptions spanOptions) {
spanOptions.setOrigin(TRACE_ORIGIN);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class ActivityLifecycleIntegrationTest {
check<TransactionOptions> { transactionOptions ->
assertEquals(fixture.options.idleTimeout, transactionOptions.idleTimeout)
assertEquals(TransactionOptions.DEFAULT_DEADLINE_TIMEOUT_AUTO_TRANSACTION, transactionOptions.deadlineTimeout)
assertEquals("auto.ui.activity", transactionOptions.origin)
}
)
}
Expand Down

0 comments on commit e34b8a2

Please sign in to comment.