From 73d66f8bbcbb86c82968176367ede5097f750893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerhard=20St=C3=B6bich?= <18708370+Flarna@users.noreply.github.com> Date: Wed, 21 Dec 2022 16:00:23 +0100 Subject: [PATCH 1/2] fix(sdk-node): register instrumentations early Register instrumentations as first step in start() before it gets async to ensure that modules required during async resource detection get instrumented. --- experimental/CHANGELOG.md | 1 + experimental/packages/opentelemetry-sdk-node/src/sdk.ts | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 95d3407dd5..40453d588f 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to experimental packages in this project will be documented * fix(prometheus-sanitization): replace repeated `_` with a single `_` [3470](https://github.com/open-telemetry/opentelemetry-js/pull/3470) @samimusallam * fix(prometheus-serializer): correct string used for NaN [#3477](https://github.com/open-telemetry/opentelemetry-js/pull/3477) @JacksonWeber * fix(instrumentation-http): close server span when response finishes [#3407](https://github.com/open-telemetry/opentelemetry-js/pull/3407) @legendecas +* fix(sdk-node): register instrumentations early [#PRID](https://github.com/open-telemetry/opentelemetry-js/pull/PRID) @flarna ### :books: (Refine Doc) diff --git a/experimental/packages/opentelemetry-sdk-node/src/sdk.ts b/experimental/packages/opentelemetry-sdk-node/src/sdk.ts index ca8ae65573..60e4df5539 100644 --- a/experimental/packages/opentelemetry-sdk-node/src/sdk.ts +++ b/experimental/packages/opentelemetry-sdk-node/src/sdk.ts @@ -191,6 +191,10 @@ export class NodeSDK { * Once the SDK has been configured, call this method to construct SDK components and register them with the OpenTelemetry API. */ public async start(): Promise { + registerInstrumentations({ + instrumentations: this._instrumentations, + }); + if (this._autoDetectResources) { await this.detectResources(); } @@ -238,10 +242,6 @@ export class NodeSDK { metrics.setGlobalMeterProvider(meterProvider); } - - registerInstrumentations({ - instrumentations: this._instrumentations, - }); } public shutdown(): Promise { From 50a901a26157ad4f6c9258b80ee2e4445b5d07b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerhard=20St=C3=B6bich?= Date: Wed, 21 Dec 2022 16:07:22 +0100 Subject: [PATCH 2/2] Update experimental/CHANGELOG.md --- experimental/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 40453d588f..ea8df842f2 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -21,7 +21,7 @@ All notable changes to experimental packages in this project will be documented * fix(prometheus-sanitization): replace repeated `_` with a single `_` [3470](https://github.com/open-telemetry/opentelemetry-js/pull/3470) @samimusallam * fix(prometheus-serializer): correct string used for NaN [#3477](https://github.com/open-telemetry/opentelemetry-js/pull/3477) @JacksonWeber * fix(instrumentation-http): close server span when response finishes [#3407](https://github.com/open-telemetry/opentelemetry-js/pull/3407) @legendecas -* fix(sdk-node): register instrumentations early [#PRID](https://github.com/open-telemetry/opentelemetry-js/pull/PRID) @flarna +* fix(sdk-node): register instrumentations early [#3502](https://github.com/open-telemetry/opentelemetry-js/pull/3502) @flarna ### :books: (Refine Doc)