Skip to content

Commit

Permalink
Merge a95639b into 31dd7b7
Browse files Browse the repository at this point in the history
  • Loading branch information
haddasbronfman authored Mar 2, 2023
2 parents 31dd7b7 + a95639b commit ea1659e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to experimental packages in this project will be documented
* feat: use HTTP_ROUTE in span name [#3603](https://github.com/open-telemetry/opentelemetry-js/pull/3603) @Flarna
* feat: add HTTP_ROUTE attribute to http incoming metrics if present [#3581](https://github.com/open-telemetry/opentelemetry-js/pull/3581) @hermogenes
* feat(sdk-node): install diag logger with OTEL_LOG_LEVEL [#3627](https://github.com/open-telemetry/opentelemetry-js/pull/3627) @legendecas
* feat(sdk-node): override IdGenerator when using NodeSDK [#3645](https://github.com/open-telemetry/opentelemetry-js/pull/3645) @haddasbronfman

### :bug: (Bug Fix)

Expand Down
3 changes: 3 additions & 0 deletions experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export class NodeSDK {
if (configuration.spanLimits) {
tracerProviderConfig.spanLimits = configuration.spanLimits;
}
if (configuration.idGenerator) {
tracerProviderConfig.idGenerator = configuration.idGenerator;
}

const spanProcessor =
configuration.spanProcessor ??
Expand Down
2 changes: 2 additions & 0 deletions experimental/packages/opentelemetry-sdk-node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
SpanExporter,
SpanLimits,
SpanProcessor,
IdGenerator,
} from '@opentelemetry/sdk-trace-base';

export interface NodeSDKConfiguration {
Expand All @@ -41,4 +42,5 @@ export interface NodeSDKConfiguration {
spanProcessor: SpanProcessor;
traceExporter: SpanExporter;
spanLimits: SpanLimits;
idGenerator: IdGenerator;
}
28 changes: 28 additions & 0 deletions experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
SimpleSpanProcessor,
BatchSpanProcessor,
NoopSpanProcessor,
IdGenerator,
} from '@opentelemetry/sdk-trace-base';
import * as assert from 'assert';
import * as semver from 'semver';
Expand Down Expand Up @@ -691,6 +692,33 @@ describe('Node SDK', () => {
});
});
});

describe('configure IdGenerator', async () => {
class CustomIdGenerator implements IdGenerator {
generateTraceId(): string {
return 'constant-test-trace-id';
}
generateSpanId(): string {
return 'constant-test-span-id';
}
}

it('should configure IdGenerator via config', async () => {
const idGenerator = new CustomIdGenerator();
const spanProcessor = new SimpleSpanProcessor(new ConsoleSpanExporter());
const sdk = new NodeSDK({
idGenerator,
spanProcessor,
});
sdk.start();

const span = trace.getTracer('test').startSpan('testName');
span.end();

assert.strictEqual(span.spanContext().spanId, 'constant-test-span-id');
assert.strictEqual(span.spanContext().traceId, 'constant-test-trace-id');
});
});
});

describe('setup exporter from env', () => {
Expand Down

0 comments on commit ea1659e

Please sign in to comment.