@opentelemetry/sdk-node 0.48.0 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -124,6 +124,12 @@ Configure a custom sampler. By default, all traces will be sampled.
124
124
 
125
125
  ### spanProcessor
126
126
 
127
+ Deprecated, please use [spanProcessors](#spanprocessors) instead.
128
+
129
+ ### spanProcessors
130
+
131
+ An array of span processors to register to the tracer provider.
132
+
127
133
  ### traceExporter
128
134
 
129
135
  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`.
@@ -34,6 +34,7 @@ export declare class NodeSDK {
34
34
  private _loggerProvider?;
35
35
  private _meterProvider?;
36
36
  private _serviceName?;
37
+ private _configuration?;
37
38
  private _disabled?;
38
39
  /**
39
40
  * Create a new NodeJS SDK instance
@@ -47,7 +48,7 @@ export declare class NodeSDK {
47
48
  *
48
49
  * Set configurations needed to register a TracerProvider
49
50
  */
50
- configureTracerProvider(tracerConfig: NodeTracerConfig, spanProcessor: SpanProcessor, contextManager?: ContextManager, textMapPropagator?: TextMapPropagator): void;
51
+ configureTracerProvider(tracerConfig: NodeTracerConfig, spanProcessors: SpanProcessor[], contextManager?: ContextManager, textMapPropagator?: TextMapPropagator): void;
51
52
  /**
52
53
  * @deprecated Please pass {@code logRecordProcessor} to the constructor options instead.
53
54
  *
package/build/src/sdk.js CHANGED
@@ -33,7 +33,7 @@ class NodeSDK {
33
33
  * Create a new NodeJS SDK instance
34
34
  */
35
35
  constructor(configuration = {}) {
36
- var _a, _b, _c, _d;
36
+ var _a, _b, _c, _d, _e;
37
37
  const env = (0, core_1.getEnv)();
38
38
  const envWithoutDefaults = (0, core_1.getEnvWithoutDefaults)();
39
39
  if (env.OTEL_SDK_DISABLED) {
@@ -48,6 +48,7 @@ class NodeSDK {
48
48
  logLevel: envWithoutDefaults.OTEL_LOG_LEVEL,
49
49
  });
50
50
  }
51
+ this._configuration = configuration;
51
52
  this._resource = (_a = configuration.resource) !== null && _a !== void 0 ? _a : new resources_1.Resource({});
52
53
  this._resourceDetectors = (_b = configuration.resourceDetectors) !== null && _b !== void 0 ? _b : [
53
54
  resources_1.envDetector,
@@ -55,7 +56,10 @@ class NodeSDK {
55
56
  ];
56
57
  this._serviceName = configuration.serviceName;
57
58
  this._autoDetectResources = (_c = configuration.autoDetectResources) !== null && _c !== void 0 ? _c : true;
58
- if (configuration.spanProcessor || configuration.traceExporter) {
59
+ // If a tracer provider can be created from manual configuration, create it
60
+ if (configuration.traceExporter ||
61
+ configuration.spanProcessor ||
62
+ configuration.spanProcessors) {
59
63
  const tracerProviderConfig = {};
60
64
  if (configuration.sampler) {
61
65
  tracerProviderConfig.sampler = configuration.sampler;
@@ -66,8 +70,12 @@ class NodeSDK {
66
70
  if (configuration.idGenerator) {
67
71
  tracerProviderConfig.idGenerator = configuration.idGenerator;
68
72
  }
73
+ if (configuration.spanProcessor) {
74
+ api_1.diag.warn("The 'spanProcessor' option is deprecated. Please use 'spanProcessors' instead.");
75
+ }
69
76
  const spanProcessor = (_d = configuration.spanProcessor) !== null && _d !== void 0 ? _d : new sdk_trace_base_1.BatchSpanProcessor(configuration.traceExporter);
70
- this.configureTracerProvider(tracerProviderConfig, spanProcessor, configuration.contextManager, configuration.textMapPropagator);
77
+ const spanProcessors = (_e = configuration.spanProcessors) !== null && _e !== void 0 ? _e : [spanProcessor];
78
+ this.configureTracerProvider(tracerProviderConfig, spanProcessors, configuration.contextManager, configuration.textMapPropagator);
71
79
  }
72
80
  if (configuration.logRecordProcessor) {
73
81
  const loggerProviderConfig = {
@@ -99,10 +107,10 @@ class NodeSDK {
99
107
  *
100
108
  * Set configurations needed to register a TracerProvider
101
109
  */
102
- configureTracerProvider(tracerConfig, spanProcessor, contextManager, textMapPropagator) {
110
+ configureTracerProvider(tracerConfig, spanProcessors, contextManager, textMapPropagator) {
103
111
  this._tracerProviderConfig = {
104
112
  tracerConfig,
105
- spanProcessor,
113
+ spanProcessors,
106
114
  contextManager,
107
115
  textMapPropagator,
108
116
  };
@@ -184,7 +192,7 @@ class NodeSDK {
184
192
  * Call this method to construct SDK components and register them with the OpenTelemetry API.
185
193
  */
186
194
  start() {
187
- var _a, _b, _c, _d, _e;
195
+ var _a, _b, _c, _d;
188
196
  if (this._disabled) {
189
197
  return;
190
198
  }
@@ -200,17 +208,21 @@ class NodeSDK {
200
208
  : this._resource.merge(new resources_1.Resource({
201
209
  [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: this._serviceName,
202
210
  }));
211
+ // if there is a tracerProviderConfig (traceExporter/spanProcessor was set manually) or the traceExporter is set manually, use NodeTracerProvider
203
212
  const Provider = this._tracerProviderConfig
204
213
  ? sdk_trace_node_1.NodeTracerProvider
205
214
  : TracerProviderWithEnvExporter_1.TracerProviderWithEnvExporters;
206
- const tracerProvider = new Provider(Object.assign(Object.assign({}, (_a = this._tracerProviderConfig) === null || _a === void 0 ? void 0 : _a.tracerConfig), { resource: this._resource }));
215
+ // If the Provider is configured with Env Exporters, we need to check if the SDK had any manual configurations and set them here
216
+ const tracerProvider = new Provider(Object.assign(Object.assign({}, this._configuration), { resource: this._resource }));
207
217
  this._tracerProvider = tracerProvider;
208
218
  if (this._tracerProviderConfig) {
209
- tracerProvider.addSpanProcessor(this._tracerProviderConfig.spanProcessor);
219
+ for (const spanProcessor of this._tracerProviderConfig.spanProcessors) {
220
+ tracerProvider.addSpanProcessor(spanProcessor);
221
+ }
210
222
  }
211
223
  tracerProvider.register({
212
- contextManager: (_b = this._tracerProviderConfig) === null || _b === void 0 ? void 0 : _b.contextManager,
213
- propagator: (_c = this._tracerProviderConfig) === null || _c === void 0 ? void 0 : _c.textMapPropagator,
224
+ contextManager: (_a = this._tracerProviderConfig) === null || _a === void 0 ? void 0 : _a.contextManager,
225
+ propagator: (_b = this._tracerProviderConfig) === null || _b === void 0 ? void 0 : _b.textMapPropagator,
214
226
  });
215
227
  if (this._loggerProviderConfig) {
216
228
  const loggerProvider = new sdk_logs_1.LoggerProvider({
@@ -227,7 +239,7 @@ class NodeSDK {
227
239
  }
228
240
  const meterProvider = new sdk_metrics_1.MeterProvider({
229
241
  resource: this._resource,
230
- views: (_e = (_d = this._meterProviderConfig) === null || _d === void 0 ? void 0 : _d.views) !== null && _e !== void 0 ? _e : [],
242
+ views: (_d = (_c = this._meterProviderConfig) === null || _c === void 0 ? void 0 : _c.views) !== null && _d !== void 0 ? _d : [],
231
243
  readers: readers,
232
244
  });
233
245
  this._meterProvider = meterProvider;
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAM4B;AAC5B,sDAA+C;AAC/C,oEAGwC;AACxC,wDASkC;AAClC,sDAA6E;AAC7E,4DAA+E;AAC/E,kEAGuC;AACvC,kEAGuC;AACvC,8EAAiF;AAEjF,mFAAiF;AACjF,8CAAoE;AACpE,mCAAsD;AAsBtD,MAAa,OAAO;IAuBlB;;OAEG;IACH,YAAmB,gBAA+C,EAAE;;QAClE,MAAM,GAAG,GAAG,IAAA,aAAM,GAAE,CAAC;QACrB,MAAM,kBAAkB,GAAG,IAAA,4BAAqB,GAAE,CAAC;QAEnD,IAAI,GAAG,CAAC,iBAAiB,EAAE;YACzB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,+CAA+C;YAC/C,kCAAkC;SACnC;QAED,6DAA6D;QAC7D,uDAAuD;QACvD,IAAI,kBAAkB,CAAC,cAAc,EAAE;YACrC,UAAI,CAAC,SAAS,CAAC,IAAI,uBAAiB,EAAE,EAAE;gBACtC,QAAQ,EAAE,kBAAkB,CAAC,cAAc;aAC5C,CAAC,CAAC;SACJ;QAED,IAAI,CAAC,SAAS,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,EAAE,GAAE,CAAC,CAAC,CAClB,CAAC;IACJ,CAAC;CACF;AAjUD,0BAiUC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ContextManager,\n TextMapPropagator,\n metrics,\n diag,\n DiagConsoleLogger,\n} from '@opentelemetry/api';\nimport { logs } from '@opentelemetry/api-logs';\nimport {\n InstrumentationOption,\n registerInstrumentations,\n} from '@opentelemetry/instrumentation';\nimport {\n Detector,\n DetectorSync,\n detectResourcesSync,\n envDetector,\n IResource,\n processDetector,\n Resource,\n ResourceDetectionConfig,\n} from '@opentelemetry/resources';\nimport { LogRecordProcessor, LoggerProvider } from '@opentelemetry/sdk-logs';\nimport { MeterProvider, MetricReader, View } from '@opentelemetry/sdk-metrics';\nimport {\n BatchSpanProcessor,\n SpanProcessor,\n} from '@opentelemetry/sdk-trace-base';\nimport {\n NodeTracerConfig,\n NodeTracerProvider,\n} from '@opentelemetry/sdk-trace-node';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { NodeSDKConfiguration } from './types';\nimport { TracerProviderWithEnvExporters } from './TracerProviderWithEnvExporter';\nimport { getEnv, getEnvWithoutDefaults } from '@opentelemetry/core';\nimport { parseInstrumentationOptions } from './utils';\n\n/** This class represents everything needed to register a fully configured OpenTelemetry Node.js SDK */\n\nexport type MeterProviderConfig = {\n /**\n * Reference to the MetricReader instance by the NodeSDK\n */\n reader?: MetricReader;\n /**\n * List of {@link View}s that should be passed to the MeterProvider\n */\n views?: View[];\n};\n\nexport type LoggerProviderConfig = {\n /**\n * Reference to the LoggerRecordProcessor instance by the NodeSDK\n */\n logRecordProcessor: LogRecordProcessor;\n};\n\nexport class NodeSDK {\n private _tracerProviderConfig?: {\n tracerConfig: NodeTracerConfig;\n spanProcessor: SpanProcessor;\n contextManager?: ContextManager;\n textMapPropagator?: TextMapPropagator;\n };\n private _loggerProviderConfig?: LoggerProviderConfig;\n private _meterProviderConfig?: MeterProviderConfig;\n private _instrumentations: InstrumentationOption[];\n\n private _resource: IResource;\n private _resourceDetectors: Array<Detector | DetectorSync>;\n\n private _autoDetectResources: boolean;\n\n private _tracerProvider?: NodeTracerProvider | TracerProviderWithEnvExporters;\n private _loggerProvider?: LoggerProvider;\n private _meterProvider?: MeterProvider;\n private _serviceName?: string;\n\n private _disabled?: boolean;\n\n /**\n * Create a new NodeJS SDK instance\n */\n public constructor(configuration: Partial<NodeSDKConfiguration> = {}) {\n const env = getEnv();\n const envWithoutDefaults = getEnvWithoutDefaults();\n\n if (env.OTEL_SDK_DISABLED) {\n this._disabled = true;\n // Functions with possible side-effects are set\n // to no-op via the _disabled flag\n }\n\n // Default is INFO, use environment without defaults to check\n // if the user originally set the environment variable.\n if (envWithoutDefaults.OTEL_LOG_LEVEL) {\n diag.setLogger(new DiagConsoleLogger(), {\n logLevel: envWithoutDefaults.OTEL_LOG_LEVEL,\n });\n }\n\n this._resource = configuration.resource ?? new Resource({});\n this._resourceDetectors = configuration.resourceDetectors ?? [\n envDetector,\n processDetector,\n ];\n\n this._serviceName = configuration.serviceName;\n\n this._autoDetectResources = configuration.autoDetectResources ?? true;\n\n if (configuration.spanProcessor || configuration.traceExporter) {\n const tracerProviderConfig: NodeTracerConfig = {};\n\n if (configuration.sampler) {\n tracerProviderConfig.sampler = configuration.sampler;\n }\n if (configuration.spanLimits) {\n tracerProviderConfig.spanLimits = configuration.spanLimits;\n }\n if (configuration.idGenerator) {\n tracerProviderConfig.idGenerator = configuration.idGenerator;\n }\n\n const spanProcessor =\n configuration.spanProcessor ??\n new BatchSpanProcessor(configuration.traceExporter!);\n\n this.configureTracerProvider(\n tracerProviderConfig,\n spanProcessor,\n configuration.contextManager,\n configuration.textMapPropagator\n );\n }\n\n if (configuration.logRecordProcessor) {\n const loggerProviderConfig: LoggerProviderConfig = {\n logRecordProcessor: configuration.logRecordProcessor,\n };\n this.configureLoggerProvider(loggerProviderConfig);\n }\n\n if (configuration.metricReader || configuration.views) {\n const meterProviderConfig: MeterProviderConfig = {};\n if (configuration.metricReader) {\n meterProviderConfig.reader = configuration.metricReader;\n }\n\n if (configuration.views) {\n meterProviderConfig.views = configuration.views;\n }\n\n this.configureMeterProvider(meterProviderConfig);\n }\n\n let instrumentations: InstrumentationOption[] = [];\n if (configuration.instrumentations) {\n instrumentations = configuration.instrumentations;\n }\n this._instrumentations = instrumentations;\n }\n\n /**\n *\n * @deprecated Please pass {@code sampler}, {@code generalLimits}, {@code spanLimits}, {@code resource},\n * {@code IdGenerator}, {@code spanProcessor}, {@code contextManager} and {@code textMapPropagator},\n * to the constructor options instead.\n *\n * Set configurations needed to register a TracerProvider\n */\n public configureTracerProvider(\n tracerConfig: NodeTracerConfig,\n spanProcessor: SpanProcessor,\n contextManager?: ContextManager,\n textMapPropagator?: TextMapPropagator\n ): void {\n this._tracerProviderConfig = {\n tracerConfig,\n spanProcessor,\n contextManager,\n textMapPropagator,\n };\n }\n\n /**\n * @deprecated Please pass {@code logRecordProcessor} to the constructor options instead.\n *\n * Set configurations needed to register a LoggerProvider\n */\n public configureLoggerProvider(config: LoggerProviderConfig): void {\n // nothing is set yet, we can set config and then return\n if (this._loggerProviderConfig == null) {\n this._loggerProviderConfig = config;\n return;\n }\n\n // make sure we do not override existing logRecordProcessor with other logRecordProcessors.\n if (\n this._loggerProviderConfig.logRecordProcessor != null &&\n config.logRecordProcessor != null\n ) {\n throw new Error(\n 'LogRecordProcessor passed but LogRecordProcessor has already been configured.'\n );\n }\n\n // set logRecordProcessor, but make sure we do not override existing logRecordProcessors with null/undefined.\n if (config.logRecordProcessor != null) {\n this._loggerProviderConfig.logRecordProcessor = config.logRecordProcessor;\n }\n }\n\n /**\n * @deprecated Please pass {@code views} and {@code reader} to the constructor options instead.\n *\n * Set configurations needed to register a MeterProvider\n */\n public configureMeterProvider(config: MeterProviderConfig): void {\n // nothing is set yet, we can set config and return.\n if (this._meterProviderConfig == null) {\n this._meterProviderConfig = config;\n return;\n }\n\n // make sure we do not override existing views with other views.\n if (this._meterProviderConfig.views != null && config.views != null) {\n throw new Error('Views passed but Views have already been configured.');\n }\n\n // set views, but make sure we do not override existing views with null/undefined.\n if (config.views != null) {\n this._meterProviderConfig.views = config.views;\n }\n\n // make sure we do not override existing reader with another reader.\n if (this._meterProviderConfig.reader != null && config.reader != null) {\n throw new Error(\n 'MetricReader passed but MetricReader has already been configured.'\n );\n }\n\n // set reader, but make sure we do not override existing reader with null/undefined.\n if (config.reader != null) {\n this._meterProviderConfig.reader = config.reader;\n }\n }\n\n /**\n * @deprecated Resources are detected automatically on {@link NodeSDK.start()}, when the {@code autoDetectResources}\n * constructor option is set to {@code true} or left {@code undefined}.\n *\n * Detect resource attributes\n */\n public detectResources(): void {\n if (this._disabled) {\n return;\n }\n\n const internalConfig: ResourceDetectionConfig = {\n detectors: this._resourceDetectors,\n };\n\n this.addResource(detectResourcesSync(internalConfig));\n }\n\n /**\n * @deprecated Please pre-merge resources and pass them to the constructor\n *\n * Manually add a Resource\n * @param resource\n */\n public addResource(resource: IResource): void {\n this._resource = this._resource.merge(resource);\n }\n\n /**\n * Call this method to construct SDK components and register them with the OpenTelemetry API.\n */\n public start(): void {\n if (this._disabled) {\n return;\n }\n\n registerInstrumentations({\n instrumentations: this._instrumentations,\n });\n\n if (this._autoDetectResources) {\n this.detectResources();\n }\n\n this._resource =\n this._serviceName === undefined\n ? this._resource\n : this._resource.merge(\n new Resource({\n [SemanticResourceAttributes.SERVICE_NAME]: this._serviceName,\n })\n );\n\n const Provider = this._tracerProviderConfig\n ? NodeTracerProvider\n : TracerProviderWithEnvExporters;\n\n const tracerProvider = new Provider({\n ...this._tracerProviderConfig?.tracerConfig,\n resource: this._resource,\n });\n\n this._tracerProvider = tracerProvider;\n\n if (this._tracerProviderConfig) {\n tracerProvider.addSpanProcessor(this._tracerProviderConfig.spanProcessor);\n }\n\n tracerProvider.register({\n contextManager: this._tracerProviderConfig?.contextManager,\n propagator: this._tracerProviderConfig?.textMapPropagator,\n });\n\n if (this._loggerProviderConfig) {\n const loggerProvider = new LoggerProvider({\n resource: this._resource,\n });\n loggerProvider.addLogRecordProcessor(\n this._loggerProviderConfig.logRecordProcessor\n );\n\n this._loggerProvider = loggerProvider;\n\n logs.setGlobalLoggerProvider(loggerProvider);\n }\n\n if (this._meterProviderConfig) {\n const readers: MetricReader[] = [];\n if (this._meterProviderConfig.reader) {\n readers.push(this._meterProviderConfig.reader);\n }\n const meterProvider = new MeterProvider({\n resource: this._resource,\n views: this._meterProviderConfig?.views ?? [],\n readers: readers,\n });\n\n this._meterProvider = meterProvider;\n\n metrics.setGlobalMeterProvider(meterProvider);\n\n // TODO: This is a workaround to fix https://github.com/open-telemetry/opentelemetry-js/issues/3609\n // If the MeterProvider is not yet registered when instrumentations are registered, all metrics are dropped.\n // This code is obsolete once https://github.com/open-telemetry/opentelemetry-js/issues/3622 is implemented.\n for (const instrumentation of parseInstrumentationOptions(\n this._instrumentations\n )) {\n instrumentation.setMeterProvider(metrics.getMeterProvider());\n }\n }\n }\n\n public shutdown(): Promise<void> {\n const promises: Promise<unknown>[] = [];\n if (this._tracerProvider) {\n promises.push(this._tracerProvider.shutdown());\n }\n if (this._loggerProvider) {\n promises.push(this._loggerProvider.shutdown());\n }\n if (this._meterProvider) {\n promises.push(this._meterProvider.shutdown());\n }\n\n return (\n Promise.all(promises)\n // return void instead of the array from Promise.all\n .then(() => {})\n );\n }\n}\n"]}
1
+ {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAM4B;AAC5B,sDAA+C;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SAAS;gBACxB,KAAK,EAAE,MAAA,MAAA,IAAI,CAAC,oBAAoB,0CAAE,KAAK,mCAAI,EAAE;gBAC7C,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;YAEH,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;YAEpC,aAAO,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC;YAE9C,mGAAmG;YACnG,4GAA4G;YAC5G,4GAA4G;YAC5G,KAAK,MAAM,eAAe,IAAI,IAAA,mCAA2B,EACvD,IAAI,CAAC,iBAAiB,CACvB,EAAE;gBACD,eAAe,CAAC,gBAAgB,CAAC,aAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;aAC9D;SACF;IACH,CAAC;IAEM,QAAQ;QACb,MAAM,QAAQ,GAAuB,EAAE,CAAC;QACxC,IAAI,IAAI,CAAC,eAAe,EAAE;YACxB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;SAChD;QACD,IAAI,IAAI,CAAC,eAAe,EAAE;YACxB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;SAChD;QACD,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC;SAC/C;QAED,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;YACnB,oDAAoD;aACnD,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAClB,CAAC;IACJ,CAAC;CACF;AArVD,0BAqVC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ContextManager,\n TextMapPropagator,\n metrics,\n diag,\n DiagConsoleLogger,\n} from '@opentelemetry/api';\nimport { logs } from '@opentelemetry/api-logs';\nimport {\n InstrumentationOption,\n registerInstrumentations,\n} from '@opentelemetry/instrumentation';\nimport {\n Detector,\n DetectorSync,\n detectResourcesSync,\n envDetector,\n IResource,\n processDetector,\n Resource,\n ResourceDetectionConfig,\n} from '@opentelemetry/resources';\nimport { LogRecordProcessor, LoggerProvider } from '@opentelemetry/sdk-logs';\nimport { MeterProvider, MetricReader, View } from '@opentelemetry/sdk-metrics';\nimport {\n BatchSpanProcessor,\n SpanProcessor,\n} from '@opentelemetry/sdk-trace-base';\nimport {\n NodeTracerConfig,\n NodeTracerProvider,\n} from '@opentelemetry/sdk-trace-node';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { NodeSDKConfiguration } from './types';\nimport { TracerProviderWithEnvExporters } from './TracerProviderWithEnvExporter';\nimport { getEnv, getEnvWithoutDefaults } from '@opentelemetry/core';\nimport { parseInstrumentationOptions } from './utils';\n\n/** This class represents everything needed to register a fully configured OpenTelemetry Node.js SDK */\n\nexport type MeterProviderConfig = {\n /**\n * Reference to the MetricReader instance by the NodeSDK\n */\n reader?: MetricReader;\n /**\n * List of {@link View}s that should be passed to the MeterProvider\n */\n views?: View[];\n};\n\nexport type LoggerProviderConfig = {\n /**\n * Reference to the LoggerRecordProcessor instance by the NodeSDK\n */\n logRecordProcessor: LogRecordProcessor;\n};\n\nexport class NodeSDK {\n private _tracerProviderConfig?: {\n tracerConfig: NodeTracerConfig;\n spanProcessors: SpanProcessor[];\n contextManager?: ContextManager;\n textMapPropagator?: TextMapPropagator;\n };\n private _loggerProviderConfig?: LoggerProviderConfig;\n private _meterProviderConfig?: MeterProviderConfig;\n private _instrumentations: InstrumentationOption[];\n\n private _resource: IResource;\n private _resourceDetectors: Array<Detector | DetectorSync>;\n\n private _autoDetectResources: boolean;\n\n private _tracerProvider?: NodeTracerProvider | TracerProviderWithEnvExporters;\n private _loggerProvider?: LoggerProvider;\n private _meterProvider?: MeterProvider;\n private _serviceName?: string;\n private _configuration?: Partial<NodeSDKConfiguration>;\n\n private _disabled?: boolean;\n\n /**\n * Create a new NodeJS SDK instance\n */\n public constructor(configuration: Partial<NodeSDKConfiguration> = {}) {\n const env = getEnv();\n const envWithoutDefaults = getEnvWithoutDefaults();\n\n if (env.OTEL_SDK_DISABLED) {\n this._disabled = true;\n // Functions with possible side-effects are set\n // to no-op via the _disabled flag\n }\n\n // Default is INFO, use environment without defaults to check\n // if the user originally set the environment variable.\n if (envWithoutDefaults.OTEL_LOG_LEVEL) {\n diag.setLogger(new DiagConsoleLogger(), {\n logLevel: envWithoutDefaults.OTEL_LOG_LEVEL,\n });\n }\n\n this._configuration = configuration;\n\n this._resource = configuration.resource ?? new Resource({});\n this._resourceDetectors = configuration.resourceDetectors ?? [\n envDetector,\n processDetector,\n ];\n\n this._serviceName = configuration.serviceName;\n\n this._autoDetectResources = configuration.autoDetectResources ?? true;\n\n // If a tracer provider can be created from manual configuration, create it\n if (\n configuration.traceExporter ||\n configuration.spanProcessor ||\n configuration.spanProcessors\n ) {\n const tracerProviderConfig: NodeTracerConfig = {};\n\n if (configuration.sampler) {\n tracerProviderConfig.sampler = configuration.sampler;\n }\n if (configuration.spanLimits) {\n tracerProviderConfig.spanLimits = configuration.spanLimits;\n }\n if (configuration.idGenerator) {\n tracerProviderConfig.idGenerator = configuration.idGenerator;\n }\n\n if (configuration.spanProcessor) {\n diag.warn(\n \"The 'spanProcessor' option is deprecated. Please use 'spanProcessors' instead.\"\n );\n }\n\n const spanProcessor =\n configuration.spanProcessor ??\n new BatchSpanProcessor(configuration.traceExporter!);\n\n const spanProcessors = configuration.spanProcessors ?? [spanProcessor];\n\n this.configureTracerProvider(\n tracerProviderConfig,\n spanProcessors,\n configuration.contextManager,\n configuration.textMapPropagator\n );\n }\n\n if (configuration.logRecordProcessor) {\n const loggerProviderConfig: LoggerProviderConfig = {\n logRecordProcessor: configuration.logRecordProcessor,\n };\n this.configureLoggerProvider(loggerProviderConfig);\n }\n\n if (configuration.metricReader || configuration.views) {\n const meterProviderConfig: MeterProviderConfig = {};\n if (configuration.metricReader) {\n meterProviderConfig.reader = configuration.metricReader;\n }\n\n if (configuration.views) {\n meterProviderConfig.views = configuration.views;\n }\n\n this.configureMeterProvider(meterProviderConfig);\n }\n\n let instrumentations: InstrumentationOption[] = [];\n if (configuration.instrumentations) {\n instrumentations = configuration.instrumentations;\n }\n this._instrumentations = instrumentations;\n }\n\n /**\n *\n * @deprecated Please pass {@code sampler}, {@code generalLimits}, {@code spanLimits}, {@code resource},\n * {@code IdGenerator}, {@code spanProcessor}, {@code contextManager} and {@code textMapPropagator},\n * to the constructor options instead.\n *\n * Set configurations needed to register a TracerProvider\n */\n public configureTracerProvider(\n tracerConfig: NodeTracerConfig,\n spanProcessors: SpanProcessor[],\n contextManager?: ContextManager,\n textMapPropagator?: TextMapPropagator\n ): void {\n this._tracerProviderConfig = {\n tracerConfig,\n spanProcessors,\n contextManager,\n textMapPropagator,\n };\n }\n\n /**\n * @deprecated Please pass {@code logRecordProcessor} to the constructor options instead.\n *\n * Set configurations needed to register a LoggerProvider\n */\n public configureLoggerProvider(config: LoggerProviderConfig): void {\n // nothing is set yet, we can set config and then return\n if (this._loggerProviderConfig == null) {\n this._loggerProviderConfig = config;\n return;\n }\n\n // make sure we do not override existing logRecordProcessor with other logRecordProcessors.\n if (\n this._loggerProviderConfig.logRecordProcessor != null &&\n config.logRecordProcessor != null\n ) {\n throw new Error(\n 'LogRecordProcessor passed but LogRecordProcessor has already been configured.'\n );\n }\n\n // set logRecordProcessor, but make sure we do not override existing logRecordProcessors with null/undefined.\n if (config.logRecordProcessor != null) {\n this._loggerProviderConfig.logRecordProcessor = config.logRecordProcessor;\n }\n }\n\n /**\n * @deprecated Please pass {@code views} and {@code reader} to the constructor options instead.\n *\n * Set configurations needed to register a MeterProvider\n */\n public configureMeterProvider(config: MeterProviderConfig): void {\n // nothing is set yet, we can set config and return.\n if (this._meterProviderConfig == null) {\n this._meterProviderConfig = config;\n return;\n }\n\n // make sure we do not override existing views with other views.\n if (this._meterProviderConfig.views != null && config.views != null) {\n throw new Error('Views passed but Views have already been configured.');\n }\n\n // set views, but make sure we do not override existing views with null/undefined.\n if (config.views != null) {\n this._meterProviderConfig.views = config.views;\n }\n\n // make sure we do not override existing reader with another reader.\n if (this._meterProviderConfig.reader != null && config.reader != null) {\n throw new Error(\n 'MetricReader passed but MetricReader has already been configured.'\n );\n }\n\n // set reader, but make sure we do not override existing reader with null/undefined.\n if (config.reader != null) {\n this._meterProviderConfig.reader = config.reader;\n }\n }\n\n /**\n * @deprecated Resources are detected automatically on {@link NodeSDK.start()}, when the {@code autoDetectResources}\n * constructor option is set to {@code true} or left {@code undefined}.\n *\n * Detect resource attributes\n */\n public detectResources(): void {\n if (this._disabled) {\n return;\n }\n\n const internalConfig: ResourceDetectionConfig = {\n detectors: this._resourceDetectors,\n };\n\n this.addResource(detectResourcesSync(internalConfig));\n }\n\n /**\n * @deprecated Please pre-merge resources and pass them to the constructor\n *\n * Manually add a Resource\n * @param resource\n */\n public addResource(resource: IResource): void {\n this._resource = this._resource.merge(resource);\n }\n\n /**\n * Call this method to construct SDK components and register them with the OpenTelemetry API.\n */\n public start(): void {\n if (this._disabled) {\n return;\n }\n\n registerInstrumentations({\n instrumentations: this._instrumentations,\n });\n\n if (this._autoDetectResources) {\n this.detectResources();\n }\n\n this._resource =\n this._serviceName === undefined\n ? this._resource\n : this._resource.merge(\n new Resource({\n [SemanticResourceAttributes.SERVICE_NAME]: this._serviceName,\n })\n );\n\n // if there is a tracerProviderConfig (traceExporter/spanProcessor was set manually) or the traceExporter is set manually, use NodeTracerProvider\n const Provider = this._tracerProviderConfig\n ? NodeTracerProvider\n : TracerProviderWithEnvExporters;\n\n // If the Provider is configured with Env Exporters, we need to check if the SDK had any manual configurations and set them here\n const tracerProvider = new Provider({\n ...this._configuration,\n resource: this._resource,\n });\n\n this._tracerProvider = tracerProvider;\n\n if (this._tracerProviderConfig) {\n for (const spanProcessor of this._tracerProviderConfig.spanProcessors) {\n tracerProvider.addSpanProcessor(spanProcessor);\n }\n }\n\n tracerProvider.register({\n contextManager: this._tracerProviderConfig?.contextManager,\n propagator: this._tracerProviderConfig?.textMapPropagator,\n });\n\n if (this._loggerProviderConfig) {\n const loggerProvider = new LoggerProvider({\n resource: this._resource,\n });\n loggerProvider.addLogRecordProcessor(\n this._loggerProviderConfig.logRecordProcessor\n );\n\n this._loggerProvider = loggerProvider;\n\n logs.setGlobalLoggerProvider(loggerProvider);\n }\n\n if (this._meterProviderConfig) {\n const readers: MetricReader[] = [];\n if (this._meterProviderConfig.reader) {\n readers.push(this._meterProviderConfig.reader);\n }\n const meterProvider = new MeterProvider({\n resource: this._resource,\n views: this._meterProviderConfig?.views ?? [],\n readers: readers,\n });\n\n this._meterProvider = meterProvider;\n\n metrics.setGlobalMeterProvider(meterProvider);\n\n // TODO: This is a workaround to fix https://github.com/open-telemetry/opentelemetry-js/issues/3609\n // If the MeterProvider is not yet registered when instrumentations are registered, all metrics are dropped.\n // This code is obsolete once https://github.com/open-telemetry/opentelemetry-js/issues/3622 is implemented.\n for (const instrumentation of parseInstrumentationOptions(\n this._instrumentations\n )) {\n instrumentation.setMeterProvider(metrics.getMeterProvider());\n }\n }\n }\n\n public shutdown(): Promise<void> {\n const promises: Promise<unknown>[] = [];\n if (this._tracerProvider) {\n promises.push(this._tracerProvider.shutdown());\n }\n if (this._loggerProvider) {\n promises.push(this._loggerProvider.shutdown());\n }\n if (this._meterProvider) {\n promises.push(this._meterProvider.shutdown());\n }\n\n return (\n Promise.all(promises)\n // return void instead of the array from Promise.all\n .then(() => {})\n );\n }\n}\n"]}
@@ -17,7 +17,9 @@ export interface NodeSDKConfiguration {
17
17
  resourceDetectors: Array<Detector | DetectorSync>;
18
18
  sampler: Sampler;
19
19
  serviceName?: string;
20
- spanProcessor: SpanProcessor;
20
+ /** @deprecated use spanProcessors instead*/
21
+ spanProcessor?: SpanProcessor;
22
+ spanProcessors?: SpanProcessor[];
21
23
  traceExporter: SpanExporter;
22
24
  spanLimits: SpanLimits;
23
25
  idGenerator: IdGenerator;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ContextManager } from '@opentelemetry/api';\nimport { TextMapPropagator } from '@opentelemetry/api';\nimport { InstrumentationOption } from '@opentelemetry/instrumentation';\nimport { Detector, DetectorSync, IResource } from '@opentelemetry/resources';\nimport { LogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { MetricReader, View } from '@opentelemetry/sdk-metrics';\nimport {\n Sampler,\n SpanExporter,\n SpanLimits,\n SpanProcessor,\n IdGenerator,\n} from '@opentelemetry/sdk-trace-base';\n\nexport interface NodeSDKConfiguration {\n autoDetectResources: boolean;\n contextManager: ContextManager;\n textMapPropagator: TextMapPropagator;\n logRecordProcessor: LogRecordProcessor;\n metricReader: MetricReader;\n views: View[];\n instrumentations: InstrumentationOption[];\n resource: IResource;\n resourceDetectors: Array<Detector | DetectorSync>;\n sampler: Sampler;\n serviceName?: string;\n spanProcessor: SpanProcessor;\n traceExporter: SpanExporter;\n spanLimits: SpanLimits;\n idGenerator: IdGenerator;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ContextManager } from '@opentelemetry/api';\nimport { TextMapPropagator } from '@opentelemetry/api';\nimport { InstrumentationOption } from '@opentelemetry/instrumentation';\nimport { Detector, DetectorSync, IResource } from '@opentelemetry/resources';\nimport { LogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { MetricReader, View } from '@opentelemetry/sdk-metrics';\nimport {\n Sampler,\n SpanExporter,\n SpanLimits,\n SpanProcessor,\n IdGenerator,\n} from '@opentelemetry/sdk-trace-base';\n\nexport interface NodeSDKConfiguration {\n autoDetectResources: boolean;\n contextManager: ContextManager;\n textMapPropagator: TextMapPropagator;\n logRecordProcessor: LogRecordProcessor;\n metricReader: MetricReader;\n views: View[];\n instrumentations: InstrumentationOption[];\n resource: IResource;\n resourceDetectors: Array<Detector | DetectorSync>;\n sampler: Sampler;\n serviceName?: string;\n /** @deprecated use spanProcessors instead*/\n spanProcessor?: SpanProcessor;\n spanProcessors?: SpanProcessor[];\n traceExporter: SpanExporter;\n spanLimits: SpanLimits;\n idGenerator: IdGenerator;\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.48.0";
1
+ export declare const VERSION = "0.49.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -17,5 +17,5 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.VERSION = '0.48.0';
20
+ exports.VERSION = '0.49.0';
21
21
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.48.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.49.0';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/sdk-node",
3
- "version": "0.48.0",
3
+ "version": "0.49.0",
4
4
  "description": "OpenTelemetry SDK for Node.js",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -44,27 +44,27 @@
44
44
  "access": "public"
45
45
  },
46
46
  "dependencies": {
47
- "@opentelemetry/api-logs": "0.48.0",
48
- "@opentelemetry/core": "1.21.0",
49
- "@opentelemetry/exporter-trace-otlp-grpc": "0.48.0",
50
- "@opentelemetry/exporter-trace-otlp-http": "0.48.0",
51
- "@opentelemetry/exporter-trace-otlp-proto": "0.48.0",
52
- "@opentelemetry/exporter-zipkin": "1.21.0",
53
- "@opentelemetry/instrumentation": "0.48.0",
54
- "@opentelemetry/resources": "1.21.0",
55
- "@opentelemetry/sdk-logs": "0.48.0",
56
- "@opentelemetry/sdk-metrics": "1.21.0",
57
- "@opentelemetry/sdk-trace-base": "1.21.0",
58
- "@opentelemetry/sdk-trace-node": "1.21.0",
59
- "@opentelemetry/semantic-conventions": "1.21.0"
47
+ "@opentelemetry/api-logs": "0.49.0",
48
+ "@opentelemetry/core": "1.22.0",
49
+ "@opentelemetry/exporter-trace-otlp-grpc": "0.49.0",
50
+ "@opentelemetry/exporter-trace-otlp-http": "0.49.0",
51
+ "@opentelemetry/exporter-trace-otlp-proto": "0.49.0",
52
+ "@opentelemetry/exporter-zipkin": "1.22.0",
53
+ "@opentelemetry/instrumentation": "0.49.0",
54
+ "@opentelemetry/resources": "1.22.0",
55
+ "@opentelemetry/sdk-logs": "0.49.0",
56
+ "@opentelemetry/sdk-metrics": "1.22.0",
57
+ "@opentelemetry/sdk-trace-base": "1.22.0",
58
+ "@opentelemetry/sdk-trace-node": "1.22.0",
59
+ "@opentelemetry/semantic-conventions": "1.22.0"
60
60
  },
61
61
  "peerDependencies": {
62
- "@opentelemetry/api": ">=1.3.0 <1.8.0"
62
+ "@opentelemetry/api": ">=1.3.0 <1.9.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@opentelemetry/api": "1.7.0",
66
- "@opentelemetry/context-async-hooks": "1.21.0",
67
- "@opentelemetry/exporter-jaeger": "1.21.0",
65
+ "@opentelemetry/api": "1.8.0",
66
+ "@opentelemetry/context-async-hooks": "1.22.0",
67
+ "@opentelemetry/exporter-jaeger": "1.22.0",
68
68
  "@types/mocha": "10.0.6",
69
69
  "@types/node": "18.6.5",
70
70
  "@types/semver": "7.5.6",
@@ -82,5 +82,5 @@
82
82
  },
83
83
  "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-sdk-node",
84
84
  "sideEffects": false,
85
- "gitHead": "828f2ed730e4d26d71f92e220f96b60a552a673a"
85
+ "gitHead": "7be35c7845e206b27b682e8ce1cee850b09cec04"
86
86
  }