Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
### :rocket: Features

* feat(configuration): bump config schema to v1.1.0; rename `without_scope_info` → `scope_info_enabled` and `without_target_info/development` → `target_info_enabled/development` on the Prometheus pull exporter (semantics inverted), rename `with_resource_constant_labels` → `resource_constant_labels`. Validate `file_format` per the configuration versioning spec: accept any minor version of major `1` (e.g. `1.0`, `1.1`), warn when the minor version is newer than supported, and reject other major versions. [#6781](https://github.com/open-telemetry/opentelemetry-js/pull/6781) @MikeGoldsmith
* feat(sdk-node): wire up `id_generator` from declarative config [#6782](https://github.com/open-telemetry/opentelemetry-js/pull/6782) @MikeGoldsmith
* feat(propagator-env-carrier): empty name normalization [#6827](https://github.com/open-telemetry/opentelemetry-js/pull/6827) @pellared

### :bug: Bug Fixes
Expand Down
1 change: 1 addition & 0 deletions experimental/packages/configuration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type {
NameStringValuePair as NameStringValuePairConfigModel,
HttpTls as HttpTlsConfigModel,
GrpcTls as GrpcTlsConfigModel,
IdGenerator as IdGeneratorConfigModel,
SeverityNumber as SeverityNumberConfigModel,
LoggerProvider as LoggerProviderConfigModel,
AttributeLimits as AttributeLimitsConfigModel,
Expand Down
4 changes: 3 additions & 1 deletion experimental/packages/opentelemetry-sdk-node/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
propagation,
} from '@opentelemetry/api';
import {
getIdGeneratorFromConfiguration,
getInstanceID,
createLoggerProviderFromConfig,
getMeterReadersFromConfiguration,
Expand Down Expand Up @@ -166,15 +167,16 @@ function create(

const spanProcessors = getSpanProcessorsFromConfiguration(config);
if (spanProcessors) {
const idGenerator = getIdGeneratorFromConfiguration(config);
// TODO (6506): support sampler configuration from config
const tracerProvider = new TracerProvider({
resource,
spanProcessors,
idGenerator,
spanLimits: createSpanLimitsFromConfig(
config.tracer_provider?.limits,
config.attribute_limits
),
// TODO (6616): support idGenerator configuration from config
// TODO (6624): support for `meterProvider: components.meterProvider`
});
components.tracerProvider = tracerProvider;
Expand Down
23 changes: 23 additions & 0 deletions experimental/packages/opentelemetry-sdk-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
serviceInstanceIdDetector,
} from '@opentelemetry/resources';
import type {
IdGenerator,
Sampler,
SpanExporter,
SpanProcessor,
Expand All @@ -41,6 +42,7 @@ import {
BatchSpanProcessor,
ConsoleSpanExporter,
ParentBasedSampler,
RandomIdGenerator,
SimpleSpanProcessor,
TraceIdRatioBasedSampler,
} from '@opentelemetry/sdk-trace';
Expand Down Expand Up @@ -959,6 +961,27 @@ export function getSpanProcessorsFromConfiguration(
return undefined;
}

export function getIdGeneratorFromConfiguration(
config: ConfigurationModel
): IdGenerator | undefined {
const idGenerator = config.tracer_provider?.id_generator;
if (!idGenerator) {
return undefined;
}
if (idGenerator.random !== undefined) {
return new RandomIdGenerator();
}
// Any other key is a third-party / custom id_generator type which we
// don't currently support. Warn and fall back to SDK default.
Comment on lines +974 to +975

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool for now.

However, I think we should discuss and agree on behaviour for unknown keys.
My thoughts here: #6107 (comment)

Note (for comparison), in #6785 I made Create handling throw on unrecognized keys, e.g. https://github.com/open-telemetry/opentelemetry-js/pull/6785/changes#diff-a6c0e622127e4d2eef8ea3011fbea3abc886a8d8e4adec2a765f47127e739180R731

const unknownKeys = Object.keys(idGenerator).filter(k => k !== 'random');
if (unknownKeys.length > 0) {
diag.warn(
`Unsupported id_generator type(s): ${unknownKeys.join(', ')}. Using default.`
);
}
return undefined;
}

export function getMeterReadersFromConfiguration(
config: ConfigurationModel
): IMetricReader[] | undefined {
Expand Down
48 changes: 48 additions & 0 deletions experimental/packages/opentelemetry-sdk-node/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getHeadersFromConfiguration,
getMeterViewsFromConfiguration,
getHttpAgentOptionsFromTls,
getIdGeneratorFromConfiguration,
} from '../src/utils';
import * as assert from 'assert';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -786,6 +787,53 @@ describe('getMeterViewsFromConfiguration', function () {
});
});

describe('getIdGeneratorFromConfiguration', function () {
afterEach(() => {
sinon.restore();
});

it('returns undefined when no tracer_provider is set', function () {
assert.equal(
getIdGeneratorFromConfiguration({} as ConfigurationModel),
undefined
);
});

it('returns undefined when no id_generator is set', function () {
const config = {
tracer_provider: { processors: [] },
} as ConfigurationModel;
assert.equal(getIdGeneratorFromConfiguration(config), undefined);
});

it('returns a RandomIdGenerator when random is set', function () {
const config = {
tracer_provider: { processors: [], id_generator: { random: {} } },
} as ConfigurationModel;
const idGenerator = getIdGeneratorFromConfiguration(config);
assert.ok(idGenerator);
assert.strictEqual(idGenerator.constructor.name, 'RandomIdGenerator');
});

it('warns and returns undefined for unsupported id_generator type', function () {
const warnStub = sinon.stub(diag, 'warn');
const config = {
tracer_provider: {
processors: [],
id_generator: { custom_generator: {} },
},
} as ConfigurationModel;
assert.equal(getIdGeneratorFromConfiguration(config), undefined);
assert.ok(
warnStub.args.some(args =>
String(args[0]).includes(
'Unsupported id_generator type(s): custom_generator'
)
)
);
});
});

describe('getHttpAgentOptionsFromTls', function () {
afterEach(() => {
sinon.restore();
Expand Down
Loading