Skip to content

Commit 31c4435

Browse files
kirrg001aryamohanan
authored andcommitted
fix: bumped @opentelemetry/sdk-trace-base to v2 (#2196)
refs https://jsw.ibm.com/browse/INSTA-65941
1 parent 5d688e2 commit 31c4435

5 files changed

Lines changed: 69 additions & 50 deletions

File tree

package-lock.json

Lines changed: 49 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/collector/test/tracing/opentelemetry/test.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,10 @@ mochaSuiteFn('opentelemetry tests', function () {
915915
dataProperty: 'tags',
916916
extraTests: span => {
917917
expect(span.data.tags.name).to.eql('fs readFileSync');
918-
checkTelemetryResourceAttrs(span);
918+
919+
// This test uses a global OpenTelemetry SDK instance, which still uses sdk version v1.
920+
// Its nice to keep it like that to proof that v1 and v2 work fine with our integration.
921+
checkTelemetryResourceAttrs(span, /1\.\d+\.\d/);
919922
}
920923
});
921924

@@ -928,7 +931,7 @@ mochaSuiteFn('opentelemetry tests', function () {
928931
dataProperty: 'tags',
929932
extraTests: span => {
930933
expect(span.data.tags.name).to.eql('fs statSync');
931-
checkTelemetryResourceAttrs(span);
934+
checkTelemetryResourceAttrs(span, /1\.\d+\.\d/);
932935
}
933936
});
934937
})
@@ -995,8 +998,8 @@ mochaSuiteFn('opentelemetry tests', function () {
995998
expect(response.otelspan.name).to.eql('explicit-otel-operation');
996999
expect(response.otelspan._spanContext).to.have.property('traceId');
9971000
expect(response.otelspan._spanContext).to.have.property('spanId');
998-
expect(response.otelspan.instrumentationLibrary).to.be.an('object');
999-
expect(response.otelspan.instrumentationLibrary.name).to.eql('otel-sdk-app-tracer');
1001+
expect(response.otelspan.instrumentationScope).to.be.an('object');
1002+
expect(response.otelspan.instrumentationScope.name).to.eql('otel-sdk-app-tracer');
10001003
})
10011004
.then(() => delay(DELAY_TIMEOUT_IN_MS))
10021005
.then(() =>
@@ -1021,11 +1024,11 @@ mochaSuiteFn('opentelemetry tests', function () {
10211024
});
10221025
});
10231026

1024-
function checkTelemetryResourceAttrs(span) {
1027+
function checkTelemetryResourceAttrs(span, otelSdkVersion = /2\.\d+\.\d/) {
10251028
expect(span.data.resource['service.name']).to.not.exist;
10261029
expect(span.data.resource['telemetry.sdk.language']).to.eql('nodejs');
10271030
expect(span.data.resource['telemetry.sdk.name']).to.eql('opentelemetry');
1028-
expect(span.data.resource['telemetry.sdk.version']).to.match(/1\.\d+\.\d/);
1031+
expect(span.data.resource['telemetry.sdk.version']).to.match(otelSdkVersion);
10291032
}
10301033

10311034
function verifyHttpExit(spans, parentSpan) {

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"@opentelemetry/instrumentation-restify": "0.53.0",
6565
"@opentelemetry/instrumentation-socket.io": "0.54.0",
6666
"@opentelemetry/instrumentation-tedious": "0.27.0",
67-
"@opentelemetry/sdk-trace-base": "1.25.0",
67+
"@opentelemetry/sdk-trace-base": "2.2.0",
6868
"cls-bluebird": "^2.1.0",
6969
"import-in-the-middle": "2.0.0",
7070
"lru-cache": "^10.1.0",

packages/core/src/tracing/opentelemetry-instrumentations/tedious.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ module.exports.init = () => {
1818
instrumentation.enable();
1919
}
2020
};
21-
exports.transform = otelSpan => {
22-
// NOTE: This assignment is necessary to display the database name in the UI.
23-
// In the backend, for OpenTelemetry, the service name is based on the OpenTelemetry span attribute service.name.
24-
if (otelSpan.attributes && 'db.name' in otelSpan.attributes) {
25-
otelSpan.resource._attributes['service.name'] = otelSpan.attributes['db.name'];
26-
}
27-
return otelSpan;
28-
};
2921

3022
module.exports.getKind = () => {
3123
const kind = constants.EXIT;

packages/core/src/tracing/opentelemetry-instrumentations/wrap.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

0 commit comments

Comments
 (0)