Skip to content

Commit c233756

Browse files
committed
added option to disable trace ID generation
1 parent 32212cd commit c233756

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,7 @@ private void stopPreviousTransactions() {
159159
private void startTracing(final @NotNull Activity activity) {
160160
WeakReference<Activity> weakActivity = new WeakReference<>(activity);
161161
if (scopes != null && !isRunningTransactionOrTrace(activity)) {
162-
if (!performanceEnabled) {
163-
activitiesWithOngoingTransactions.put(activity, NoOpTransaction.getInstance());
164-
TracingUtils.startNewTrace(scopes);
165-
} else {
162+
if (performanceEnabled) {
166163
// as we allow a single transaction running on the bound Scope, we finish the previous ones
167164
stopPreviousTransactions();
168165

@@ -301,6 +298,9 @@ private void startTracing(final @NotNull Activity activity) {
301298
});
302299

303300
activitiesWithOngoingTransactions.put(activity, transaction);
301+
} else if (options.isEnableAutoTraceIdGeneration()) {
302+
activitiesWithOngoingTransactions.put(activity, NoOpTransaction.getInstance());
303+
TracingUtils.startNewTrace(scopes);
304304
}
305305
}
306306
}

sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ final class ManifestMetadataReader {
107107

108108
static final String IGNORED_ERRORS = "io.sentry.ignored-errors";
109109

110+
static final String ENABLE_AUTO_TRACE_ID_GENERATION = "io.sentry.enable-trace-update";
111+
110112
/** ManifestMetadataReader ctor */
111113
private ManifestMetadataReader() {}
112114

@@ -380,6 +382,9 @@ static void applyMetadata(
380382
readBool(
381383
metadata, logger, ENABLE_SCOPE_PERSISTENCE, options.isEnableScopePersistence()));
382384

385+
options.setEnableAutoTraceIdGeneration(
386+
readBool(metadata, logger, ENABLE_AUTO_TRACE_ID_GENERATION, options.isAttachScreenshot()));
387+
383388
if (options.getSessionReplay().getSessionSampleRate() == null) {
384389
final Double sessionSampleRate =
385390
readDouble(metadata, logger, REPLAYS_SESSION_SAMPLE_RATE);

sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ public final class SentryAndroidOptions extends SentryOptions {
166166
*/
167167
private boolean enableScopeSync = true;
168168

169+
/** Whether to enable automatic trace ID generation. This is mainly used by the Hybrid SDKs to
170+
* control the trace ID generation from the outside.
171+
*/
172+
private boolean enableAutoTraceIdGeneration = true;
173+
169174
public interface BeforeCaptureCallback {
170175

171176
/**
@@ -594,4 +599,13 @@ public void setFrameMetricsCollector(
594599
final @Nullable SentryFrameMetricsCollector frameMetricsCollector) {
595600
this.frameMetricsCollector = frameMetricsCollector;
596601
}
602+
603+
604+
public boolean isEnableAutoTraceIdGeneration() {
605+
return enableAutoTraceIdGeneration;
606+
}
607+
608+
public void setEnableAutoTraceIdGeneration(final boolean enableAutoTraceIdGeneration) {
609+
this.enableAutoTraceIdGeneration = enableAutoTraceIdGeneration;
610+
}
597611
}

sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private void startTracing(final @NotNull UiElement target, final @NotNull Gestur
201201
final boolean isNewInteraction = isClickGesture || !isNewGestureSameAsActive;
202202

203203
if (!(options.isTracingEnabled() && options.isEnableUserInteractionTracing())) {
204-
if (isNewInteraction) {
204+
if (options.isEnableAutoTraceIdGeneration() && isNewInteraction) {
205205
TracingUtils.startNewTrace(scopes);
206206
activeUiElement = target;
207207
activeEventType = eventType;

0 commit comments

Comments
 (0)