Skip to content

Commit 9a10493

Browse files
committed
updated settrace to accept sample rate and sample rand
1 parent cbe837c commit 9a10493

File tree

10 files changed

+58
-19
lines changed

10 files changed

+58
-19
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,15 @@ private static Session updateSession(
335335
* Continue a trace based on the trace ID and span ID provided
336336
*
337337
* @param traceId the trace ID
338-
* @param spanId the span ID
338+
* @param spanId the trace origin's span ID
339+
* @param sampleRate the sample rate used by the origin of the trace
340+
* @param sampleRand the random value used to sample with by the origin of the trace
339341
*/
340-
public static void setTrace(final @NotNull String traceId, final @NotNull String spanId, final @Nullable String sampleRand) {
341-
getCurrentScopes().setTrace(traceId, spanId);
342+
public static void setTrace(
343+
final @NotNull String traceId,
344+
final @NotNull String spanId,
345+
final @Nullable Double sampleRate,
346+
final @Nullable Double sampleRand) {
347+
getCurrentScopes().setTrace(traceId, spanId, sampleRate, sampleRand);
342348
}
343349
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void setTrace(@Nullable SpanContext spanContext, @NotNull IScope scope) {
142142
nativeScope.setTrace(
143143
spanContext.getTraceId().toString(), spanContext.getSpanId().toString()));
144144
} catch (Throwable e) {
145-
options.getLogger().log(SentryLevel.ERROR, e, "Scope sync setTraceId failed.");
145+
options.getLogger().log(SentryLevel.ERROR, e, "Scope sync setTrace failed.");
146146
}
147147
}
148148
}

sentry/src/main/java/io/sentry/HubAdapter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,12 @@ public void reportFullyDisplayed() {
323323
}
324324

325325
@Override
326-
public void setTrace(final @NotNull String traceId, final @NotNull String spanId) {
327-
Sentry.getCurrentScopes().setTrace(traceId, spanId);
326+
public void setTrace(
327+
final @NotNull String traceId,
328+
final @NotNull String spanId,
329+
final @Nullable Double sampleRate,
330+
final @Nullable Double sampleRand) {
331+
Sentry.getCurrentScopes().setTrace(traceId, spanId, sampleRate, sampleRand);
328332
}
329333

330334
@Override

sentry/src/main/java/io/sentry/HubScopesWrapper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,12 @@ public void reportFullyDisplayed() {
317317
}
318318

319319
@Override
320-
public void setTrace(@NotNull String traceId, @NotNull String spanId) {
321-
scopes.setTrace(traceId, spanId);
320+
public void setTrace(
321+
final @NotNull String traceId,
322+
final @NotNull String spanId,
323+
final @Nullable Double sampleRate,
324+
final @Nullable Double sampleRand) {
325+
Sentry.getCurrentScopes().setTrace(traceId, spanId, sampleRate, sampleRand);
322326
}
323327

324328
@Override

sentry/src/main/java/io/sentry/IScopes.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,15 @@ TransactionContext continueTrace(
661661
* Set a trace. This is primarily used by other SDKs in a Hybrid SDK context
662662
*
663663
* @param traceId the trace ID
664-
* @param spanId the span ID this is continuing the trace from
665-
*/
666-
void setTrace(final @NotNull String traceId, final @NotNull String spanId);
664+
* @param spanId the trace origin's span ID
665+
* @param sampleRate the sample rate used by the origin of the trace
666+
* @param sampleRand the random value used to sample with by the origin of the trace
667+
*/
668+
void setTrace(
669+
final @NotNull String traceId,
670+
final @NotNull String spanId,
671+
final @Nullable Double sampleRate,
672+
final @Nullable Double sampleRand);
667673

668674
/**
669675
* Returns the "sentry-trace" header that allows tracing across services. Can also be used in

sentry/src/main/java/io/sentry/NoOpHub.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ public void reportFullyDisplayed() {}
277277
}
278278

279279
@Override
280-
public void setTrace(final @NotNull String traceID, final @NotNull String spanId) {}
280+
public void setTrace(
281+
final @NotNull String traceId,
282+
final @NotNull String spanId,
283+
final @Nullable Double sampleRate,
284+
final @Nullable Double sampleRand) {}
281285

282286
@Override
283287
public @Nullable SentryTraceHeader getTraceparent() {

sentry/src/main/java/io/sentry/NoOpScopes.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ public void reportFullyDisplayed() {}
272272
}
273273

274274
@Override
275-
public void setTrace(final @NotNull String traceId, final @NotNull String spanId) {}
275+
public void setTrace(
276+
final @NotNull String traceId,
277+
final @NotNull String spanId,
278+
final @Nullable Double sampleRate,
279+
final @Nullable Double sampleRand) {}
276280

277281
@Override
278282
public @Nullable SentryTraceHeader getTraceparent() {

sentry/src/main/java/io/sentry/PropagationContext.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,16 @@ public static PropagationContext fromHeaders(
5252
}
5353

5454
public static @NotNull PropagationContext fromId(
55-
final @NotNull String traceId, final @NotNull String spanId) {
55+
final @NotNull String traceId,
56+
final @NotNull String spanId,
57+
final @Nullable Double decisionSampleRate,
58+
final @Nullable Double decisionSampleRand) {
5659
return new PropagationContext(
57-
new SentryId(traceId), new SpanId(), new SpanId(spanId), null, null);
60+
new SentryId(traceId),
61+
new SpanId(),
62+
new SpanId(spanId),
63+
TracingUtils.ensureBaggage(null, null, decisionSampleRate, decisionSampleRand),
64+
null);
5865
}
5966

6067
private @NotNull SentryId traceId;

sentry/src/main/java/io/sentry/Scopes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,8 @@ public void reportFullyDisplayed() {
991991

992992
@Override
993993
public void setTrace(
994-
final @NotNull String traceId, final @NotNull String spanID) {
995-
@NotNull PropagationContext propagationContext = PropagationContext.fromId(traceId, spanID);
994+
final @NotNull String traceId, final @NotNull String spanId, final @Nullable Double sampleRate, final @Nullable Double sampleRand) {
995+
@NotNull PropagationContext propagationContext = PropagationContext.fromId(traceId, spanId, sampleRate, sampleRand);
996996
configureScope(
997997
(scope) -> {
998998
scope.setPropagationContext(propagationContext);

sentry/src/main/java/io/sentry/ScopesAdapter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,12 @@ public void reportFullyDisplayed() {
322322
}
323323

324324
@Override
325-
public void setTrace(final @NotNull String traceId, final @NotNull String spanId) {
326-
Sentry.getCurrentScopes().setTrace(traceId, spanId);
325+
public void setTrace(
326+
final @NotNull String traceId,
327+
final @NotNull String spanId,
328+
final @Nullable Double sampleRate,
329+
final @Nullable Double sampleRand) {
330+
Sentry.getCurrentScopes().setTrace(traceId, spanId, sampleRate, sampleRand);
327331
}
328332

329333
@Override

0 commit comments

Comments
 (0)