22
33import static datadog .trace .api .DDSpanTypes .HTTP_CLIENT ;
44import static datadog .trace .api .DDSpanTypes .HTTP_SERVER ;
5+ import static datadog .trace .api .DDSpanTypes .INTERNAL ;
56import static datadog .trace .api .DDSpanTypes .MESSAGE_CONSUMER ;
67import static datadog .trace .api .DDSpanTypes .MESSAGE_PRODUCER ;
8+ import static datadog .trace .bootstrap .instrumentation .api .Tags .SPAN_KIND ;
9+ import static datadog .trace .bootstrap .instrumentation .api .Tags .SPAN_KIND_CLIENT ;
10+ import static datadog .trace .bootstrap .instrumentation .api .Tags .SPAN_KIND_CONSUMER ;
11+ import static datadog .trace .bootstrap .instrumentation .api .Tags .SPAN_KIND_INTERNAL ;
12+ import static datadog .trace .bootstrap .instrumentation .api .Tags .SPAN_KIND_PRODUCER ;
13+ import static datadog .trace .bootstrap .instrumentation .api .Tags .SPAN_KIND_SERVER ;
714import static java .lang .Math .min ;
815
916import datadog .trace .api .InstrumenterConfig ;
@@ -54,13 +61,13 @@ protected CharSequence component() {
5461
5562 public AgentSpan startMethodSpan (Method method ) {
5663 CharSequence operationName = null ;
57- CharSequence spanType = null ;
64+ SpanKind spanKind = null ;
5865 boolean inheritContext = true ;
5966
6067 WithSpan withSpanAnnotation = method .getAnnotation (WithSpan .class );
6168 if (withSpanAnnotation != null ) {
6269 operationName = withSpanAnnotation .value ();
63- spanType = convertToSpanType ( withSpanAnnotation .kind () );
70+ spanKind = withSpanAnnotation .kind ();
6471 if (INHERIT_CONTEXT_MH != null ) {
6572 try {
6673 inheritContext = (boolean ) INHERIT_CONTEXT_MH .invokeExact (withSpanAnnotation );
@@ -82,8 +89,9 @@ public AgentSpan startMethodSpan(Method method) {
8289 final AgentSpan span = spanBuilder .start ();
8390 DECORATE .afterStart (span );
8491
85- if (spanType != null ) {
86- span .setSpanType (spanType );
92+ if (spanKind != null ) {
93+ span .setSpanType (convertToSpanType (spanKind ));
94+ span .setTag (SPAN_KIND , convertToSpanKindTag (spanKind ));
8795 }
8896 if (InstrumenterConfig .get ().isMethodMeasured (method )) {
8997 span .setMeasured (true );
@@ -106,6 +114,28 @@ private static String convertToSpanType(SpanKind kind) {
106114 case CONSUMER :
107115 return MESSAGE_CONSUMER ;
108116 case INTERNAL :
117+ // checking for SpanKind.INTERNAL, returning DDSpanTypes.INTERNAL
118+ return INTERNAL ;
119+ default :
120+ return null ;
121+ }
122+ }
123+
124+ private static String convertToSpanKindTag (SpanKind kind ) {
125+ if (kind == null ) {
126+ return null ;
127+ }
128+ switch (kind ) {
129+ case CLIENT :
130+ return SPAN_KIND_CLIENT ;
131+ case SERVER :
132+ return SPAN_KIND_SERVER ;
133+ case PRODUCER :
134+ return SPAN_KIND_PRODUCER ;
135+ case CONSUMER :
136+ return SPAN_KIND_CONSUMER ;
137+ case INTERNAL :
138+ return SPAN_KIND_INTERNAL ;
109139 default :
110140 return null ;
111141 }
0 commit comments