Skip to content

Commit

Permalink
Merge branch 'main' into fix/ci-tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Mar 24, 2023
2 parents 5d128e6 + 0c37daa commit 65d21a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix(sdk-node): only set DiagConsoleLogger when OTEL_LOG_LEVEL is set [#3693](https://github.com/open-telemetry/opentelemetry-js/pull/3672) @pichlermarc

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
11 changes: 8 additions & 3 deletions experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { NodeSDKConfiguration } from './types';
import { TracerProviderWithEnvExporters } from './TracerProviderWithEnvExporter';
import { getEnv } from '@opentelemetry/core';
import { getEnv, getEnvWithoutDefaults } from '@opentelemetry/core';
import { parseInstrumentationOptions } from './utils';

/** This class represents everything needed to register a fully configured OpenTelemetry Node.js SDK */
Expand Down Expand Up @@ -89,14 +89,19 @@ export class NodeSDK {
*/
public constructor(configuration: Partial<NodeSDKConfiguration> = {}) {
const env = getEnv();
const envWithoutDefaults = getEnvWithoutDefaults();

if (env.OTEL_SDK_DISABLED) {
this._disabled = true;
// Functions with possible side-effects are set
// to no-op via the _disabled flag
}
if (env.OTEL_LOG_LEVEL) {

// Default is INFO, use environment without defaults to check
// if the user originally set the environment variable.
if (envWithoutDefaults.OTEL_LOG_LEVEL) {
diag.setLogger(new DiagConsoleLogger(), {
logLevel: env.OTEL_LOG_LEVEL,
logLevel: envWithoutDefaults.OTEL_LOG_LEVEL,
});
}

Expand Down
13 changes: 13 additions & 0 deletions experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ describe('Node SDK', () => {
delete env.OTEL_LOG_LEVEL;
});

it('should not register a diag logger with OTEL_LOG_LEVEL unset', () => {
delete env.OTEL_LOG_LEVEL;

const spy = Sinon.spy(diag, 'setLogger');
const sdk = new NodeSDK({
autoDetectResources: false,
});

sdk.start();

assert.strictEqual(spy.callCount, 0);
});

it('should register a tracer provider if an exporter is provided', async () => {
const sdk = new NodeSDK({
traceExporter: new ConsoleSpanExporter(),
Expand Down

0 comments on commit 65d21a6

Please sign in to comment.