11package com .datadoghq .trace .impl ;
22
3+ import com .fasterxml .jackson .annotation .JsonGetter ;
4+ import com .fasterxml .jackson .annotation .JsonIgnore ;
5+ import io .opentracing .Span ;
6+ import org .slf4j .Logger ;
7+ import org .slf4j .LoggerFactory ;
8+
39import java .util .HashMap ;
410import java .util .List ;
511import java .util .Map ;
612import java .util .Map .Entry ;
713import java .util .concurrent .TimeUnit ;
814
9- import org .slf4j .Logger ;
10- import org .slf4j .LoggerFactory ;
11-
12- import com .fasterxml .jackson .annotation .JsonGetter ;
13- import com .fasterxml .jackson .annotation .JsonIgnore ;
14-
15- import io .opentracing .Span ;
16-
1715/**
1816 * Represents an in-flight span in the opentracing system.
1917 * <p>
2220 */
2321public class DDSpan implements io .opentracing .Span {
2422
25- /**
26- * Each span have an operation name describing the current span
27- */
28- private String operationName ;
29- /**
30- * Tags are associated to the current span, they will not propagate to the children span
31- */
32- private Map <String , Object > tags ;
23+
3324 /**
3425 * StartTime stores the creation time of the span in milliseconds
3526 */
@@ -53,19 +44,13 @@ public class DDSpan implements io.opentracing.Span {
5344 * A simple constructor.
5445 * Currently, users have
5546 *
56- * @param operationName the operation name associated to the span
57- * @param tags Tags attached to the span
5847 * @param timestampMicro if set, use this time instead of the auto-generated time
5948 * @param context the context
6049 */
6150 protected DDSpan (
62- String operationName ,
63- Map <String , Object > tags ,
6451 long timestampMicro ,
6552 DDSpanContext context ) {
6653
67- this .operationName = operationName ;
68- this .tags = tags ;
6954 this .context = context ;
7055
7156 // record the start time in nano (current milli + nano delta)
@@ -79,11 +64,6 @@ protected DDSpan(
7964 // track each span of the trace
8065 this .context .getTrace ().add (this );
8166
82- // check DD attributes required
83- // FIXME Remove IAE
84- if (this .context .getServiceName () == null ) {
85- throw new IllegalArgumentException ("No ServiceName provided" );
86- }
8767 }
8868
8969 /* (non-Javadoc)
@@ -145,34 +125,26 @@ private boolean isRootSpan() {
145125 * @see io.opentracing.Span#setTag(java.lang.String, java.lang.String)
146126 */
147127 public Span setTag (String tag , String value ) {
148- return setTag (tag , (Object ) value );
128+ this .context ().setTag (tag , (Object ) value );
129+ return this ;
149130 }
150131
151132 /* (non-Javadoc)
152133 * @see io.opentracing.Span#setTag(java.lang.String, boolean)
153134 */
154135 public Span setTag (String tag , boolean value ) {
155- return setTag (tag , (Object ) value );
136+ this .context ().setTag (tag , (Object ) value );
137+ return this ;
156138 }
157139
158140 /* (non-Javadoc)
159141 * @see io.opentracing.Span#setTag(java.lang.String, java.lang.Number)
160142 */
161143 public Span setTag (String tag , Number value ) {
162- return this .setTag (tag , (Object ) value );
144+ this .context ().setTag (tag , (Object ) value );
145+ return this ;
163146 }
164147
165- /**
166- * Add a tag to the span. Tags are not propagated to the children
167- *
168- * @param tag the tag-name
169- * @param value the value of the value
170- * @return the builder instance
171- */
172- private Span setTag (String tag , Object value ) {
173- tags .put (tag , value );
174- return this ;
175- }
176148
177149 /* (non-Javadoc)
178150 * @see io.opentracing.Span#context()
@@ -200,11 +172,7 @@ public String getBaggageItem(String key) {
200172 * @see io.opentracing.Span#setOperationName(java.lang.String)
201173 */
202174 public Span setOperationName (String operationName ) {
203- // FIXME operationName is in each constructor --> always IAE
204- if (this .operationName != null ) {
205- throw new IllegalArgumentException ("The operationName is already assigned." );
206- }
207- this .operationName = operationName ;
175+ this .context ().setOperationName (operationName );
208176 return this ;
209177 }
210178
@@ -258,15 +226,6 @@ public Span log(long l, String s, Object o) {
258226
259227
260228 //Getters and JSON serialisation instructions
261- @ JsonGetter ("name" )
262- public String getOperationName () {
263- return operationName ;
264- }
265-
266- @ JsonIgnore
267- public Map <String , Object > getTags () {
268- return this .tags ;
269- }
270229
271230 /**
272231 * Meta merges baggage and tags (stringified values)
@@ -295,8 +254,8 @@ public long getDurationNano() {
295254 return durationNano ;
296255 }
297256
298- @ JsonGetter
299- public String getService () {
257+ @ JsonGetter ( "service" )
258+ public String getServiceName () {
300259 return context .getServiceName ();
301260 }
302261
@@ -317,9 +276,18 @@ public long getParentId() {
317276
318277 @ JsonGetter ("resource" )
319278 public String getResourceName () {
320- return context .getResourceName () == null ? this .operationName : context .getResourceName ();
279+ return context .getResourceName () == null ? context .getOperationName () : context .getResourceName ();
280+ }
281+
282+ @ JsonGetter ("name" )
283+ public String getOperationName () {
284+ return this .context ().getOperationName ();
321285 }
322286
287+ @ JsonIgnore
288+ public Map <String , Object > getTags () {
289+ return this .context ().getTags ();
290+ }
323291 @ JsonGetter
324292 public String getType () {
325293 return context .getSpanType ();
@@ -335,4 +303,19 @@ public String toString() {
335303 return context .toString ();
336304 }
337305
306+
307+ public Span setServiceName (String serviceName ) {
308+ this .context ().setServiceName (serviceName );
309+ return this ;
310+ }
311+
312+ public Span setResourceName (String resourceName ) {
313+ this .context ().setResourceName (resourceName );
314+ return this ;
315+ }
316+
317+ public Span setType (String type ) {
318+ this .context ().setType (type );
319+ return this ;
320+ }
338321}
0 commit comments