Skip to content

Commit

Permalink
Merge branch 'main' into hectorhdzg/logsinstr
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhdzg authored Feb 5, 2024
2 parents 366d6e1 + 0229434 commit aab138b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :rocket: (Enhancement)

* feat(instrumentation): Make `init()` method public [#4418](https://github.com/open-telemetry/opentelemetry-js/pull/4418)

### :bug: (Bug Fix)

### :books: (Refine Doc)
Expand Down
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ All notable changes to experimental packages in this project will be documented
### :rocket: (Enhancement)

* feat(instrumentation): allow LoggerProvider to be specified in Instrumentations [#4314](https://github.com/open-telemetry/opentelemetry-js/pull/4314) @hectorhdzg
* feat(instrumentation): Make `init()` method public [#4418](https://github.com/open-telemetry/opentelemetry-js/pull/4418)
* feat(exporter-metrics-otlp-http): add option to set the exporter aggregation preference [#4409](https://github.com/open-telemetry/opentelemetry-js/pull/4409) @AkselAllas
* feat(node-sdk): add spanProcessors option [#4454](https://github.com/open-telemetry/opentelemetry-js/pull/4454) @naseemkullah

### :bug: (Bug Fix)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ export abstract class InstrumentationAbstract<T = any>

/**
* Init method in which plugin should define _modules and patches for
* methods
* methods.
* Use `enable()` if you are trying to turn on this plugin. This method
* will return objects to patch specific modules with the appropriate
* instrumentation (or not return anything).
*/
protected abstract init():
abstract init():
| InstrumentationModuleDefinition<T>
| InstrumentationModuleDefinition<T>[]
| void;
Expand Down
6 changes: 6 additions & 0 deletions experimental/packages/opentelemetry-sdk-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ Configure a custom sampler. By default, all traces will be sampled.

### spanProcessor

Deprecated, please use [spanProcessors](#spanprocessors) instead.

### spanProcessors

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 programatically, this package will auto setup the default `otlp` exporter with `http/protobuf` protocol with a `BatchSpanProcessor`.
Expand Down
26 changes: 20 additions & 6 deletions experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export type LoggerProviderConfig = {
export class NodeSDK {
private _tracerProviderConfig?: {
tracerConfig: NodeTracerConfig;
spanProcessor: SpanProcessor;
spanProcessors: SpanProcessor[];
contextManager?: ContextManager;
textMapPropagator?: TextMapPropagator;
};
Expand Down Expand Up @@ -130,7 +130,11 @@ export class NodeSDK {
this._autoDetectResources = configuration.autoDetectResources ?? true;

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

if (configuration.sampler) {
Expand All @@ -143,13 +147,21 @@ export class NodeSDK {
tracerProviderConfig.idGenerator = configuration.idGenerator;
}

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.configureTracerProvider(
tracerProviderConfig,
spanProcessor,
spanProcessors,
configuration.contextManager,
configuration.textMapPropagator
);
Expand Down Expand Up @@ -192,13 +204,13 @@ export class NodeSDK {
*/
public configureTracerProvider(
tracerConfig: NodeTracerConfig,
spanProcessor: SpanProcessor,
spanProcessors: SpanProcessor[],
contextManager?: ContextManager,
textMapPropagator?: TextMapPropagator
): void {
this._tracerProviderConfig = {
tracerConfig,
spanProcessor,
spanProcessors,
contextManager,
textMapPropagator,
};
Expand Down Expand Up @@ -334,7 +346,9 @@ export class NodeSDK {
this._tracerProvider = tracerProvider;

if (this._tracerProviderConfig) {
tracerProvider.addSpanProcessor(this._tracerProviderConfig.spanProcessor);
for (const spanProcessor of this._tracerProviderConfig.spanProcessors) {
tracerProvider.addSpanProcessor(spanProcessor);
}
}

tracerProvider.register({
Expand Down
4 changes: 3 additions & 1 deletion experimental/packages/opentelemetry-sdk-node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export interface NodeSDKConfiguration {
resourceDetectors: Array<Detector | DetectorSync>;
sampler: Sampler;
serviceName?: string;
spanProcessor: SpanProcessor;
/** @deprecated use spanProcessors instead*/
spanProcessor?: SpanProcessor;
spanProcessors?: SpanProcessor[];
traceExporter: SpanExporter;
spanLimits: SpanLimits;
idGenerator: IdGenerator;
Expand Down
18 changes: 15 additions & 3 deletions experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,15 @@ describe('Node SDK', () => {
delete env.OTEL_TRACES_EXPORTER;
});

it('should register a tracer provider if a span processor is provided', async () => {
it('should register a tracer provider if span processors are provided', async () => {
const exporter = new ConsoleSpanExporter();
const spanProcessor = new SimpleSpanProcessor(exporter);

const sdk = new NodeSDK({
spanProcessor,
spanProcessors: [
new NoopSpanProcessor(),
new SimpleSpanProcessor(exporter),
new BatchSpanProcessor(exporter),
],
autoDetectResources: false,
});

Expand All @@ -223,6 +226,15 @@ describe('Node SDK', () => {
const apiTracerProvider =
trace.getTracerProvider() as ProxyTracerProvider;
assert.ok(apiTracerProvider.getDelegate() instanceof NodeTracerProvider);

const listOfProcessors =
sdk['_tracerProvider']!['_registeredSpanProcessors']!;

assert(sdk['_tracerProvider'] instanceof NodeTracerProvider);
assert(listOfProcessors.length === 3);
assert(listOfProcessors[0] instanceof NoopSpanProcessor);
assert(listOfProcessors[1] instanceof SimpleSpanProcessor);
assert(listOfProcessors[2] instanceof BatchSpanProcessor);
});

it('should register a meter provider if a reader is provided', async () => {
Expand Down

0 comments on commit aab138b

Please sign in to comment.