2424public class DDSpanContext implements io .opentracing .SpanContext {
2525 public static final String PRIORITY_SAMPLING_KEY = "_sampling_priority_v1" ;
2626 public static final String SAMPLE_RATE_KEY = "_sample_rate" ;
27+ public static final String ORIGIN_KEY = "_dd.origin" ;
2728
2829 private static final Map <String , Number > EMPTY_METRICS = Collections .emptyMap ();
2930
@@ -62,6 +63,8 @@ public class DDSpanContext implements io.opentracing.SpanContext {
6263 * <p>For thread safety, this boolean is only modified or accessed under instance lock.
6364 */
6465 private boolean samplingPriorityLocked = false ;
66+ /** The origin of the trace. (eg. Synthetics) */
67+ private final String origin ;
6568 /** Metrics on the span */
6669 private final AtomicReference <Map <String , Number >> metrics = new AtomicReference <>();
6770
@@ -77,6 +80,7 @@ public DDSpanContext(
7780 final String operationName ,
7881 final String resourceName ,
7982 final int samplingPriority ,
83+ final String origin ,
8084 final Map <String , String > baggageItems ,
8185 final boolean errorFlag ,
8286 final String spanType ,
@@ -111,10 +115,20 @@ public DDSpanContext(
111115 this .resourceName = resourceName ;
112116 this .errorFlag = errorFlag ;
113117 this .spanType = spanType ;
118+ this .origin = origin ;
114119
115120 if (samplingPriority != PrioritySampling .UNSET ) {
116121 setSamplingPriority (samplingPriority );
117122 }
123+
124+ if (spanType != null ) {
125+ this .tags .put (DDTags .SPAN_TYPE , spanType );
126+ }
127+ if (origin != null ) {
128+ this .tags .put (ORIGIN_KEY , origin );
129+ }
130+ this .tags .put (DDTags .THREAD_NAME , threadName );
131+ this .tags .put (DDTags .THREAD_ID , threadId );
118132 }
119133
120134 public String getTraceId () {
@@ -167,6 +181,11 @@ public String getSpanType() {
167181
168182 public void setSpanType (final String spanType ) {
169183 this .spanType = spanType ;
184+ if (spanType == null ) {
185+ tags .remove (DDTags .SPAN_TYPE );
186+ } else {
187+ tags .put (DDTags .SPAN_TYPE , spanType );
188+ }
170189 }
171190
172191 public void setSamplingPriority (final int newPriority ) {
@@ -236,6 +255,15 @@ public boolean lockSamplingPriority() {
236255 }
237256 }
238257
258+ public String getOrigin () {
259+ final DDSpan rootSpan = trace .getRootSpan ();
260+ if (null != rootSpan ) {
261+ return rootSpan .context ().origin ;
262+ } else {
263+ return origin ;
264+ }
265+ }
266+
239267 public void setBaggageItem (final String key , final String value ) {
240268 baggageItems .put (key , value );
241269 }
@@ -312,12 +340,6 @@ public synchronized void setTag(final String tag, final Object value) {
312340 }
313341
314342 public synchronized Map <String , Object > getTags () {
315- tags .put (DDTags .THREAD_NAME , threadName );
316- tags .put (DDTags .THREAD_ID , threadId );
317- final String spanType = getSpanType ();
318- if (spanType != null ) {
319- tags .put (DDTags .SPAN_TYPE , spanType );
320- }
321343 return Collections .unmodifiableMap (tags );
322344 }
323345
0 commit comments