Skip to content

Commit ca95b42

Browse files
committed
Restricting API access
Removed SpanLinkAccessor interface SpanLinkAccessor was intended to limit how the span is modified in DDSpanContext#processTagsAndBaggage, but the trade-off was introducing a public getLinks method on DDSpan. Reduced visibility of processTagsAndBaggage methods on DDSpanContext Since processTagsAndBaggage is really just a helper routine of DDSpan.processTagsAndBaggage and the usage is a bit sensitive, I decided to reduce the visibility
1 parent 9c0745a commit ca95b42

3 files changed

Lines changed: 13 additions & 23 deletions

File tree

dd-trace-core/src/main/java/datadog/trace/core/DDSpan.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* <p>Spans are created by the {@link CoreTracer#buildSpan}. This implementation adds some features
5252
* according to the DD agent.
5353
*/
54-
public class DDSpan implements AgentSpan, CoreSpan<DDSpan>, SpanLinkAccessor, AttachableWrapper {
54+
public class DDSpan implements AgentSpan, CoreSpan<DDSpan>, AttachableWrapper {
5555
private static final Logger log = LoggerFactory.getLogger(DDSpan.class);
5656

5757
static DDSpan create(
@@ -884,8 +884,7 @@ public TraceConfig traceConfig() {
884884
return context.getTraceCollector().getTraceConfig();
885885
}
886886

887-
@Override
888-
public List<? extends AgentSpanLink> getLinks() {
887+
List<? extends AgentSpanLink> getLinks() {
889888
return this.links;
890889
}
891890

@@ -908,8 +907,7 @@ public void addLink(AgentSpanLink link) {
908907
// so just add to the list
909908

910909
// If links still points to EMPTY inside the synchronized block, then construct a new
911-
// CopyOnWriteArrayList
912-
// containing the newly added link
910+
// CopyOnWriteArrayList containing the newly added link
913911

914912
List<AgentSpanLink> links = this.links;
915913
if (links != EMPTY) {

dd-trace-core/src/main/java/datadog/trace/core/DDSpanContext.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import datadog.trace.api.sampling.PrioritySampling;
2525
import datadog.trace.api.sampling.SamplingMechanism;
2626
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
27+
import datadog.trace.bootstrap.instrumentation.api.AppendableSpanLinks;
2728
import datadog.trace.bootstrap.instrumentation.api.Baggage;
2829
import datadog.trace.bootstrap.instrumentation.api.ProfilerContext;
2930
import datadog.trace.bootstrap.instrumentation.api.ProfilingContextIntegration;
@@ -1086,19 +1087,23 @@ public <T> void setMetaStruct(final String field, final T value) {
10861087
}
10871088
}
10881089

1089-
public void earlyProcessTags(SpanLinkAccessor links) {
1090+
void earlyProcessTags(AppendableSpanLinks links) {
10901091
synchronized (unsafeTags) {
10911092
TagsPostProcessorFactory.eagerProcessor().processTags(unsafeTags, this, links);
10921093
}
10931094
}
10941095

1095-
public void processTagsAndBaggage(
1096-
final MetadataConsumer consumer, int longRunningVersion, SpanLinkAccessor links) {
1096+
void processTagsAndBaggage(
1097+
final MetadataConsumer consumer, int longRunningVersion, DDSpan restrictedSpan) {
1098+
// NOTE: The span is passed for the sole purpose of allowing updating & reading of the span links
1099+
// This is a compromise to avoid...
1100+
// - creating an extra wrapper object that would create significant allocation
1101+
// - implementing an interface to read the spans that require making the read method public
10971102
synchronized (unsafeTags) {
10981103
// Tags
1099-
TagsPostProcessorFactory.lazyProcessor().processTags(unsafeTags, this, links);
1104+
TagsPostProcessorFactory.lazyProcessor().processTags(unsafeTags, this, restrictedSpan);
11001105

1101-
String linksTag = DDSpanLink.toTag(links.getLinks());
1106+
String linksTag = DDSpanLink.toTag(restrictedSpan.getLinks());
11021107
if (linksTag != null) {
11031108
unsafeTags.put(SPAN_LINKS, linksTag);
11041109
}

dd-trace-core/src/main/java/datadog/trace/core/SpanLinkAccessor.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)