Skip to content

Commit 700b1c3

Browse files
committed
Add suggestions
1 parent 59512b0 commit 700b1c3

File tree

4 files changed

+55
-23
lines changed

4 files changed

+55
-23
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/WebsocketDecorator.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import datadog.trace.api.time.SystemTimeSource;
2020
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
2121
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
22+
import datadog.trace.bootstrap.instrumentation.api.NotSampledSpanContext;
2223
import datadog.trace.bootstrap.instrumentation.api.SpanAttributes;
2324
import datadog.trace.bootstrap.instrumentation.api.SpanLink;
2425
import datadog.trace.bootstrap.instrumentation.api.Tags;
@@ -163,7 +164,13 @@ private AgentSpan onFrameStart(
163164
// the link is not added if the user wants to have receive frames on the same trace as the
164165
// handshake
165166
wsSpan.addLink(
166-
SpanLink.from(handshakeSpan.context(), (byte) 0, "", linkAttributes, inheritSampling));
167+
SpanLink.from(
168+
inheritSampling
169+
? handshakeSpan.context()
170+
: new NotSampledSpanContext(handshakeSpan.context()),
171+
SpanLink.DEFAULT_FLAGS,
172+
"",
173+
linkAttributes));
167174
}
168175
}
169176
return wsSpan;

internal-api/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ excludedClassesCoverage += [
9696
"datadog.trace.bootstrap.instrumentation.api.NoopScope",
9797
"datadog.trace.bootstrap.instrumentation.api.NoopSpan",
9898
"datadog.trace.bootstrap.instrumentation.api.NoopSpanContext",
99+
"datadog.trace.bootstrap.instrumentation.api.NotSampledSpanContext",
99100
"datadog.trace.bootstrap.instrumentation.api.ResourceNamePriorities",
100101
"datadog.trace.bootstrap.instrumentation.api.Schema",
101102
"datadog.trace.bootstrap.instrumentation.api.ScopeSource",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package datadog.trace.bootstrap.instrumentation.api;
2+
3+
import datadog.trace.api.DDTraceId;
4+
import datadog.trace.api.datastreams.PathwayContext;
5+
import datadog.trace.api.sampling.PrioritySampling;
6+
import java.util.Map;
7+
8+
/** An {@link AgentSpanContext} that hides the sampling priority. */
9+
public final class NotSampledSpanContext implements AgentSpanContext {
10+
private final AgentSpanContext delegate;
11+
12+
public NotSampledSpanContext(AgentSpanContext delegate) {
13+
this.delegate = delegate;
14+
}
15+
16+
@Override
17+
public DDTraceId getTraceId() {
18+
return delegate.getTraceId();
19+
}
20+
21+
@Override
22+
public long getSpanId() {
23+
return delegate.getSpanId();
24+
}
25+
26+
@Override
27+
public AgentTraceCollector getTraceCollector() {
28+
return delegate.getTraceCollector();
29+
}
30+
31+
@Override
32+
public int getSamplingPriority() {
33+
return PrioritySampling.UNSET;
34+
}
35+
36+
@Override
37+
public Iterable<Map.Entry<String, String>> baggageItems() {
38+
return delegate.baggageItems();
39+
}
40+
41+
@Override
42+
public PathwayContext getPathwayContext() {
43+
return delegate.getPathwayContext();
44+
}
45+
}

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/SpanLink.java

+1-22
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,7 @@ public static SpanLink from(AgentSpanContext context) {
4848
*/
4949
public static SpanLink from(
5050
AgentSpanContext context, byte traceFlags, String traceState, SpanAttributes attributes) {
51-
return from(context, traceFlags, traceState, attributes, true);
52-
}
53-
54-
/**
55-
* Creates a span link from a span context with W3C trace state and custom attributes. Gathers the
56-
* trace and span identifiers from the given instance.
57-
*
58-
* @param context The context of the span to get the link to.
59-
* @param traceFlags The W3C formatted trace flags.
60-
* @param traceState The W3C formatted trace state.
61-
* @param attributes The link attributes.
62-
* @param inheritSampling if true the sampling flag will be set based on the context's sampling
63-
* priority.
64-
* @return A span link to the given context.
65-
*/
66-
public static SpanLink from(
67-
AgentSpanContext context,
68-
byte traceFlags,
69-
String traceState,
70-
SpanAttributes attributes,
71-
boolean inheritSampling) {
72-
if (inheritSampling && context.getSamplingPriority() > 0) {
51+
if (context.getSamplingPriority() > 0) {
7352
traceFlags = (byte) (traceFlags | SAMPLED_FLAG);
7453
}
7554
return new SpanLink(

0 commit comments

Comments
 (0)