Skip to content

Commit ea206a7

Browse files
committed
sync trace as well
1 parent 880dc4f commit ea206a7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import io.sentry.Breadcrumb;
44
import io.sentry.DateUtils;
5+
import io.sentry.IScope;
56
import io.sentry.ScopeObserverAdapter;
67
import io.sentry.SentryLevel;
78
import io.sentry.SentryOptions;
9+
import io.sentry.SpanContext;
810
import io.sentry.ndk.INativeScope;
911
import io.sentry.ndk.NativeScope;
12+
import io.sentry.protocol.SentryId;
1013
import io.sentry.protocol.User;
1114
import io.sentry.util.Objects;
1215
import java.util.Locale;
@@ -125,4 +128,24 @@ public void removeExtra(final @NotNull String key) {
125128
.log(SentryLevel.ERROR, e, "Scope sync removeExtra(%s) has an error.", key);
126129
}
127130
}
131+
132+
@Override
133+
public void setTrace(@Nullable SpanContext spanContext, @NotNull IScope scope) {
134+
options.getLogger().log(SentryLevel.INFO, "Attempting to set the trace ID");
135+
136+
if(spanContext == null) {
137+
return;
138+
}
139+
140+
@Nullable SentryId traceId = spanContext.getTraceId();
141+
String traceIdString = traceId.toString();
142+
143+
options.getLogger().log(SentryLevel.INFO, "Fetched trace ID '%s'.", traceIdString);
144+
145+
try {
146+
options.getExecutorService().submit(() -> nativeScope.setTraceId(traceIdString));
147+
} catch (Throwable e) {
148+
options.getLogger().log(SentryLevel.ERROR, e, "Scope sync setTraceId(%s) has an error.", traceIdString);
149+
}
150+
}
128151
}

0 commit comments

Comments
 (0)