20
20
21
21
import co .elastic .apm .agent .impl .context .ServiceTargetImpl ;
22
22
import co .elastic .apm .agent .impl .transaction .*;
23
- import co .elastic .apm .agent .impl .transaction .TransactionImpl ;
24
23
import co .elastic .apm .agent .opentelemetry .global .ElasticOpenTelemetry ;
25
24
import co .elastic .apm .agent .opentelemetry .tracing .ElasticOpenTelemetryTest ;
26
25
import co .elastic .apm .agent .opentelemetry .tracing .OTelSpan ;
34
33
import io .opentelemetry .api .trace .SpanKind ;
35
34
import io .opentelemetry .api .trace .StatusCode ;
36
35
import io .opentelemetry .context .Context ;
37
- import io .opentelemetry .semconv .SemanticAttributes ;
38
36
39
37
import javax .annotation .Nullable ;
40
38
import java .util .HashMap ;
@@ -103,7 +101,7 @@ public void bridgedTransactionWithRemoteContextParent() {
103
101
assertThat (traceContext .getTraceId ().toString ()).isEqualTo (REMOTE_PARENT_TRACE_ID );
104
102
}
105
103
106
- private Context getRemoteContext (){
104
+ private Context getRemoteContext () {
107
105
return getOtel ().getPropagators ()
108
106
.getTextMapPropagator ()
109
107
.extract (Context .current (),
@@ -113,7 +111,7 @@ private Context getRemoteContext(){
113
111
}
114
112
115
113
@ Given ("OTel span is created without parent" )
116
- public void createOTelSpanWithoutParent (){
114
+ public void createOTelSpanWithoutParent () {
117
115
otelSpan = (OTelSpan ) getOtel ().getTracer ("" )
118
116
.spanBuilder ("otel span" )
119
117
.setNoParent () // redundant, but makes it explicit
@@ -156,14 +154,14 @@ public void otelSpanIsCreatedWithKind(String kind) {
156
154
// the parent transaction is created by another step definition, thus we reuse the existing state
157
155
TransactionImpl parentTransaction = state .getTransaction ();
158
156
159
- Function <String ,OTelSpan > createSpanWithKind = k -> {
157
+ Function <String , OTelSpan > createSpanWithKind = k -> {
160
158
SpanBuilder spanBuilder = getOtel ().getTracer ("" )
161
159
.spanBuilder ("span" )
162
160
.setSpanKind (SpanKind .valueOf (k ));
163
161
return (OTelSpan ) spanBuilder .startSpan ();
164
162
};
165
163
166
- if ( parentTransaction != null ){
164
+ if ( parentTransaction != null ) {
167
165
// creating a span as a child of existing transaction
168
166
try (Scope scope = parentTransaction .activateInScope ()) {
169
167
this .otelSpan = createSpanWithKind .apply (kind );
@@ -205,40 +203,19 @@ public void otelSpanAttributes(io.cucumber.datatable.DataTable table) {
205
203
}
206
204
207
205
private static AttributeKey <?> lookupKey (String name ) {
206
+ // only doing a simple type mapping to cover existing test cases
207
+ // this is not meant to be exhaustive nor to cover up-to-date semconv definitions
208
208
switch (name ) {
209
- case "http.url" :
210
- return SemanticAttributes .HTTP_URL ;
211
- case "http.scheme" :
212
- return SemanticAttributes .HTTP_SCHEME ;
213
- case "http.host" :
214
- return SemanticAttributes .HTTP_HOST ;
215
- case "net.peer.name" :
216
- return SemanticAttributes .NET_PEER_NAME ;
217
- case "net.peer.ip" :
218
- return SemanticAttributes .NET_PEER_IP ;
219
209
case "net.peer.port" :
220
- return SemanticAttributes .NET_PEER_PORT ;
221
- case "db.system" :
222
- return SemanticAttributes .DB_SYSTEM ;
223
- case "db.name" :
224
- return SemanticAttributes .DB_NAME ;
225
- case "messaging.system" :
226
- return SemanticAttributes .MESSAGING_SYSTEM ;
227
- case "messaging.url" :
228
- return SemanticAttributes .MESSAGING_URL ;
229
- case "messaging.destination" :
230
- return SemanticAttributes .MESSAGING_DESTINATION ;
231
- case "rpc.system" :
232
- return SemanticAttributes .RPC_SYSTEM ;
233
- case "rpc.service" :
234
- return SemanticAttributes .RPC_SERVICE ;
210
+ return AttributeKey .longKey (name );
235
211
default :
236
- throw new IllegalArgumentException ("unknown key for name " + name );
212
+ return AttributeKey .stringKey (name );
213
+
237
214
}
238
215
}
239
216
240
217
@ Then ("Elastic bridged (transaction|span) OTel kind is {string}" )
241
- public void bridgeObjectKind (String kind ){
218
+ public void bridgeObjectKind (String kind ) {
242
219
assertThat (getBridgedAbstractSpan ().getOtelKind ())
243
220
.isEqualTo (OTelSpanKind .valueOf (kind ));
244
221
}
@@ -325,7 +302,7 @@ public void bridgedSpanTargetServiceType(String type, String name) {
325
302
}
326
303
327
304
@ Then ("OTel span status set to {string}" )
328
- public void setOtelSpanStatus (String status ){
305
+ public void setOtelSpanStatus (String status ) {
329
306
otelSpan .setStatus (StatusCode .valueOf (status .toUpperCase (Locale .ROOT )));
330
307
}
331
308
0 commit comments