Skip to content

Conversation

@david-luna
Copy link
Member

@david-luna david-luna commented Mar 17, 2025

https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/upgrade-to-2.x.md

Note: this is not considered a breaking change for EDOT Node.js because:

  • The breaking 0.7.0 release already bumped the min supported Node.js inline with what OTel JS SDK 2.0 supports as a minimum.
  • The only non-experimental supported way to start EDOT Node.js for the upcoming GA is the zero-code node --import @elastic/opentelemetry-node ... mechanism. Programmatic bootstrapping of EDOT Node.js will remain experimental and may be broken in minor releases.

@david-luna david-luna marked this pull request as ready for review March 18, 2025 16:42
function restoreEnvironment() {
Object.keys(envToRestore).forEach((k) => {
process.env[k] = envToRestore[k];
delete envToRestore[k];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for reviewer: IMO the getters defined below should take values directly from prcess.env once the environment vars are restored.

const logsExportProtocol =
process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL ||
getEnvVar('OTEL_EXPORTER_OTLP_PROTOCOL');
getEnvString('OTEL_EXPORTER_OTLP_PROTOCOL');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% node --import @elastic/opentelemetry-node simple-http-request.js
{"name":"elastic-otel-node","level":40,"msg":"Logs exporter protocol \"undefined\" unknown. Using default \"http/protobuf\" protocol","time":"2025-03-18T20:10:04.261Z"}
...

I think that log warn is because this doesn't have a default fallback now.

const metricsExportProtocol =
process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL ||
getEnvVar('OTEL_EXPORTER_OTLP_PROTOCOL');
getEnvString('OTEL_EXPORTER_OTLP_PROTOCOL');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% node --import @elastic/opentelemetry-node simple-http-request.js
...
{"name":"elastic-otel-node","level":40,"msg":"Metrics exporter protocol \"undefined\" unknown. Using default \"http/protobuf\" protocol","time":"2025-03-18T20:10:04.263Z"}
...

I think that log warn is because this doesn't have a default fallback now.

// @ts-ignore -- T is {keyof OtelEnv} but not sure how to make TS infer that
return otelEnv[name];
}
function makeEnvVarGetter(getterFn) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm. AFAICT, the only reason for the isStashed handling in here is because in elastic-node-sdk.js we are currently calling setupEnvironment before the call the resolveDetectors that uses the OTEL_NODE_RESOURCE_DETECTORS envvar value.

What if we move setupEnvironment() to be just before the super(configuration) call. I think that was the original intent. The only reason the setupEnvironment / restoreEnvironment things are done is to tweak the env for when the NodeSDK constructor runs. (Possibly also its .start() as well.)

Then if the isStashed stuff isn't needed, we could drop the getEnv* functions and just use the get*FromEnv functions from @opentelemetry/core directly, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See commit 3c28ba4 for an attempt at this.

@trentm trentm changed the title feat(otel-node): update to SDK 2.0 feat(otel-node)!: update to SDK 2.0 Mar 18, 2025
…Environment tweaking closer to NodeSDK ctor call, so don't need special lookup handling for tweaked envvars
@trentm
Copy link
Member

trentm commented Mar 18, 2025

@david-luna What do you think of commit 3c28ba4?

Copy link
Member

@trentm trentm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Changelog entry

@david-luna
Copy link
Member Author

@david-luna What do you think of commit 3c28ba4?

Looks good. I'm going to approve and add the changelog entry. Thanks! :)

@david-luna david-luna merged commit 41a96cb into main Mar 19, 2025
9 checks passed
@david-luna david-luna deleted the dluna-sdk-2-0 branch March 19, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants