Skip to content

[contribfest] use env var utility functions to setup diagnostics loggingΒ #2774

@pichlermarc

Description

@pichlermarc

Description

Description

Important

This issue is reserved for attendees of OpenTelemetry ContribFest at KubeCon EU 2025
If you are attending KubeCon EU 2025, please join us at Level 3 | ICC Capital Suite 1 on Wednesday April 2, 2025 16:15 - 17:30 BST πŸ™Œ

If you are not attending KubeCon EU 2025, the remainder of this issue will be
marked as "good-first-issue" starting Thursday. πŸ™‚

With open-telemetry/opentelemetry-js#5443 we've introduced new utility functions for getting getting environment variables in an OTel Spec compliant manner, and we've migrated from using the old getEnv() utility function (#2708).

However, to provide an easier upgrade-path, for users of getEnv() we've also introduced a utility function to get a log level from a string, so the mapping we now do is now obsolete and we should align it with the core repo.

The goal of this issue is to replace the diagnostics logging setup here:

diag.setLogger(new DiagConsoleLogger(), getLogLevelFromEnv());

with a setup which is the same as in the core repo.

You can then remove this code here:

export function getLogLevelFromEnv(): DiagLogLevel {
const rawLogLevel = process.env.OTEL_LOG_LEVEL;
// NOTE: as per specification we should actually only register if something is set, but our previous implementation
// always registered a logger, even when nothing was set. Falling back to 'INFO' here to keep the same behavior as
// with previous implementations.
// Also: no point in warning - no logger is registered yet
return (
logLevelMap[rawLogLevel?.trim().toUpperCase() ?? 'INFO'] ??
DiagLogLevel.INFO
);
}

and any other code that becomes unused from this change.

To complete this issue:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions