|
2 | 2 |
|
3 | 3 | import io.sentry.Breadcrumb; |
4 | 4 | import io.sentry.DateUtils; |
| 5 | +import io.sentry.IScope; |
5 | 6 | import io.sentry.ScopeObserverAdapter; |
6 | 7 | import io.sentry.SentryLevel; |
7 | 8 | import io.sentry.SentryOptions; |
| 9 | +import io.sentry.SpanContext; |
8 | 10 | import io.sentry.ndk.INativeScope; |
9 | 11 | import io.sentry.ndk.NativeScope; |
| 12 | +import io.sentry.protocol.SentryId; |
10 | 13 | import io.sentry.protocol.User; |
11 | 14 | import io.sentry.util.Objects; |
12 | 15 | import java.util.Locale; |
@@ -125,4 +128,24 @@ public void removeExtra(final @NotNull String key) { |
125 | 128 | .log(SentryLevel.ERROR, e, "Scope sync removeExtra(%s) has an error.", key); |
126 | 129 | } |
127 | 130 | } |
| 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 | + } |
128 | 151 | } |
0 commit comments