@opentelemetry/sdk-node 0.222.0-development.0 → 0.300.0-development.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.
Files changed (72) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  2. package/dist/create-from-config.cjs +753 -0
  3. package/dist/create-from-config.cjs.map +1 -0
  4. package/dist/create-from-config.mjs +740 -0
  5. package/dist/create-from-config.mjs.map +1 -0
  6. package/dist/create-from-env.cjs +59 -0
  7. package/dist/create-from-env.cjs.map +1 -0
  8. package/dist/create-from-env.mjs +57 -0
  9. package/dist/create-from-env.mjs.map +1 -0
  10. package/dist/diag.cjs +95 -0
  11. package/dist/diag.cjs.map +1 -0
  12. package/dist/diag.mjs +95 -0
  13. package/dist/diag.mjs.map +1 -0
  14. package/dist/index.cjs +52 -0
  15. package/dist/index.d.cts +9 -0
  16. package/dist/index.d.mts +9 -0
  17. package/dist/index.mjs +8 -0
  18. package/dist/sdk.cjs +206 -0
  19. package/dist/sdk.cjs.map +1 -0
  20. package/dist/sdk.d.cts +65 -0
  21. package/dist/sdk.d.cts.map +1 -0
  22. package/dist/sdk.d.mts +65 -0
  23. package/dist/sdk.d.mts.map +1 -0
  24. package/dist/sdk.mjs +206 -0
  25. package/dist/sdk.mjs.map +1 -0
  26. package/dist/start.cjs +76 -0
  27. package/dist/start.cjs.map +1 -0
  28. package/dist/start.d.cts +12 -0
  29. package/dist/start.d.cts.map +1 -0
  30. package/dist/start.d.mts +12 -0
  31. package/dist/start.d.mts.map +1 -0
  32. package/dist/start.mjs +75 -0
  33. package/dist/start.mjs.map +1 -0
  34. package/dist/types.d.cts +42 -0
  35. package/dist/types.d.cts.map +1 -0
  36. package/dist/types.d.mts +42 -0
  37. package/dist/types.d.mts.map +1 -0
  38. package/dist/utils.cjs +214 -0
  39. package/dist/utils.cjs.map +1 -0
  40. package/dist/utils.mjs +203 -0
  41. package/dist/utils.mjs.map +1 -0
  42. package/package.json +47 -41
  43. package/build/src/create-from-config.d.ts +0 -29
  44. package/build/src/create-from-config.js +0 -1036
  45. package/build/src/create-from-config.js.map +0 -1
  46. package/build/src/create-from-env.d.ts +0 -11
  47. package/build/src/create-from-env.js +0 -81
  48. package/build/src/create-from-env.js.map +0 -1
  49. package/build/src/diag.d.ts +0 -47
  50. package/build/src/diag.js +0 -100
  51. package/build/src/diag.js.map +0 -1
  52. package/build/src/index.d.ts +0 -19
  53. package/build/src/index.js +0 -32
  54. package/build/src/index.js.map +0 -1
  55. package/build/src/sdk.d.ts +0 -62
  56. package/build/src/sdk.js +0 -315
  57. package/build/src/sdk.js.map +0 -1
  58. package/build/src/semconv.d.ts +0 -62
  59. package/build/src/semconv.js +0 -74
  60. package/build/src/semconv.js.map +0 -1
  61. package/build/src/start.d.ts +0 -12
  62. package/build/src/start.js +0 -121
  63. package/build/src/start.js.map +0 -1
  64. package/build/src/types.d.ts +0 -55
  65. package/build/src/types.js +0 -7
  66. package/build/src/types.js.map +0 -1
  67. package/build/src/utils.d.ts +0 -31
  68. package/build/src/utils.js +0 -327
  69. package/build/src/utils.js.map +0 -1
  70. package/build/src/version.d.ts +0 -2
  71. package/build/src/version.js +0 -10
  72. package/build/src/version.js.map +0 -1
package/build/src/sdk.js DELETED
@@ -1,315 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.NodeSDK = void 0;
8
- const api_1 = require("@opentelemetry/api");
9
- const api_logs_1 = require("@opentelemetry/api-logs");
10
- const instrumentation_1 = require("@opentelemetry/instrumentation");
11
- const resources_1 = require("@opentelemetry/resources");
12
- const sdk_logs_1 = require("@opentelemetry/sdk-logs");
13
- const exporter_logs_otlp_http_1 = require("@opentelemetry/exporter-logs-otlp-http");
14
- const exporter_logs_otlp_grpc_1 = require("@opentelemetry/exporter-logs-otlp-grpc");
15
- const exporter_logs_otlp_proto_1 = require("@opentelemetry/exporter-logs-otlp-proto");
16
- const exporter_prometheus_1 = require("@opentelemetry/exporter-prometheus");
17
- const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
18
- const sdk_trace_1 = require("@opentelemetry/sdk-trace");
19
- const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
20
- const core_1 = require("@opentelemetry/core");
21
- const utils_1 = require("./utils");
22
- const create_from_env_1 = require("./create-from-env");
23
- /**
24
- *
25
- * @returns MetricReader[] if appropriate environment variables are configured
26
- */
27
- function getMetricReadersFromEnv() {
28
- const metricReaders = [];
29
- const enabledExporters = Array.from(new Set((0, core_1.getStringListFromEnv)('OTEL_METRICS_EXPORTER') ?? []));
30
- if (enabledExporters.length === 0) {
31
- api_1.diag.debug('OTEL_METRICS_EXPORTER is empty. Using default otlp exporter.');
32
- enabledExporters.push('otlp');
33
- }
34
- if (enabledExporters.includes('none')) {
35
- api_1.diag.info('OTEL_METRICS_EXPORTER contains "none". Metric provider will not be initialized.');
36
- return metricReaders;
37
- }
38
- enabledExporters.forEach(exporter => {
39
- if (exporter === 'otlp') {
40
- metricReaders.push((0, utils_1.getPeriodicExportingMetricReaderFromEnv)((0, utils_1.getOtlpMetricExporterFromEnv)()));
41
- }
42
- else if (exporter === 'console') {
43
- metricReaders.push(new sdk_metrics_1.PeriodicExportingMetricReader({
44
- exporter: new sdk_metrics_1.ConsoleMetricExporter(),
45
- }));
46
- }
47
- else if (exporter === 'prometheus') {
48
- metricReaders.push(new exporter_prometheus_1.PrometheusExporter());
49
- }
50
- else {
51
- api_1.diag.warn(`Unsupported OTEL_METRICS_EXPORTER value: "${exporter}". Supported values are: otlp, console, prometheus, none.`);
52
- }
53
- });
54
- return metricReaders;
55
- }
56
- /**
57
- * A setup helper for the OpenTelemetry SDKs (logs, metrics, traces).
58
- * <p> After successful setup using {@link NodeSDK#start()}, use `@opentelemetry/api` to obtain the registered components.
59
- * <p> Use the shutdown handler {@link NodeSDK#shutdown()} to ensure your telemetry is exported before the process exits.
60
- *
61
- * @example <caption> Register SDK by using environment variables </caption>
62
- * const nodeSdk = new NodeSDK(); // providing no options uses OTEL_* environment variables for SDK setup.
63
- * nodeSdk.start(); // registers all configured SDK components
64
- * @example <caption> Override environment variable config with your own components </caption>
65
- * const nodeSdk = new NodeSDK({
66
- * // override the list of metric reader with your own options and ignore environment variable config
67
- * // explore the docs of other options to learn more!
68
- * metricReaders: [ new PeriodicExportingMetricReader({
69
- * exporter: new OTLPMetricsExporter()
70
- * })]
71
- * });
72
- * nodeSdk.start(); // registers all configured SDK components
73
- */
74
- class NodeSDK {
75
- _loggerProviderConfig;
76
- _meterProviderConfig;
77
- _instrumentations;
78
- _resource;
79
- _resourceDetectors;
80
- _autoDetectResources;
81
- _tracerProvider;
82
- _loggerProvider;
83
- _meterProvider;
84
- _serviceName;
85
- _configuration;
86
- _disabled;
87
- /**
88
- * Create a new NodeJS SDK instance
89
- */
90
- constructor(configuration = {}) {
91
- if ((0, core_1.getBooleanFromEnv)('OTEL_SDK_DISABLED')) {
92
- this._disabled = true;
93
- // Functions with possible side-effects are set
94
- // to no-op via the _disabled flag
95
- }
96
- const logLevel = (0, core_1.getStringFromEnv)('OTEL_LOG_LEVEL');
97
- if (logLevel != null) {
98
- api_1.diag.setLogger(new api_1.DiagConsoleLogger(), {
99
- logLevel: (0, core_1.diagLogLevelFromString)(logLevel),
100
- });
101
- }
102
- this._configuration = configuration;
103
- this._resource = configuration.resource ?? (0, resources_1.defaultResource)();
104
- this._autoDetectResources = configuration.autoDetectResources ?? true;
105
- if (!this._autoDetectResources) {
106
- this._resourceDetectors = [];
107
- }
108
- else if (configuration.resourceDetectors != null) {
109
- this._resourceDetectors = configuration.resourceDetectors;
110
- }
111
- else if ((0, core_1.getStringFromEnv)('OTEL_NODE_RESOURCE_DETECTORS')) {
112
- this._resourceDetectors = (0, utils_1.getResourceDetectorsFromEnv)();
113
- }
114
- else {
115
- this._resourceDetectors = [resources_1.envDetector, resources_1.processDetector, resources_1.hostDetector];
116
- }
117
- this._serviceName = configuration.serviceName;
118
- if (configuration.spanProcessor) {
119
- api_1.diag.warn("The 'spanProcessor' option is deprecated. Please use 'spanProcessors' instead.");
120
- }
121
- if (configuration.logRecordProcessors) {
122
- this._loggerProviderConfig = {
123
- logRecordProcessors: configuration.logRecordProcessors,
124
- };
125
- }
126
- else if (configuration.logRecordProcessor) {
127
- this._loggerProviderConfig = {
128
- logRecordProcessors: [configuration.logRecordProcessor],
129
- };
130
- api_1.diag.warn("The 'logRecordProcessor' option is deprecated. Please use 'logRecordProcessors' instead.");
131
- }
132
- if (configuration.metricReaders) {
133
- this._meterProviderConfig = {
134
- readers: configuration.metricReaders,
135
- views: configuration.views,
136
- };
137
- }
138
- else if (configuration.metricReader) {
139
- this._meterProviderConfig = {
140
- readers: [configuration.metricReader],
141
- views: configuration.views,
142
- };
143
- api_1.diag.warn("The 'metricReader' option is deprecated. Please use 'metricReaders' instead.");
144
- }
145
- else {
146
- this._meterProviderConfig = {
147
- readers: getMetricReadersFromEnv(),
148
- views: configuration.views,
149
- };
150
- }
151
- this._instrumentations = configuration.instrumentations?.flat() ?? [];
152
- }
153
- /**
154
- * Call this method to construct SDK components and register them with the OpenTelemetry API.
155
- */
156
- start() {
157
- if (this._disabled) {
158
- return;
159
- }
160
- (0, instrumentation_1.registerInstrumentations)({
161
- instrumentations: this._instrumentations,
162
- });
163
- (0, utils_1.setupContextManager)(this._configuration?.contextManager);
164
- (0, utils_1.setupPropagator)(this._configuration?.textMapPropagator === null
165
- ? null // null means don't set, so we cannot fall back to env config.
166
- : (this._configuration?.textMapPropagator ?? (0, utils_1.getPropagatorFromEnv)()));
167
- if (this._autoDetectResources) {
168
- const internalConfig = {
169
- detectors: this._resourceDetectors,
170
- };
171
- this._resource = this._resource.merge((0, resources_1.detectResources)(internalConfig));
172
- }
173
- this._resource =
174
- this._serviceName === undefined
175
- ? this._resource
176
- : this._resource.merge((0, resources_1.resourceFromAttributes)({
177
- [semantic_conventions_1.ATTR_SERVICE_NAME]: this._serviceName,
178
- }));
179
- // While SDK metrics are unstable, we require an opt-in.
180
- // https://opentelemetry.io/docs/specs/semconv/otel/sdk-metrics/
181
- const sdkMetricsEnabled = (0, core_1.getBooleanFromEnv)('OTEL_NODE_EXPERIMENTAL_SDK_METRICS');
182
- if (this._meterProviderConfig?.readers &&
183
- // only register if there is a reader, otherwise we waste compute/memory.
184
- this._meterProviderConfig.readers.length > 0) {
185
- const meterProvider = new sdk_metrics_1.MeterProvider({
186
- resource: this._resource,
187
- views: this._meterProviderConfig?.views ?? [],
188
- readers: this._meterProviderConfig.readers,
189
- sdkMetricsEnabled,
190
- });
191
- this._meterProvider = meterProvider;
192
- api_1.metrics.setGlobalMeterProvider(meterProvider);
193
- // TODO: This is a workaround to fix https://github.com/open-telemetry/opentelemetry-js/issues/3609
194
- // If the MeterProvider is not yet registered when instrumentations are registered, all metrics are dropped.
195
- // This code is obsolete once https://github.com/open-telemetry/opentelemetry-js/issues/3622 is implemented.
196
- for (const instrumentation of this._instrumentations) {
197
- instrumentation.setMeterProvider(api_1.metrics.getMeterProvider());
198
- }
199
- }
200
- // Determine `spanProcessors` from multiple possible options.
201
- let spanProcessors;
202
- if (this._configuration?.spanProcessors) {
203
- spanProcessors = this._configuration.spanProcessors;
204
- }
205
- else if (this._configuration?.spanProcessor) {
206
- spanProcessors = [this._configuration.spanProcessor];
207
- }
208
- else if (this._configuration?.traceExporter) {
209
- spanProcessors = [
210
- (0, create_from_env_1.createBatchSpanProcessorFromEnv)(this._configuration.traceExporter, sdkMetricsEnabled ? this._meterProvider : undefined),
211
- ];
212
- }
213
- else {
214
- spanProcessors = (0, utils_1.getSpanProcessorsFromEnv)(sdkMetricsEnabled ? this._meterProvider : undefined);
215
- }
216
- // Only register if there is a span processor
217
- if (spanProcessors.length > 0) {
218
- this._tracerProvider = new sdk_trace_1.TracerProvider({
219
- sampler: this._configuration?.sampler ?? (0, create_from_env_1.createSamplerFromEnv)(),
220
- spanLimits: {
221
- ...(0, create_from_env_1.createSpanLimitsFromEnv)(),
222
- ...this._configuration?.spanLimits,
223
- },
224
- resource: this._resource,
225
- meterProvider: sdkMetricsEnabled ? this._meterProvider : undefined,
226
- idGenerator: this._configuration?.idGenerator,
227
- spanProcessors,
228
- });
229
- api_1.trace.setGlobalTracerProvider(this._tracerProvider);
230
- }
231
- if (!this._loggerProviderConfig) {
232
- this.configureLoggerProviderFromEnv(sdkMetricsEnabled ? this._meterProvider : undefined);
233
- }
234
- if (this._loggerProviderConfig) {
235
- const loggerProvider = new sdk_logs_1.LoggerProvider({
236
- ...(0, utils_1.getLoggerProviderConfigFromEnv)(),
237
- resource: this._resource,
238
- processors: this._loggerProviderConfig.logRecordProcessors,
239
- meterProvider: sdkMetricsEnabled ? this._meterProvider : undefined,
240
- });
241
- this._loggerProvider = loggerProvider;
242
- api_logs_1.logs.setGlobalLoggerProvider(loggerProvider);
243
- }
244
- }
245
- shutdown() {
246
- const promises = [];
247
- if (this._tracerProvider) {
248
- promises.push(this._tracerProvider.shutdown());
249
- }
250
- if (this._loggerProvider) {
251
- promises.push(this._loggerProvider.shutdown());
252
- }
253
- if (this._meterProvider) {
254
- promises.push(this._meterProvider.shutdown());
255
- }
256
- return (Promise.all(promises)
257
- // return void instead of the array from Promise.all
258
- .then(() => { }));
259
- }
260
- configureLoggerProviderFromEnv(meterProvider) {
261
- const enabledExporters = Array.from(new Set((0, core_1.getStringListFromEnv)('OTEL_LOGS_EXPORTER') ?? []));
262
- if (enabledExporters.length === 0) {
263
- api_1.diag.debug('OTEL_LOGS_EXPORTER is empty. Using default otlp exporter.');
264
- enabledExporters.push('otlp');
265
- }
266
- if (enabledExporters.includes('none')) {
267
- api_1.diag.info('OTEL_LOGS_EXPORTER contains "none". Logger provider will not be initialized.');
268
- return;
269
- }
270
- const exporters = [];
271
- enabledExporters.forEach(exporter => {
272
- if (exporter === 'otlp') {
273
- const protocol = ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_PROTOCOL') ??
274
- (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_PROTOCOL'))?.trim() || 'http/protobuf'; // Using || to also fall back on empty string
275
- switch (protocol) {
276
- case 'grpc':
277
- exporters.push(new exporter_logs_otlp_grpc_1.OTLPLogExporter());
278
- break;
279
- case 'http/json':
280
- exporters.push(new exporter_logs_otlp_http_1.OTLPLogExporter());
281
- break;
282
- case 'http/protobuf':
283
- exporters.push(new exporter_logs_otlp_proto_1.OTLPLogExporter());
284
- break;
285
- default:
286
- api_1.diag.warn(`Unsupported OTLP logs protocol: "${protocol}". Using http/protobuf.`);
287
- exporters.push(new exporter_logs_otlp_proto_1.OTLPLogExporter());
288
- }
289
- }
290
- else if (exporter === 'console') {
291
- exporters.push(new sdk_logs_1.ConsoleLogRecordExporter());
292
- }
293
- else {
294
- api_1.diag.warn(`Unsupported OTEL_LOGS_EXPORTER value: "${exporter}". Supported values are: otlp, console, none.`);
295
- }
296
- });
297
- if (exporters.length > 0) {
298
- this._loggerProviderConfig = {
299
- logRecordProcessors: exporters.map(exporter => {
300
- if (exporter instanceof sdk_logs_1.ConsoleLogRecordExporter) {
301
- return new sdk_logs_1.SimpleLogRecordProcessor({
302
- exporter,
303
- selfObsMeterProvider: meterProvider,
304
- });
305
- }
306
- else {
307
- return (0, utils_1.getBatchLogRecordProcessorFromEnv)(exporter, meterProvider);
308
- }
309
- }),
310
- };
311
- }
312
- }
313
- }
314
- exports.NodeSDK = NodeSDK;
315
- //# sourceMappingURL=sdk.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAA6E;AAC7E,sDAA+C;AAE/C,oEAA0E;AAM1E,wDAOkC;AAKlC,sDAIiC;AACjC,oFAAgG;AAChG,oFAAgG;AAChG,sFAAkG;AAClG,4EAAoG;AAEpG,4DAIoC;AAEpC,wDAA0D;AAC1D,8EAAwE;AAExE,8CAK6B;AA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CAAC;wBACF,SAAS,CAAC,IAAI,CAAC,IAAI,0CAAoB,EAAE,CAAC,CAAC;iBAC9C;aACF;iBAAM,IAAI,QAAQ,KAAK,SAAS,EAAE;gBACjC,SAAS,CAAC,IAAI,CAAC,IAAI,mCAAwB,EAAE,CAAC,CAAC;aAChD;iBAAM;gBACL,UAAI,CAAC,IAAI,CACP,0CAA0C,QAAQ,+CAA+C,CAClG,CAAC;aACH;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;YACxB,IAAI,CAAC,qBAAqB,GAAG;gBAC3B,mBAAmB,EAAE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;oBAC5C,IAAI,QAAQ,YAAY,mCAAwB,EAAE;wBAChD,OAAO,IAAI,mCAAwB,CAAC;4BAClC,QAAQ;4BACR,oBAAoB,EAAE,aAAa;yBACpC,CAAC,CAAC;qBACJ;yBAAM;wBACL,OAAO,IAAA,yCAAiC,EAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;qBACnE;gBACH,CAAC,CAAC;aACH,CAAC;SACH;IACH,CAAC;CACF;AA7SD,0BA6SC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { metrics, trace, diag, DiagConsoleLogger } from '@opentelemetry/api';\nimport { logs } from '@opentelemetry/api-logs';\nimport type { Instrumentation } from '@opentelemetry/instrumentation';\nimport { registerInstrumentations } from '@opentelemetry/instrumentation';\nimport type {\n Resource,\n ResourceDetectionConfig,\n ResourceDetector,\n} from '@opentelemetry/resources';\nimport {\n defaultResource,\n detectResources,\n envDetector,\n hostDetector,\n processDetector,\n resourceFromAttributes,\n} from '@opentelemetry/resources';\nimport type {\n LogRecordProcessor,\n LogRecordExporter,\n} from '@opentelemetry/sdk-logs';\nimport {\n LoggerProvider,\n ConsoleLogRecordExporter,\n SimpleLogRecordProcessor,\n} from '@opentelemetry/sdk-logs';\nimport { OTLPLogExporter as OTLPHttpLogExporter } from '@opentelemetry/exporter-logs-otlp-http';\nimport { OTLPLogExporter as OTLPGrpcLogExporter } from '@opentelemetry/exporter-logs-otlp-grpc';\nimport { OTLPLogExporter as OTLPProtoLogExporter } from '@opentelemetry/exporter-logs-otlp-proto';\nimport { PrometheusExporter as PrometheusMetricExporter } from '@opentelemetry/exporter-prometheus';\nimport type { IMetricReader, ViewOptions } from '@opentelemetry/sdk-metrics';\nimport {\n MeterProvider,\n ConsoleMetricExporter,\n PeriodicExportingMetricReader,\n} from '@opentelemetry/sdk-metrics';\nimport type { SpanProcessor } from '@opentelemetry/sdk-trace';\nimport { TracerProvider } from '@opentelemetry/sdk-trace';\nimport { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';\nimport type { NodeSDKConfiguration } from './types';\nimport {\n getBooleanFromEnv,\n getStringFromEnv,\n getStringListFromEnv,\n diagLogLevelFromString,\n} from '@opentelemetry/core';\nimport {\n getResourceDetectorsFromEnv,\n getSpanProcessorsFromEnv,\n getPropagatorFromEnv,\n setupPropagator,\n setupContextManager,\n getPeriodicExportingMetricReaderFromEnv,\n getOtlpMetricExporterFromEnv,\n getBatchLogRecordProcessorFromEnv,\n getLoggerProviderConfigFromEnv,\n} from './utils';\nimport {\n createBatchSpanProcessorFromEnv,\n createSamplerFromEnv,\n createSpanLimitsFromEnv,\n} from './create-from-env';\n\nexport type MeterProviderConfig = {\n /**\n * Reference to the MetricReader instances by the NodeSDK\n */\n readers?: IMetricReader[];\n /**\n * List of {@link ViewOptions}s that should be passed to the MeterProvider\n */\n views?: ViewOptions[];\n};\n\nexport type LoggerProviderConfig = {\n /**\n * Reference to the LoggerRecordProcessor instance by the NodeSDK\n */\n logRecordProcessors: LogRecordProcessor[];\n};\n\n/**\n *\n * @returns MetricReader[] if appropriate environment variables are configured\n */\nfunction getMetricReadersFromEnv(): IMetricReader[] {\n const metricReaders: IMetricReader[] = [];\n const enabledExporters = Array.from(\n new Set(getStringListFromEnv('OTEL_METRICS_EXPORTER') ?? [])\n );\n\n if (enabledExporters.length === 0) {\n diag.debug('OTEL_METRICS_EXPORTER is empty. Using default otlp exporter.');\n enabledExporters.push('otlp');\n }\n\n if (enabledExporters.includes('none')) {\n diag.info(\n 'OTEL_METRICS_EXPORTER contains \"none\". Metric provider will not be initialized.'\n );\n return metricReaders;\n }\n\n enabledExporters.forEach(exporter => {\n if (exporter === 'otlp') {\n metricReaders.push(\n getPeriodicExportingMetricReaderFromEnv(getOtlpMetricExporterFromEnv())\n );\n } else if (exporter === 'console') {\n metricReaders.push(\n new PeriodicExportingMetricReader({\n exporter: new ConsoleMetricExporter(),\n })\n );\n } else if (exporter === 'prometheus') {\n metricReaders.push(new PrometheusMetricExporter());\n } else {\n diag.warn(\n `Unsupported OTEL_METRICS_EXPORTER value: \"${exporter}\". Supported values are: otlp, console, prometheus, none.`\n );\n }\n });\n\n return metricReaders;\n}\n\n/**\n * A setup helper for the OpenTelemetry SDKs (logs, metrics, traces).\n * <p> After successful setup using {@link NodeSDK#start()}, use `@opentelemetry/api` to obtain the registered components.\n * <p> Use the shutdown handler {@link NodeSDK#shutdown()} to ensure your telemetry is exported before the process exits.\n *\n * @example <caption> Register SDK by using environment variables </caption>\n * const nodeSdk = new NodeSDK(); // providing no options uses OTEL_* environment variables for SDK setup.\n * nodeSdk.start(); // registers all configured SDK components\n * @example <caption> Override environment variable config with your own components </caption>\n * const nodeSdk = new NodeSDK({\n * // override the list of metric reader with your own options and ignore environment variable config\n * // explore the docs of other options to learn more!\n * metricReaders: [ new PeriodicExportingMetricReader({\n * exporter: new OTLPMetricsExporter()\n * })]\n * });\n * nodeSdk.start(); // registers all configured SDK components\n */\nexport class NodeSDK {\n private _loggerProviderConfig?: LoggerProviderConfig;\n private _meterProviderConfig?: MeterProviderConfig;\n private _instrumentations: Instrumentation[];\n\n private _resource: Resource;\n private _resourceDetectors: Array<ResourceDetector>;\n\n private _autoDetectResources: boolean;\n\n private _tracerProvider?: TracerProvider;\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 if (getBooleanFromEnv('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 const logLevel = getStringFromEnv('OTEL_LOG_LEVEL');\n if (logLevel != null) {\n diag.setLogger(new DiagConsoleLogger(), {\n logLevel: diagLogLevelFromString(logLevel),\n });\n }\n\n this._configuration = configuration;\n\n this._resource = configuration.resource ?? defaultResource();\n this._autoDetectResources = configuration.autoDetectResources ?? true;\n if (!this._autoDetectResources) {\n this._resourceDetectors = [];\n } else if (configuration.resourceDetectors != null) {\n this._resourceDetectors = configuration.resourceDetectors;\n } else if (getStringFromEnv('OTEL_NODE_RESOURCE_DETECTORS')) {\n this._resourceDetectors = getResourceDetectorsFromEnv();\n } else {\n this._resourceDetectors = [envDetector, processDetector, hostDetector];\n }\n\n this._serviceName = configuration.serviceName;\n\n if (configuration.spanProcessor) {\n diag.warn(\n \"The 'spanProcessor' option is deprecated. Please use 'spanProcessors' instead.\"\n );\n }\n\n if (configuration.logRecordProcessors) {\n this._loggerProviderConfig = {\n logRecordProcessors: configuration.logRecordProcessors,\n };\n } else if (configuration.logRecordProcessor) {\n this._loggerProviderConfig = {\n logRecordProcessors: [configuration.logRecordProcessor],\n };\n diag.warn(\n \"The 'logRecordProcessor' option is deprecated. Please use 'logRecordProcessors' instead.\"\n );\n }\n\n if (configuration.metricReaders) {\n this._meterProviderConfig = {\n readers: configuration.metricReaders,\n views: configuration.views,\n };\n } else if (configuration.metricReader) {\n this._meterProviderConfig = {\n readers: [configuration.metricReader],\n views: configuration.views,\n };\n diag.warn(\n \"The 'metricReader' option is deprecated. Please use 'metricReaders' instead.\"\n );\n } else {\n this._meterProviderConfig = {\n readers: getMetricReadersFromEnv(),\n views: configuration.views,\n };\n }\n\n this._instrumentations = configuration.instrumentations?.flat() ?? [];\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 setupContextManager(this._configuration?.contextManager);\n setupPropagator(\n this._configuration?.textMapPropagator === null\n ? null // null means don't set, so we cannot fall back to env config.\n : (this._configuration?.textMapPropagator ?? getPropagatorFromEnv())\n );\n\n if (this._autoDetectResources) {\n const internalConfig: ResourceDetectionConfig = {\n detectors: this._resourceDetectors,\n };\n\n this._resource = this._resource.merge(detectResources(internalConfig));\n }\n\n this._resource =\n this._serviceName === undefined\n ? this._resource\n : this._resource.merge(\n resourceFromAttributes({\n [ATTR_SERVICE_NAME]: this._serviceName,\n })\n );\n\n // While SDK metrics are unstable, we require an opt-in.\n // https://opentelemetry.io/docs/specs/semconv/otel/sdk-metrics/\n const sdkMetricsEnabled = getBooleanFromEnv(\n 'OTEL_NODE_EXPERIMENTAL_SDK_METRICS'\n );\n\n if (\n this._meterProviderConfig?.readers &&\n // only register if there is a reader, otherwise we waste compute/memory.\n this._meterProviderConfig.readers.length > 0\n ) {\n const meterProvider = new MeterProvider({\n resource: this._resource,\n views: this._meterProviderConfig?.views ?? [],\n readers: this._meterProviderConfig.readers,\n sdkMetricsEnabled,\n });\n\n this._meterProvider = meterProvider;\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 this._instrumentations) {\n instrumentation.setMeterProvider(metrics.getMeterProvider());\n }\n }\n\n // Determine `spanProcessors` from multiple possible options.\n let spanProcessors: SpanProcessor[];\n if (this._configuration?.spanProcessors) {\n spanProcessors = this._configuration.spanProcessors;\n } else if (this._configuration?.spanProcessor) {\n spanProcessors = [this._configuration.spanProcessor];\n } else if (this._configuration?.traceExporter) {\n spanProcessors = [\n createBatchSpanProcessorFromEnv(\n this._configuration.traceExporter!,\n sdkMetricsEnabled ? this._meterProvider : undefined\n ),\n ];\n } else {\n spanProcessors = getSpanProcessorsFromEnv(\n sdkMetricsEnabled ? this._meterProvider : undefined\n );\n }\n\n // Only register if there is a span processor\n if (spanProcessors.length > 0) {\n this._tracerProvider = new TracerProvider({\n sampler: this._configuration?.sampler ?? createSamplerFromEnv(),\n spanLimits: {\n ...createSpanLimitsFromEnv(),\n ...this._configuration?.spanLimits,\n },\n resource: this._resource,\n meterProvider: sdkMetricsEnabled ? this._meterProvider : undefined,\n idGenerator: this._configuration?.idGenerator,\n spanProcessors,\n });\n trace.setGlobalTracerProvider(this._tracerProvider);\n }\n\n if (!this._loggerProviderConfig) {\n this.configureLoggerProviderFromEnv(\n sdkMetricsEnabled ? this._meterProvider : undefined\n );\n }\n\n if (this._loggerProviderConfig) {\n const loggerProvider = new LoggerProvider({\n ...getLoggerProviderConfigFromEnv(),\n resource: this._resource,\n processors: this._loggerProviderConfig.logRecordProcessors,\n meterProvider: sdkMetricsEnabled ? this._meterProvider : undefined,\n });\n\n this._loggerProvider = loggerProvider;\n\n logs.setGlobalLoggerProvider(loggerProvider);\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 private configureLoggerProviderFromEnv(\n meterProvider: MeterProvider | undefined\n ): void {\n const enabledExporters = Array.from(\n new Set(getStringListFromEnv('OTEL_LOGS_EXPORTER') ?? [])\n );\n\n if (enabledExporters.length === 0) {\n diag.debug('OTEL_LOGS_EXPORTER is empty. Using default otlp exporter.');\n enabledExporters.push('otlp');\n }\n\n if (enabledExporters.includes('none')) {\n diag.info(\n 'OTEL_LOGS_EXPORTER contains \"none\". Logger provider will not be initialized.'\n );\n return;\n }\n\n const exporters: LogRecordExporter[] = [];\n\n enabledExporters.forEach(exporter => {\n if (exporter === 'otlp') {\n const protocol =\n (\n getStringFromEnv('OTEL_EXPORTER_OTLP_LOGS_PROTOCOL') ??\n getStringFromEnv('OTEL_EXPORTER_OTLP_PROTOCOL')\n )?.trim() || 'http/protobuf'; // Using || to also fall back on empty string\n\n switch (protocol) {\n case 'grpc':\n exporters.push(new OTLPGrpcLogExporter());\n break;\n case 'http/json':\n exporters.push(new OTLPHttpLogExporter());\n break;\n case 'http/protobuf':\n exporters.push(new OTLPProtoLogExporter());\n break;\n default:\n diag.warn(\n `Unsupported OTLP logs protocol: \"${protocol}\". Using http/protobuf.`\n );\n exporters.push(new OTLPProtoLogExporter());\n }\n } else if (exporter === 'console') {\n exporters.push(new ConsoleLogRecordExporter());\n } else {\n diag.warn(\n `Unsupported OTEL_LOGS_EXPORTER value: \"${exporter}\". Supported values are: otlp, console, none.`\n );\n }\n });\n\n if (exporters.length > 0) {\n this._loggerProviderConfig = {\n logRecordProcessors: exporters.map(exporter => {\n if (exporter instanceof ConsoleLogRecordExporter) {\n return new SimpleLogRecordProcessor({\n exporter,\n selfObsMeterProvider: meterProvider,\n });\n } else {\n return getBatchLogRecordProcessorFromEnv(exporter, meterProvider);\n }\n }),\n };\n }\n }\n}\n"]}
@@ -1,62 +0,0 @@
1
- /**
2
- * Name of the host. On Unix systems, it may contain what the hostname command returns, or the fully qualified hostname, or another name specified by the user.
3
- *
4
- * @example opentelemetry-test
5
- *
6
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
7
- */
8
- export declare const ATTR_HOST_NAME: "host.name";
9
- /**
10
- * Process identifier (PID).
11
- *
12
- * @example 1234
13
- *
14
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
15
- */
16
- export declare const ATTR_PROCESS_PID: "process.pid";
17
- /**
18
- * The string ID of the service instance.
19
- *
20
- * @example 627cc493-f310-47de-96bd-71410b7dec09
21
- *
22
- * @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words
23
- * `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to
24
- * distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled
25
- * service).
26
- *
27
- * Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC
28
- * 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of
29
- * this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and
30
- * **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.
31
- *
32
- * UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is
33
- * needed. Similar to what can be seen in the man page for the
34
- * [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying
35
- * data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it
36
- * or not via another resource attribute.
37
- *
38
- * For applications running behind an application server (like unicorn), we do not recommend using one identifier
39
- * for all processes participating in the application. Instead, it's recommended each division (e.g. a worker
40
- * thread in unicorn) to have its own instance.id.
41
- *
42
- * It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the
43
- * service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will
44
- * likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.
45
- * However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance
46
- * for that telemetry. This is typically the case for scraping receivers, as they know the target address and
47
- * port.
48
- *
49
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
50
- */
51
- export declare const ATTR_SERVICE_INSTANCE_ID: "service.instance.id";
52
- /**
53
- * A namespace for `service.name`.
54
- *
55
- * @example Shop
56
- *
57
- * @note A string value having a meaning that helps to distinguish a group of services, for example the team name that owns a group of services. `service.name` is expected to be unique within the same namespace. If `service.namespace` is not specified in the Resource then `service.name` is expected to be unique for all services that have no explicit namespace defined (so the empty/unspecified namespace is simply one more valid namespace). Zero-length namespace string is assumed equal to unspecified namespace.
58
- *
59
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
60
- */
61
- export declare const ATTR_SERVICE_NAMESPACE: "service.namespace";
62
- //# sourceMappingURL=semconv.d.ts.map
@@ -1,74 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ATTR_SERVICE_NAMESPACE = exports.ATTR_SERVICE_INSTANCE_ID = exports.ATTR_PROCESS_PID = exports.ATTR_HOST_NAME = void 0;
8
- /*
9
- * This file contains a copy of unstable semantic convention definitions
10
- * used by this package.
11
- * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
12
- */
13
- /**
14
- * Name of the host. On Unix systems, it may contain what the hostname command returns, or the fully qualified hostname, or another name specified by the user.
15
- *
16
- * @example opentelemetry-test
17
- *
18
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
19
- */
20
- exports.ATTR_HOST_NAME = 'host.name';
21
- /**
22
- * Process identifier (PID).
23
- *
24
- * @example 1234
25
- *
26
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
27
- */
28
- exports.ATTR_PROCESS_PID = 'process.pid';
29
- /**
30
- * The string ID of the service instance.
31
- *
32
- * @example 627cc493-f310-47de-96bd-71410b7dec09
33
- *
34
- * @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words
35
- * `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to
36
- * distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled
37
- * service).
38
- *
39
- * Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC
40
- * 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of
41
- * this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and
42
- * **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.
43
- *
44
- * UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is
45
- * needed. Similar to what can be seen in the man page for the
46
- * [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying
47
- * data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it
48
- * or not via another resource attribute.
49
- *
50
- * For applications running behind an application server (like unicorn), we do not recommend using one identifier
51
- * for all processes participating in the application. Instead, it's recommended each division (e.g. a worker
52
- * thread in unicorn) to have its own instance.id.
53
- *
54
- * It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the
55
- * service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will
56
- * likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.
57
- * However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance
58
- * for that telemetry. This is typically the case for scraping receivers, as they know the target address and
59
- * port.
60
- *
61
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
62
- */
63
- exports.ATTR_SERVICE_INSTANCE_ID = 'service.instance.id';
64
- /**
65
- * A namespace for `service.name`.
66
- *
67
- * @example Shop
68
- *
69
- * @note A string value having a meaning that helps to distinguish a group of services, for example the team name that owns a group of services. `service.name` is expected to be unique within the same namespace. If `service.namespace` is not specified in the Resource then `service.name` is expected to be unique for all services that have no explicit namespace defined (so the empty/unspecified namespace is simply one more valid namespace). Zero-length namespace string is assumed equal to unspecified namespace.
70
- *
71
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
72
- */
73
- exports.ATTR_SERVICE_NAMESPACE = 'service.namespace';
74
- //# sourceMappingURL=semconv.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AACU,QAAA,cAAc,GAAG,WAAoB,CAAC;AAEnD;;;;;;GAMG;AACU,QAAA,gBAAgB,GAAG,aAAsB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACU,QAAA,wBAAwB,GAAG,qBAA8B,CAAC;AAEvE;;;;;;;;GAQG;AACU,QAAA,sBAAsB,GAAG,mBAA4B,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * Name of the host. On Unix systems, it may contain what the hostname command returns, or the fully qualified hostname, or another name specified by the user.\n *\n * @example opentelemetry-test\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_HOST_NAME = 'host.name' as const;\n\n/**\n * Process identifier (PID).\n *\n * @example 1234\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_PROCESS_PID = 'process.pid' as const;\n\n/**\n * The string ID of the service instance.\n *\n * @example 627cc493-f310-47de-96bd-71410b7dec09\n *\n * @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words\n * `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to\n * distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled\n * service).\n *\n * Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC\n * 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of\n * this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and\n * **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.\n *\n * UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is\n * needed. Similar to what can be seen in the man page for the\n * [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying\n * data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it\n * or not via another resource attribute.\n *\n * For applications running behind an application server (like unicorn), we do not recommend using one identifier\n * for all processes participating in the application. Instead, it's recommended each division (e.g. a worker\n * thread in unicorn) to have its own instance.id.\n *\n * It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the\n * service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will\n * likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.\n * However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance\n * for that telemetry. This is typically the case for scraping receivers, as they know the target address and\n * port.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_SERVICE_INSTANCE_ID = 'service.instance.id' as const;\n\n/**\n * A namespace for `service.name`.\n *\n * @example Shop\n *\n * @note A string value having a meaning that helps to distinguish a group of services, for example the team name that owns a group of services. `service.name` is expected to be unique within the same namespace. If `service.namespace` is not specified in the Resource then `service.name` is expected to be unique for all services that have no explicit namespace defined (so the empty/unspecified namespace is simply one more valid namespace). Zero-length namespace string is assumed equal to unspecified namespace.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_SERVICE_NAMESPACE = 'service.namespace' as const;\n"]}
@@ -1,12 +0,0 @@
1
- import type { SDKOptions } from './types';
2
- export declare const NOOP_SDK: {
3
- shutdown: () => Promise<void>;
4
- };
5
- /**
6
- * @experimental Function to start the OpenTelemetry Node SDK
7
- * @param sdkOptions
8
- */
9
- export declare function startNodeSDK(sdkOptions?: SDKOptions): {
10
- shutdown: () => Promise<void>;
11
- };
12
- //# sourceMappingURL=start.d.ts.map
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startNodeSDK = exports.NOOP_SDK = void 0;
4
- const configuration_1 = require("@opentelemetry/configuration");
5
- const api_1 = require("@opentelemetry/api");
6
- const instrumentation_1 = require("@opentelemetry/instrumentation");
7
- const api_logs_1 = require("@opentelemetry/api-logs");
8
- const context_async_hooks_1 = require("@opentelemetry/context-async-hooks");
9
- const diag_1 = require("./diag");
10
- const create_from_config_1 = require("./create-from-config");
11
- // Exported for testing.
12
- exports.NOOP_SDK = {
13
- shutdown: async () => { },
14
- };
15
- /**
16
- * @experimental Function to start the OpenTelemetry Node SDK
17
- * @param sdkOptions
18
- */
19
- function startNodeSDK(sdkOptions) {
20
- let config;
21
- try {
22
- const configFactory = (0, configuration_1.createConfigFactory)();
23
- config = configFactory.getConfigModel();
24
- }
25
- catch (configErr) {
26
- // Set the diag logger, otherwise the diag.error will typically not be shown.
27
- const logLevel = (0, diag_1.diagLogLevelFromSeverityNumberConfig)();
28
- api_1.diag.setLogger(new api_1.DiagConsoleLogger(), { logLevel });
29
- api_1.diag.error(`Could not load OpenTelemetry configuration, SDK will not be setup: ${configErr.message}`);
30
- return exports.NOOP_SDK;
31
- }
32
- if (config.disabled) {
33
- return exports.NOOP_SDK;
34
- }
35
- const logLevel = (0, diag_1.diagLogLevelFromSeverityNumberConfig)(config.log_level);
36
- api_1.diag.setLogger(new api_1.DiagConsoleLogger(), { logLevel });
37
- (0, instrumentation_1.registerInstrumentations)({
38
- instrumentations: sdkOptions?.instrumentations?.flat() ?? [],
39
- });
40
- let components;
41
- try {
42
- components = create(config, sdkOptions);
43
- }
44
- catch (createErr) {
45
- api_1.diag.error(`Could not create OpenTelemetry SDK from configuration, SDK will not be setup: ${createErr.message}`);
46
- return exports.NOOP_SDK;
47
- }
48
- if (components.contextManager) {
49
- api_1.context.setGlobalContextManager(components.contextManager);
50
- }
51
- if (components.loggerProvider) {
52
- api_logs_1.logs.setGlobalLoggerProvider(components.loggerProvider);
53
- }
54
- if (components.meterProvider) {
55
- api_1.metrics.setGlobalMeterProvider(components.meterProvider);
56
- }
57
- if (components.tracerProvider) {
58
- api_1.trace.setGlobalTracerProvider(components.tracerProvider);
59
- }
60
- if (components.propagator) {
61
- api_1.propagation.setGlobalPropagator(components.propagator);
62
- }
63
- const shutdownFn = async () => {
64
- const promises = [];
65
- if (components.loggerProvider) {
66
- promises.push(components.loggerProvider.shutdown());
67
- }
68
- if (components.meterProvider) {
69
- promises.push(components.meterProvider.shutdown());
70
- }
71
- if (components.tracerProvider) {
72
- promises.push(components.tracerProvider.shutdown());
73
- }
74
- await Promise.all(promises);
75
- };
76
- return { shutdown: shutdownFn };
77
- }
78
- exports.startNodeSDK = startNodeSDK;
79
- /**
80
- * Interpret configuration model and return SDK components.
81
- */
82
- function create(config, sdkOptions) {
83
- const components = {};
84
- try {
85
- components.contextManager = new context_async_hooks_1.AsyncLocalStorageContextManager();
86
- components.contextManager.enable();
87
- const resource = (0, create_from_config_1.createResourceFromConfig)(config.resource);
88
- if (sdkOptions?.textMapPropagator !== undefined) {
89
- if (sdkOptions.textMapPropagator !== null) {
90
- components.propagator = sdkOptions.textMapPropagator;
91
- }
92
- }
93
- else if (config.propagator) {
94
- components.propagator = (0, create_from_config_1.createPropagatorFromConfig)(config.propagator);
95
- }
96
- if (config.logger_provider) {
97
- components.loggerProvider = (0, create_from_config_1.createLoggerProviderFromConfig)(resource, config.logger_provider, config.attribute_limits);
98
- }
99
- if (config.meter_provider) {
100
- components.meterProvider = (0, create_from_config_1.createMeterProviderFromConfig)(resource, config.meter_provider);
101
- }
102
- if (config.tracer_provider) {
103
- components.tracerProvider = (0, create_from_config_1.createTracerProviderFromConfig)(resource, config.tracer_provider, config.attribute_limits);
104
- }
105
- return components;
106
- }
107
- catch (createErr) {
108
- // Clean up any SDK components that were created before the error.
109
- if (components.loggerProvider) {
110
- void components.loggerProvider.shutdown();
111
- }
112
- if (components.meterProvider) {
113
- void components.meterProvider.shutdown();
114
- }
115
- if (components.tracerProvider) {
116
- void components.tracerProvider.shutdown();
117
- }
118
- throw createErr;
119
- }
120
- }
121
- //# sourceMappingURL=start.js.map