@@ -40,11 +40,19 @@ module.exports.init = (_config, cls) => {
4040 } ) ;
4141
4242 const transformToInstanaSpan = otelSpan => {
43- if ( ! otelSpan || ! otelSpan . instrumentationLibrary ) {
43+ // TODO: remove instrumentationLibrary in next major release
44+ // instrumentationScope was introduced in OpenTelemetry v2
45+ if ( ! otelSpan || ( ! otelSpan . instrumentationScope && ! otelSpan . instrumentationLibrary ) ) {
46+ return ;
47+ }
48+
49+ const targetInstrumentionName =
50+ otelSpan . instrumentationScope ?. name || otelSpan . instrumentationLibrary ?. name || null ;
51+
52+ if ( ! targetInstrumentionName ) {
4453 return ;
4554 }
4655
47- const targetInstrumentionName = otelSpan . instrumentationLibrary . name ;
4856 let kind = constants . EXIT ;
4957
5058 if ( instrumentations [ targetInstrumentionName ] && instrumentations [ targetInstrumentionName ] . module ) {
@@ -73,11 +81,22 @@ module.exports.init = (_config, cls) => {
7381
7482 try {
7583 cls . ns . runAndReturn ( ( ) => {
84+ // NOTE: 'service.name' is "unknown" - probably because we don't setup otel completely.
85+ // The removal fixes incorrect infrastructure correlation.
86+ delete otelSpan . resource . attributes [ 'service.name' ] ;
87+
7688 const instanaSpan = cls . startSpan ( {
7789 spanName : 'otel' ,
7890 kind : kind
7991 } ) ;
92+
93+ // opentelemetry/instrumentation-fs -> we only want the name behind instrumentation-
94+ const operation = targetInstrumentionName . split ( '-' ) . pop ( ) ;
95+
8096 instanaSpan . data = {
97+ // span.data.operation is mapped to endpoint for otel span plugin in BE. We need to set the endpoint otherwise
98+ // the ui will show unspecified
99+ operation,
81100 tags : Object . assign ( { name : otelSpan . name } , otelSpan . attributes ) ,
82101 resource : otelSpan . resource . attributes
83102 } ;
0 commit comments