From 54f09d42903cf759a9e929100eafa71fc4f97248 Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Fri, 24 Nov 2023 08:25:58 +1100 Subject: [PATCH 1/4] fix: support otel v0.12.0 context propagation --- packages/instrumentation-kafkajs/src/kafkajs.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/instrumentation-kafkajs/src/kafkajs.ts b/packages/instrumentation-kafkajs/src/kafkajs.ts index 6c7bb711..20b1a6b1 100644 --- a/packages/instrumentation-kafkajs/src/kafkajs.ts +++ b/packages/instrumentation-kafkajs/src/kafkajs.ts @@ -8,7 +8,6 @@ import { trace, context, diag, - ROOT_CONTEXT, } from '@opentelemetry/api'; import { SemanticAttributes, @@ -137,7 +136,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase const self = this; return function (payload: EachMessagePayload): Promise { const propagatedContext: Context = propagation.extract( - ROOT_CONTEXT, + context.active(), payload.message.headers, bufferTextMapGetter ); @@ -163,12 +162,12 @@ export class KafkaJsInstrumentation extends InstrumentationBase payload.batch.topic, undefined, MessagingOperationValues.RECEIVE, - ROOT_CONTEXT + context.active() ); return context.with(trace.setSpan(context.active(), receivingSpan), () => { const spans = payload.batch.messages.map((message: KafkaMessage) => { const propagatedContext: Context = propagation.extract( - ROOT_CONTEXT, + context.active(), message.headers, bufferTextMapGetter ); From 34e9cad2b848cee22e23c9fc2b152d477a78fc89 Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Mon, 27 Nov 2023 19:29:10 +1100 Subject: [PATCH 2/4] fix: build failure due to version mismatch --- detectors/node/resource-detector-deployment/package.json | 2 +- detectors/node/resource-detector-git/package.json | 2 +- detectors/node/resource-detector-service/package.json | 2 +- detectors/resource-detector-sync-api/package.json | 2 +- packages/instrumentation-elasticsearch/package.json | 2 +- packages/instrumentation-express/package.json | 2 +- packages/instrumentation-kafkajs/package.json | 2 +- packages/instrumentation-neo4j/package.json | 2 +- packages/instrumentation-node-cache/package.json | 2 +- packages/instrumentation-sequelize/package.json | 2 +- packages/instrumentation-typeorm/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/detectors/node/resource-detector-deployment/package.json b/detectors/node/resource-detector-deployment/package.json index a042bf01..01a41e72 100644 --- a/detectors/node/resource-detector-deployment/package.json +++ b/detectors/node/resource-detector-deployment/package.json @@ -36,7 +36,7 @@ "@opentelemetry/api": "^1.6.0" }, "dependencies": { - "@opentelemetry/resources": "~1.17.1", + "@opentelemetry/resources": "^1.17.1", "@opentelemetry/semantic-conventions": "^1.17.1", "opentelemetry-resource-detector-sync-api": "^0.29.0" }, diff --git a/detectors/node/resource-detector-git/package.json b/detectors/node/resource-detector-git/package.json index af304641..1c5fb0f6 100644 --- a/detectors/node/resource-detector-git/package.json +++ b/detectors/node/resource-detector-git/package.json @@ -37,7 +37,7 @@ "@opentelemetry/api": "^1.6.0" }, "dependencies": { - "@opentelemetry/resources": "~1.17.1", + "@opentelemetry/resources": "^1.17.1", "@opentelemetry/semantic-conventions": "^1.17.1", "opentelemetry-resource-detector-sync-api": "^0.29.0", "uuid": "^8.3.2" diff --git a/detectors/node/resource-detector-service/package.json b/detectors/node/resource-detector-service/package.json index f7760300..a919b79b 100644 --- a/detectors/node/resource-detector-service/package.json +++ b/detectors/node/resource-detector-service/package.json @@ -36,7 +36,7 @@ "@opentelemetry/api": "^1.6.0" }, "dependencies": { - "@opentelemetry/resources": "~1.17.1", + "@opentelemetry/resources": "^1.17.1", "@opentelemetry/semantic-conventions": "^1.17.1", "opentelemetry-resource-detector-sync-api": "^0.29.0", "uuid": "^8.3.2" diff --git a/detectors/resource-detector-sync-api/package.json b/detectors/resource-detector-sync-api/package.json index 1a8570d8..9eaa75d6 100644 --- a/detectors/resource-detector-sync-api/package.json +++ b/detectors/resource-detector-sync-api/package.json @@ -33,7 +33,7 @@ "@opentelemetry/api": "^1.6.0" }, "dependencies": { - "@opentelemetry/resources": "~1.17.1" + "@opentelemetry/resources": "^1.17.1" }, "devDependencies": { "@opentelemetry/api": "^1.6.0", diff --git a/packages/instrumentation-elasticsearch/package.json b/packages/instrumentation-elasticsearch/package.json index 6c2686ac..e19c7cd9 100644 --- a/packages/instrumentation-elasticsearch/package.json +++ b/packages/instrumentation-elasticsearch/package.json @@ -46,7 +46,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.17.1", - "@opentelemetry/instrumentation": "^0.44.0", + "@opentelemetry/instrumentation": "^0.45.1", "@opentelemetry/semantic-conventions": "^1.17.1" }, "devDependencies": { diff --git a/packages/instrumentation-express/package.json b/packages/instrumentation-express/package.json index ca28cb22..e770663c 100644 --- a/packages/instrumentation-express/package.json +++ b/packages/instrumentation-express/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.17.1", - "@opentelemetry/instrumentation": "^0.44.0", + "@opentelemetry/instrumentation": "^0.45.1", "@opentelemetry/semantic-conventions": "^1.17.1", "parseurl": "~1.3.3", "path-to-regexp": "0.1.7" diff --git a/packages/instrumentation-kafkajs/package.json b/packages/instrumentation-kafkajs/package.json index bae6b983..4ae7c39d 100644 --- a/packages/instrumentation-kafkajs/package.json +++ b/packages/instrumentation-kafkajs/package.json @@ -38,7 +38,7 @@ "@opentelemetry/api": "^1.6.0" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.44.0", + "@opentelemetry/instrumentation": "^0.45.1", "@opentelemetry/semantic-conventions": "^1.17.1" }, "devDependencies": { diff --git a/packages/instrumentation-neo4j/package.json b/packages/instrumentation-neo4j/package.json index a7f19ebb..5e5e813e 100644 --- a/packages/instrumentation-neo4j/package.json +++ b/packages/instrumentation-neo4j/package.json @@ -44,7 +44,7 @@ "@opentelemetry/api": "^1.6.0" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.44.0", + "@opentelemetry/instrumentation": "^0.45.1", "@opentelemetry/semantic-conventions": "^1.17.1" }, "devDependencies": { diff --git a/packages/instrumentation-node-cache/package.json b/packages/instrumentation-node-cache/package.json index cd1ed0d9..adc97d97 100644 --- a/packages/instrumentation-node-cache/package.json +++ b/packages/instrumentation-node-cache/package.json @@ -44,7 +44,7 @@ "dependencies": { "@opentelemetry/contrib-test-utils": "^0.34.2", "@opentelemetry/core": "^1.17.1", - "@opentelemetry/instrumentation": "^0.44.0", + "@opentelemetry/instrumentation": "^0.45.1", "@opentelemetry/semantic-conventions": "^1.17.1" }, "devDependencies": { diff --git a/packages/instrumentation-sequelize/package.json b/packages/instrumentation-sequelize/package.json index f1bd6a5f..cdf1392b 100644 --- a/packages/instrumentation-sequelize/package.json +++ b/packages/instrumentation-sequelize/package.json @@ -43,7 +43,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.17.1", - "@opentelemetry/instrumentation": "^0.44.0", + "@opentelemetry/instrumentation": "^0.45.1", "@opentelemetry/semantic-conventions": "^1.17.1" }, "devDependencies": { diff --git a/packages/instrumentation-typeorm/package.json b/packages/instrumentation-typeorm/package.json index c403df3a..c33da1e0 100644 --- a/packages/instrumentation-typeorm/package.json +++ b/packages/instrumentation-typeorm/package.json @@ -39,7 +39,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.17.1", - "@opentelemetry/instrumentation": "^0.44.0", + "@opentelemetry/instrumentation": "^0.45.1", "@opentelemetry/semantic-conventions": "^1.17.1", "is-promise": "^4.0.0" }, From 7defb632a89a6d1dba3c54a1c17fdf4d9c3ff734 Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Mon, 27 Nov 2023 19:29:22 +1100 Subject: [PATCH 3/4] fix: prettier --- packages/instrumentation-kafkajs/src/kafkajs.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/packages/instrumentation-kafkajs/src/kafkajs.ts b/packages/instrumentation-kafkajs/src/kafkajs.ts index 20b1a6b1..32b6308f 100644 --- a/packages/instrumentation-kafkajs/src/kafkajs.ts +++ b/packages/instrumentation-kafkajs/src/kafkajs.ts @@ -1,14 +1,4 @@ -import { - SpanKind, - Span, - SpanStatusCode, - Context, - propagation, - Link, - trace, - context, - diag, -} from '@opentelemetry/api'; +import { SpanKind, Span, SpanStatusCode, Context, propagation, Link, trace, context, diag } from '@opentelemetry/api'; import { SemanticAttributes, MessagingOperationValues, From 8f995da56b831f36c93e83475d5d18053a0fe034 Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Tue, 28 Nov 2023 07:52:42 +1100 Subject: [PATCH 4/4] fix: update unit test --- packages/instrumentation-kafkajs/test/kafkajs.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/instrumentation-kafkajs/test/kafkajs.spec.ts b/packages/instrumentation-kafkajs/test/kafkajs.spec.ts index c9e954dd..9ad9cf44 100644 --- a/packages/instrumentation-kafkajs/test/kafkajs.spec.ts +++ b/packages/instrumentation-kafkajs/test/kafkajs.spec.ts @@ -5,6 +5,7 @@ import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import { propagation, context, SpanKind, SpanStatusCode, Span } from '@opentelemetry/api'; import { MessagingDestinationKindValues, SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { getTestSpans, registerInstrumentationTesting } from '@opentelemetry/contrib-test-utils'; +import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; const instrumentation = registerInstrumentationTesting(new KafkaJsInstrumentation()); @@ -26,6 +27,7 @@ import { DummyPropagation } from './DummyPropagation'; import { W3CBaggagePropagator, CompositePropagator } from '@opentelemetry/core'; describe('instrumentation-kafkajs', () => { + context.setGlobalContextManager(new AsyncHooksContextManager()); propagation.setGlobalPropagator( new CompositePropagator({ propagators: [new DummyPropagation(), new W3CBaggagePropagator()] }) );