Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate sdk-node away from getEnv(), introduce diagLogLevelFromString() util #5475

Conversation

pichlermarc
Copy link
Member

Which problem is this PR solving?

  • Migrates away from getEnv() to the get*FromEnv() functions introduced in feat(core): add more scalable replacements for getEnv(), getEnvWithoutDefaults() #5443 @opentelemetry/sdk-node this is a pure refactoring and does not change behavior since that package is not used in the browser.
  • Adds a utility to @opentelemetry/core to convert a string returned from getStringFromEnv() to a DiagLogLevel. This is what we can also use to replace the code in contrib and in the lambda wrapper.
    • getEnv().OTEL_LOG_LEVEL becomes stringToLogLevel(getStringFromEnv('OTEL_LOG_LEVEL))

Refs #5217

Type of change

  • New feature (non-breaking change which adds functionality)
  • refactor (sdk-node)

How Has This Been Tested?

  • Unit tests

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.93%. Comparing base (60f2ce9) to head (5acb77e).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5475      +/-   ##
==========================================
+ Coverage   94.91%   94.93%   +0.02%     
==========================================
  Files         308      309       +1     
  Lines        7980     8002      +22     
  Branches     1682     1686       +4     
==========================================
+ Hits         7574     7597      +23     
+ Misses        406      405       -1     
Files with missing lines Coverage Δ
...imental/packages/opentelemetry-sdk-node/src/sdk.ts 96.01% <100.00%> (-0.02%) ⬇️
...ental/packages/opentelemetry-sdk-node/src/utils.ts 92.03% <100.00%> (+0.65%) ⬆️
...ages/opentelemetry-core/src/utils/configuration.ts 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

@pichlermarc pichlermarc force-pushed the feat/migrate-from-getenv-sdk-node branch from e954193 to 66d4704 Compare February 13, 2025 18:50
@pichlermarc pichlermarc marked this pull request as ready for review February 13, 2025 19:01
@pichlermarc pichlermarc requested a review from a team as a code owner February 13, 2025 19:01
@pichlermarc pichlermarc added the target:next-major-release This PR targets the next major release (`next` branch) label Feb 13, 2025
@pichlermarc pichlermarc added this to the OpenTelemetry SDK 2.0 milestone Feb 13, 2025
Copy link
Contributor

@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.

Drive by review while this was still in draft.

* Convert a string to a {@link DiagLogLevel}, defaults to {@link DiagLogLevel} if the log level does not exist or undefined if the input is undefined.
* @param value
*/
export function stringToLogLevel(
Copy link
Contributor

Choose a reason for hiding this comment

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

Drive-by bikeshedding nit: Perhaps diagLogLevelFromString or getDiagLogLevelFromString?
Just a nit, however, so feel free to ignore this.

  • diag in the name to differentiate these from the similar but different log severity values (
    export enum SeverityNumber {
    UNSPECIFIED = 0,
    TRACE = 1,
    TRACE2 = 2,
    TRACE3 = 3,
    TRACE4 = 4,
    DEBUG = 5,
    DEBUG2 = 6,
    DEBUG3 = 7,
    DEBUG4 = 8,
    INFO = 9,
    INFO2 = 10,
    INFO3 = 11,
    INFO4 = 12,
    WARN = 13,
    WARN2 = 14,
    WARN3 = 15,
    WARN4 = 16,
    ERROR = 17,
    ERROR2 = 18,
    ERROR3 = 19,
    ERROR4 = 20,
    FATAL = 21,
    FATAL2 = 22,
    FATAL3 = 23,
    FATAL4 = 24,
    }
    )
  • aFromB or getAFromB naming to match some of the other similar API function names like getStringFromEnv. (Though to be fair bToA naming is used by "src/common/time.ts" exports like millisToHrTime. I'm an old timey fan of the aFromB naming per the ancient https://www.joelonsoftware.com/2005/05/11/making-wrong-code-look-wrong/) :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I like diagLogLevelFromString 🙂
Applied in 3a0a6c3

@pichlermarc pichlermarc force-pushed the feat/migrate-from-getenv-sdk-node branch from b34712b to 3a0a6c3 Compare February 13, 2025 19:21
Copy link
Contributor

@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.

LGTM, modulo two small nits.

CHANGELOG.md Outdated Show resolved Hide resolved
@trentm trentm changed the title feat: migrate sdk-node away from getEnv(), introduce stringToLogLevel() util feat: migrate sdk-node away from getEnv(), introduce diagLogLevelFromString() util Feb 13, 2025
@pichlermarc pichlermarc added this pull request to the merge queue Feb 17, 2025
Merged via the queue into open-telemetry:main with commit 5b988c8 Feb 17, 2025
18 checks passed
@pichlermarc pichlermarc deleted the feat/migrate-from-getenv-sdk-node branch February 17, 2025 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:core pkg:sdk-node target:next-major-release This PR targets the next major release (`next` branch)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants