Skip to content

Commit

Permalink
Merge branch 'main' into feat/node-exporter-transport
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc committed Jun 3, 2024
2 parents c284ec4 + 95edbd9 commit 084a893
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 224 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
* feat: support node 22 [#4666](https://github.com/open-telemetry/opentelemetry-js/pull/4666) @dyladan
* feat(context-zone*): support zone.js 0.12.x [#4376](https://github.com/open-telemetry/opentelemetry-js/pull/4736) @maldago
* refactor(core): Use tree-shakeable string constants for semconv [#4739](https://github.com/open-telemetry/opentelemetry-js/pull/4739) @JohannesHuster
* refactor(shim-opentracing): Use tree-shakeable string constants for semconv [#4746](https://github.com/open-telemetry/opentelemetry-js/pull/4746) @JohannesHuster
* refactor(sdk-trace-web): Use tree-shakeable string constants for semconv [#4747](https://github.com/open-telemetry/opentelemetry-js/pull/4747) @JohannesHuster
* refactor(sdk-trace-node): Use tree-shakeable string constants for semconv [#4748](https://github.com/open-telemetry/opentelemetry-js/pull/4748) @JohannesHuster
* refactor(sdk-trace-base): Use tree-shakeable string constants for semconv [#4749](https://github.com/open-telemetry/opentelemetry-js/pull/4749) @JohannesHuster

### :bug: (Bug Fix)

Expand Down
9 changes: 9 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ All notable changes to experimental packages in this project will be documented
* (internal) the `@opentelemetry/otlp-exporter-proto-base` package has been removed, and will from now on be deprecated in `npm`
* feat(instrumentation): remove default value for config in base instrumentation constructor [#4695](https://github.com/open-telemetry/opentelemetry-js/pull/4695): @blumamir
* fix(instrumentation)!: remove unused supportedVersions from Instrumentation interface [#4694](https://github.com/open-telemetry/opentelemetry-js/pull/4694) @blumamir
* feat(instrumentation)!: simplify `registerInstrumentations()` API
* Breaking changes:
* removes `InstrumentationOptions` type
* occurrences of `InstrumentationOptions` are now replaced by `(Instrumentation | Instrumentation[])[]`
* migrate usages of `registerInstrumentations({instrumentations: fooInstrumentation})` to `registerInstrumentations({instrumentations: [fooInstrumentation]})`
* passing Instrumentation classes to `registerInstrumentations()` is now not possible anymore.
* feat(sdk-node)!: simplify type of `instrumentations` option
* Breaking changes:
* replaces `InstrumentationOptions` with `(Instrumentation | Instrumentation[])[]`
* feat(exporter-*-otlp-*)!: use transport interface in node.js exporters [#4743](https://github.com/open-telemetry/opentelemetry-js/pull/4743) @pichlermarc
* (user-facing) `headers` was intended for internal use has been removed from all exporters
* (user-facing) `compression` was intended for internal use and has been removed from all exporters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { logs } from '@opentelemetry/api-logs';
import {
disableInstrumentations,
enableInstrumentations,
parseInstrumentationOptions,
} from './autoLoaderUtils';
import { AutoLoaderOptions } from './types_internal';

Expand All @@ -32,12 +31,10 @@ import { AutoLoaderOptions } from './types_internal';
export function registerInstrumentations(
options: AutoLoaderOptions
): () => void {
const { instrumentations } = parseInstrumentationOptions(
options.instrumentations
);
const tracerProvider = options.tracerProvider || trace.getTracerProvider();
const meterProvider = options.meterProvider || metrics.getMeterProvider();
const loggerProvider = options.loggerProvider || logs.getLoggerProvider();
const instrumentations = options.instrumentations?.flat() ?? [];

enableInstrumentations(
instrumentations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,8 @@

import { TracerProvider, MeterProvider } from '@opentelemetry/api';
import { Instrumentation } from './types';
import { AutoLoaderResult, InstrumentationOption } from './types_internal';
import { LoggerProvider } from '@opentelemetry/api-logs';

/**
* Parses the options and returns instrumentations, node plugins and
* web plugins
* @param options
*/
export function parseInstrumentationOptions(
options: InstrumentationOption[] = []
): AutoLoaderResult {
let instrumentations: Instrumentation[] = [];
for (let i = 0, j = options.length; i < j; i++) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const option = options[i] as any;
if (Array.isArray(option)) {
const results = parseInstrumentationOptions(option);
instrumentations = instrumentations.concat(results.instrumentations);
} else if (typeof option === 'function') {
instrumentations.push(new option());
} else if ((option as Instrumentation).instrumentationName) {
instrumentations.push(option);
}
}

return { instrumentations };
}

/**
* Enable instrumentations
* @param instrumentations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

export * from './autoLoader';
export { registerInstrumentations } from './autoLoader';
export { InstrumentationBase } from './platform/index';
export { InstrumentationNodeModuleDefinition } from './instrumentationNodeModuleDefinition';
export { InstrumentationNodeModuleFile } from './instrumentationNodeModuleFile';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,15 @@
*/

import { TracerProvider, MeterProvider } from '@opentelemetry/api';
import { InstrumentationBase } from './platform';
import { Instrumentation } from './types';
import { LoggerProvider } from '@opentelemetry/api-logs';

export type InstrumentationOption =
| typeof InstrumentationBase
| (typeof InstrumentationBase)[]
| Instrumentation
| Instrumentation[];

export interface AutoLoaderResult {
instrumentations: Instrumentation[];
}

export interface AutoLoaderOptions {
instrumentations?: InstrumentationOption[];
instrumentations?: (Instrumentation | Instrumentation[])[];
tracerProvider?: TracerProvider;
meterProvider?: MeterProvider;
loggerProvider?: LoggerProvider;
Expand Down

This file was deleted.

19 changes: 5 additions & 14 deletions experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '@opentelemetry/api';
import { logs } from '@opentelemetry/api-logs';
import {
InstrumentationOption,
Instrumentation,
registerInstrumentations,
} from '@opentelemetry/instrumentation';
import {
Expand Down Expand Up @@ -51,10 +51,7 @@ import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
import { NodeSDKConfiguration } from './types';
import { TracerProviderWithEnvExporters } from './TracerProviderWithEnvExporter';
import { getEnv, getEnvWithoutDefaults } from '@opentelemetry/core';
import {
getResourceDetectorsFromEnv,
parseInstrumentationOptions,
} from './utils';
import { getResourceDetectorsFromEnv } from './utils';

/** This class represents everything needed to register a fully configured OpenTelemetry Node.js SDK */

Expand Down Expand Up @@ -85,7 +82,7 @@ export class NodeSDK {
};
private _loggerProviderConfig?: LoggerProviderConfig;
private _meterProviderConfig?: MeterProviderConfig;
private _instrumentations: InstrumentationOption[];
private _instrumentations: Instrumentation[];

private _resource: IResource;
private _resourceDetectors: Array<Detector | DetectorSync>;
Expand Down Expand Up @@ -196,11 +193,7 @@ export class NodeSDK {
this._meterProviderConfig = meterProviderConfig;
}

let instrumentations: InstrumentationOption[] = [];
if (configuration.instrumentations) {
instrumentations = configuration.instrumentations;
}
this._instrumentations = instrumentations;
this._instrumentations = configuration.instrumentations?.flat() ?? [];
}

/**
Expand Down Expand Up @@ -289,9 +282,7 @@ export class NodeSDK {
// TODO: This is a workaround to fix https://github.com/open-telemetry/opentelemetry-js/issues/3609
// If the MeterProvider is not yet registered when instrumentations are registered, all metrics are dropped.
// This code is obsolete once https://github.com/open-telemetry/opentelemetry-js/issues/3622 is implemented.
for (const instrumentation of parseInstrumentationOptions(
this._instrumentations
)) {
for (const instrumentation of this._instrumentations) {
instrumentation.setMeterProvider(metrics.getMeterProvider());
}
}
Expand Down
4 changes: 2 additions & 2 deletions experimental/packages/opentelemetry-sdk-node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type { ContextManager } from '@opentelemetry/api';
import { TextMapPropagator } from '@opentelemetry/api';
import { InstrumentationOption } from '@opentelemetry/instrumentation';
import { Instrumentation } from '@opentelemetry/instrumentation';
import { Detector, DetectorSync, IResource } from '@opentelemetry/resources';
import { LogRecordProcessor } from '@opentelemetry/sdk-logs';
import { MetricReader, View } from '@opentelemetry/sdk-metrics';
Expand All @@ -35,7 +35,7 @@ export interface NodeSDKConfiguration {
logRecordProcessor: LogRecordProcessor;
metricReader: MetricReader;
views: View[];
instrumentations: InstrumentationOption[];
instrumentations: (Instrumentation | Instrumentation[])[];
resource: IResource;
resourceDetectors: Array<Detector | DetectorSync>;
sampler: Sampler;
Expand Down
27 changes: 0 additions & 27 deletions experimental/packages/opentelemetry-sdk-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/

import { diag } from '@opentelemetry/api';
import {
Instrumentation,
InstrumentationOption,
} from '@opentelemetry/instrumentation';
import {
DetectorSync,
envDetectorSync,
Expand All @@ -28,29 +24,6 @@ import {
serviceInstanceIdDetectorSync,
} from '@opentelemetry/resources';

// TODO: This part of a workaround to fix https://github.com/open-telemetry/opentelemetry-js/issues/3609
// If the MeterProvider is not yet registered when instrumentations are registered, all metrics are dropped.
// This code is obsolete once https://github.com/open-telemetry/opentelemetry-js/issues/3622 is implemented.
export function parseInstrumentationOptions(
options: InstrumentationOption[] = []
): Instrumentation[] {
let instrumentations: Instrumentation[] = [];
for (let i = 0, j = options.length; i < j; i++) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const option = options[i] as any;
if (Array.isArray(option)) {
const results = parseInstrumentationOptions(option);
instrumentations = instrumentations.concat(results);
} else if (typeof option === 'function') {
instrumentations.push(new option());
} else if ((option as Instrumentation).instrumentationName) {
instrumentations.push(option);
}
}

return instrumentations;
}

const RESOURCE_DETECTOR_ENVIRONMENT = 'env';
const RESOURCE_DETECTOR_HOST = 'host';
const RESOURCE_DETECTOR_OS = 'os';
Expand Down
Loading

0 comments on commit 084a893

Please sign in to comment.