Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2

### :rocket: Features

* feat(sdk-node): migrate to use the new sdk-trace package
* There is a new `trace` export. It re-exports `@opentelemetry/sdk-trace`.
This should be used instead of the `node` re-export of `@opentelemetry/sdk-trace-node` and `tracing` re-export of `@opentelemetry/sdk-trace-base`,
both of which are now *deprecated*.
* 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(propagator-env-carrier): empty name normalization [#6827](https://github.com/open-telemetry/opentelemetry-js/pull/6827) @pellared

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 @@ -14,6 +14,7 @@ export type {
Sampler as SamplerConfigModel,
SpanExporter as SpanExporterConfigModel,
SpanProcessor as SpanProcessorConfigModel,
SpanLimits as SpanLimitsConfigModel,
MetricProducer as MetricProducerConfigModel,
NameStringValuePair as NameStringValuePairConfigModel,
HttpTls as HttpTlsConfigModel,
Expand Down
6 changes: 3 additions & 3 deletions experimental/packages/opentelemetry-sdk-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ An array of span processors to register to the tracer provider.

### traceExporter

Configure a trace exporter. If an exporter is configured, it will be used with a [BatchSpanProcessor](../../../packages/opentelemetry-sdk-trace-base/src/platform/node/export/BatchSpanProcessor.ts). If an exporter OR span processor is not configured programmatically, this package will auto setup the default `otlp` exporter with `http/protobuf` protocol with a `BatchSpanProcessor`.
Configure a trace exporter. If an exporter is configured, it will be used with a [BatchSpanProcessor](../../../packages/sdk-trace/src/platform/node/export/BatchSpanProcessor.ts). If an exporter OR span processor is not configured programmatically, this package will auto setup the default `otlp` exporter with `http/protobuf` protocol with a `BatchSpanProcessor`.

### spanLimits

Configure tracing parameters. These are the same trace parameters used to [configure a tracer](../../../packages/opentelemetry-sdk-trace-base/src/types.ts#L71).
Configure tracing parameters. These are the same trace parameters used to [configure a tracer](../../../packages/sdk-trace/src/types.ts#L20).

### serviceName

Expand Down Expand Up @@ -245,7 +245,7 @@ linkes for details:

- Metric reader metrics: [MetricReaderMetrics](../../../packages//sdk-metrics/src/export/MetricReaderMetrics.ts)
- Logger metrics: [LoggerMetrics.ts](../sdk-logs/src/LoggerMetrics.ts)
- Span metrics: [TracerMetrics.ts](../../../packages/opentelemetry-sdk-trace-base/src/TracerMetrics.ts)
- Span metrics: [TracerMetrics.ts](../../../packages/sdk-trace/src/TracerMetrics.ts)

## Useful links

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@opentelemetry/resources": "2.8.0",
"@opentelemetry/sdk-logs": "0.219.0",
"@opentelemetry/sdk-metrics": "2.8.0",
"@opentelemetry/sdk-trace": "2.8.0",
"@opentelemetry/sdk-trace-base": "2.8.0",
"@opentelemetry/sdk-trace-node": "2.8.0",
"@opentelemetry/semantic-conventions": "^1.29.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Create SDK components from parsed declarative config.
* https://opentelemetry.io/docs/specs/otel/configuration/sdk/#create
*/

import type {
AttributeLimitsConfigModel,
SpanLimitsConfigModel,
} from '@opentelemetry/configuration';
import type { SpanLimits } from '@opentelemetry/sdk-trace';

export function createSpanLimitsFromConfig(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: This continues the create<SDK Thing>FromConfig() pattern started in #6785

I've also started moving "FromConfig"-specific things to this file, from the overly large "utils.ts".
I think it'll be helpful for maint and testing to separate the "FromEnv" handling and the "FromConfig" handling. Over a number of PRs I'll move/re-implement things in utils.ts over to "create-from-config.ts" and "create-from-env.ts".

limits?: SpanLimitsConfigModel,
attribute_limits?: AttributeLimitsConfigModel
): SpanLimits | undefined {
if (!limits && !attribute_limits) {
return undefined;
}
return {
attributeValueLengthLimit:
limits?.attribute_value_length_limit ??
attribute_limits?.attribute_value_length_limit ??
undefined,
attributeCountLimit:
limits?.attribute_count_limit ??
attribute_limits?.attribute_count_limit ??
undefined,
eventCountLimit: limits?.event_count_limit ?? undefined,
linkCountLimit: limits?.link_count_limit ?? undefined,
attributePerEventCountLimit:
limits?.event_attribute_count_limit ?? undefined,
attributePerLinkCountLimit: limits?.link_attribute_count_limit ?? undefined,
};
}
113 changes: 113 additions & 0 deletions experimental/packages/opentelemetry-sdk-node/src/create-from-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Create SDK components from environment variable settings.
* https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/
*/

import { diag } from '@opentelemetry/api';
import { getNumberFromEnv, getStringFromEnv } from '@opentelemetry/core';
import type {
Sampler,
SpanExporter,
SpanLimits,
} from '@opentelemetry/sdk-trace';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace';
import {
AlwaysOffSampler,
AlwaysOnSampler,
ParentBasedSampler,
TraceIdRatioBasedSampler,
} from '@opentelemetry/sdk-trace';
import { getNonNegativeNumberFromEnv } from './utils';

const DEFAULT_RATIO = 1;

export function createSamplerFromEnv(): Sampler | undefined {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: Adapted from buildSamplerFromEnv in sdk-trace-base:

export function buildSamplerFromEnv(): Sampler {

const samplerName = getStringFromEnv('OTEL_TRACES_SAMPLER');
if (samplerName === undefined) {
return undefined;
}
switch (samplerName) {
case 'always_on':
return new AlwaysOnSampler();
case 'always_off':
return new AlwaysOffSampler();
case 'parentbased_always_on':
return new ParentBasedSampler({
root: new AlwaysOnSampler(),
});
case 'parentbased_always_off':
return new ParentBasedSampler({
root: new AlwaysOffSampler(),
});
case 'traceidratio':
return new TraceIdRatioBasedSampler(getSamplerRatioFromEnv());
case 'parentbased_traceidratio':
return new ParentBasedSampler({
root: new TraceIdRatioBasedSampler(getSamplerRatioFromEnv()),
});
default:
diag.error(
`unknown OTEL_TRACES_SAMPLER value "${samplerName}", using default`
);
return undefined;
}
}

function getSamplerRatioFromEnv(): number | undefined {
const ratio = getNumberFromEnv('OTEL_TRACES_SAMPLER_ARG');
if (ratio == null) {
diag.error(
`OTEL_TRACES_SAMPLER_ARG is blank, defaulting to ${DEFAULT_RATIO}.`
);
return DEFAULT_RATIO;
}

if (ratio < 0 || ratio > 1) {
diag.error(
`OTEL_TRACES_SAMPLER_ARG=${ratio} was given, but it is out of range ([0..1]), defaulting to ${DEFAULT_RATIO}.`
);
return DEFAULT_RATIO;
}

return ratio;
}

export function createSpanLimitsFromEnv(): SpanLimits | undefined {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: Adapted from reconfigureLimits in sdk-trace-base:

export function reconfigureLimits(userConfig: TracerConfig): TracerConfig {

return {
attributeCountLimit:
getNumberFromEnv('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT') ??
getNumberFromEnv('OTEL_ATTRIBUTE_COUNT_LIMIT'),
attributeValueLengthLimit:
getNumberFromEnv('OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT') ??
getNumberFromEnv('OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT'),
eventCountLimit: getNumberFromEnv('OTEL_SPAN_EVENT_COUNT_LIMIT'),
linkCountLimit: getNumberFromEnv('OTEL_SPAN_LINK_COUNT_LIMIT'),
attributePerEventCountLimit: getNumberFromEnv(
'OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT'
),
attributePerLinkCountLimit: getNumberFromEnv(
'OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT'
),
};
}

export function createBatchSpanProcessorFromEnv(
exporter: SpanExporter
): BatchSpanProcessor {
return new BatchSpanProcessor({
exporter,
maxQueueSize: getNonNegativeNumberFromEnv('OTEL_BSP_MAX_QUEUE_SIZE'),
scheduledDelayMillis: getNonNegativeNumberFromEnv(
'OTEL_BSP_SCHEDULE_DELAY'
),
exportTimeoutMillis: getNonNegativeNumberFromEnv('OTEL_BSP_EXPORT_TIMEOUT'),
maxExportBatchSize: getNonNegativeNumberFromEnv(
'OTEL_BSP_MAX_EXPORT_BATCH_SIZE'
),
});
}
10 changes: 9 additions & 1 deletion experimental/packages/opentelemetry-sdk-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ export * as contextBase from '@opentelemetry/api';
export * as core from '@opentelemetry/core';
export * as logs from '@opentelemetry/sdk-logs';
export * as metrics from '@opentelemetry/sdk-metrics';
export * as node from '@opentelemetry/sdk-trace-node';
export * as resources from '@opentelemetry/resources';
export * as trace from '@opentelemetry/sdk-trace';
Comment thread
trentm marked this conversation as resolved.
Outdated

/**
* @deprecated Use `trace` re-export from `@opentelemetry/sdk-trace` instead.
*/
export * as node from '@opentelemetry/sdk-trace-node';
/**
* @deprecated Use `trace` re-export from `@opentelemetry/sdk-trace` instead.
*/
export * as tracing from '@opentelemetry/sdk-trace-base';
Comment on lines +22 to 26

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: These existing re-exports are the only reason sdk-node cannot yet drop its dep on sdk-trace-node and sdk-trace-base. We'll drop these with SDK 3.0.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see you opened #6824. If you're feeling adventurous, we could also try to remove it and see if anybody is unhappy with that. I'd be willing to bet that almost nobody is using these re-exports.

We don't need to do it in this PR though, let's keep this low-friction for now.

/* eslint-enable no-restricted-syntax */

Expand Down
81 changes: 31 additions & 50 deletions experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ import {
ConsoleMetricExporter,
PeriodicExportingMetricReader,
} from '@opentelemetry/sdk-metrics';
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import type { NodeTracerConfig } from '@opentelemetry/sdk-trace-node';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { TracerProvider } from '@opentelemetry/sdk-trace';
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
import type { NodeSDKConfiguration } from './types';
import {
Expand All @@ -62,11 +59,11 @@ import {
getBatchLogRecordProcessorFromEnv,
getLoggerProviderConfigFromEnv,
} from './utils';

type TracerProviderConfig = {
tracerConfig: NodeTracerConfig;
spanProcessors: SpanProcessor[];
};
import {
createBatchSpanProcessorFromEnv,
createSamplerFromEnv,
createSpanLimitsFromEnv,
} from './create-from-env';

export type MeterProviderConfig = {
/**
Expand Down Expand Up @@ -150,7 +147,6 @@ function getMetricReadersFromEnv(): IMetricReader[] {
* nodeSdk.start(); // registers all configured SDK components
*/
export class NodeSDK {
private _tracerProviderConfig?: TracerProviderConfig;
private _loggerProviderConfig?: LoggerProviderConfig;
private _meterProviderConfig?: MeterProviderConfig;
private _instrumentations: Instrumentation[];
Expand All @@ -160,7 +156,7 @@ export class NodeSDK {

private _autoDetectResources: boolean;

private _tracerProvider?: NodeTracerProvider;
private _tracerProvider?: TracerProvider;
private _loggerProvider?: LoggerProvider;
private _meterProvider?: MeterProvider;
private _serviceName?: string;
Expand Down Expand Up @@ -201,40 +197,10 @@ export class NodeSDK {

this._serviceName = configuration.serviceName;

// If a tracer provider can be created from manual configuration, create it
if (
configuration.traceExporter ||
configuration.spanProcessor ||
configuration.spanProcessors
) {
const tracerProviderConfig: NodeTracerConfig = {};

if (configuration.sampler) {
tracerProviderConfig.sampler = configuration.sampler;
}
if (configuration.spanLimits) {
tracerProviderConfig.spanLimits = configuration.spanLimits;
}
if (configuration.idGenerator) {
tracerProviderConfig.idGenerator = configuration.idGenerator;
}
Comment on lines -212 to -220

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: This tracerProviderConfig was never used.


if (configuration.spanProcessor) {
diag.warn(
"The 'spanProcessor' option is deprecated. Please use 'spanProcessors' instead."
);
}

const spanProcessor =
configuration.spanProcessor ??
new BatchSpanProcessor(configuration.traceExporter!);

const spanProcessors = configuration.spanProcessors ?? [spanProcessor];

this._tracerProviderConfig = {
tracerConfig: tracerProviderConfig,
spanProcessors,
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: All of this handling of input config options for span processors is moved (and cleaned up) to and if-block in .start() below.

if (configuration.spanProcessor) {
diag.warn(
"The 'spanProcessor' option is deprecated. Please use 'spanProcessors' instead."
);
}

if (configuration.logRecordProcessors) {
Expand Down Expand Up @@ -340,16 +306,31 @@ export class NodeSDK {
}
}

const spanProcessors = this._tracerProviderConfig
? this._tracerProviderConfig.spanProcessors
: getSpanProcessorsFromEnv();
// Determine `spanProcessors` from multiple possible options.
let spanProcessors;
if (this._configuration?.spanProcessors) {
spanProcessors = this._configuration.spanProcessors;
} else if (this._configuration?.spanProcessor) {
spanProcessors = [this._configuration.spanProcessor];
} else if (this._configuration?.traceExporter) {
spanProcessors = [
createBatchSpanProcessorFromEnv(this._configuration.traceExporter!),
];
} else {
spanProcessors = getSpanProcessorsFromEnv();
}

// Only register if there is a span processor
if (spanProcessors.length > 0) {
this._tracerProvider = new NodeTracerProvider({
...this._configuration,
this._tracerProvider = new TracerProvider({
sampler: this._configuration?.sampler ?? createSamplerFromEnv(),
spanLimits: {
...createSpanLimitsFromEnv(),
...this._configuration?.spanLimits,
},
resource: this._resource,
meterProvider: sdkMetricsEnabled ? this._meterProvider : undefined,
idGenerator: this._configuration?.idGenerator,
spanProcessors,
});
trace.setGlobalTracerProvider(this._tracerProvider);
Expand Down
18 changes: 7 additions & 11 deletions experimental/packages/opentelemetry-sdk-node/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {
getPropagatorFromConfiguration,
getResourceDetectorsFromConfiguration,
getResourceFromConfiguration,
getSpanLimitsFromConfiguration,
getSpanProcessorsFromConfiguration,
} from './utils';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import type { SDKComponents, SDKOptions } from './types';
import { MeterProvider } from '@opentelemetry/sdk-metrics';
import { TracerProvider } from '@opentelemetry/sdk-trace';
import { logs } from '@opentelemetry/api-logs';
import type {
Resource,
Expand All @@ -42,8 +42,8 @@ import {
} from '@opentelemetry/resources';
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
import { ATTR_SERVICE_INSTANCE_ID } from './semconv';
import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
import { diagLogLevelFromSeverityNumberConfig } from './diag';
import { createSpanLimitsFromConfig } from './create-from-config';

// Exported for testing.
export const NOOP_SDK = {
Expand Down Expand Up @@ -166,18 +166,14 @@ function create(

const spanProcessors = getSpanProcessorsFromConfiguration(config);
if (spanProcessors) {
const spanLimits = getSpanLimitsFromConfiguration(config);
// TODO (6506): support sampler configuration from config
const tracerProvider = new BasicTracerProvider({
const tracerProvider = new TracerProvider({
resource,
spanProcessors,
spanLimits,
generalLimits: {
attributeValueLengthLimit:
config.attribute_limits?.attribute_value_length_limit ?? undefined,
attributeCountLimit:
config.attribute_limits?.attribute_count_limit ?? undefined,
},
spanLimits: createSpanLimitsFromConfig(
config.tracer_provider?.limits,
config.attribute_limits
),
// TODO (6616): support idGenerator configuration from config
// TODO (6624): support for `meterProvider: components.meterProvider`
});
Expand Down
Loading