@opentelemetry/sdk-node 0.212.0 → 0.214.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
@@ -146,6 +146,8 @@ If `resourceDetectors` was not set, you can also use the environment variable `O
146
146
  - **NOTE:** future versions of `@opentelemetry/sdk-node` may include additional detectors that will be covered by this scope.
147
147
  - `none` - disable resource detection
148
148
 
149
+ **NOTE:** `env` and `os` are Node.js-specific detectors with no equivalent in the [OpenTelemetry declarative configuration spec](https://github.com/open-telemetry/opentelemetry-configuration). They are supported when using the `detection/development` block in a declarative config file.
150
+
149
151
  For example, to enable only the `env`, `host` detectors:
150
152
 
151
153
  ```shell
@@ -228,6 +230,21 @@ Additionally, you can specify other applicable environment variables that apply
228
230
  - [OTLP exporter environment configuration](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options)
229
231
  - [Zipkin exporter environment configuration](https://github.com/open-telemetry/opentelemetry-specification/blob/6ce62202e5407518e19c56c445c13682ef51a51d/specification/sdk-environment-variables.md#zipkin-exporter)
230
232
 
233
+ ## Enable OpenTelemetry SDK internal metrics from environment
234
+
235
+ OpenTelemetry defines [metrics for monitoring SDK components](https://opentelemetry.io/docs/specs/semconv/otel/sdk-metrics/).
236
+ Until this spec is stabilized, the following environment variable must be used
237
+ to enable these metrics:
238
+
239
+ ```bash
240
+ OTEL_NODE_EXPERIMENTAL_SDK_METRICS=true
241
+ ```
242
+
243
+ Currently a subset of the specified metrics are implemented. See the following
244
+ linkes for details:
245
+
246
+ - Span metrics: [TracerMetrics.ts](../../../packages/opentelemetry-sdk-trace-base/src/TracerMetrics.ts)
247
+
231
248
  ## Useful links
232
249
 
233
250
  - For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
@@ -1,18 +1,7 @@
1
1
  "use strict";
2
2
  /*
3
3
  * Copyright The OpenTelemetry Authors
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * https://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
4
+ * SPDX-License-Identifier: Apache-2.0
16
5
  */
17
6
  Object.defineProperty(exports, "__esModule", { value: true });
18
7
  exports.startNodeSDK = exports.NodeSDK = exports.tracing = exports.resources = exports.node = exports.metrics = exports.logs = exports.core = exports.contextBase = exports.api = void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,2EAA2E;AAC3E,8EAA8E;AAC9E,2EAA2E;AAC3E,0CAA0C;AAE1C,yCAAyC;AACzC,4CAA0C;AAC1C,oDAAkD;AAClD,8CAA4C;AAC5C,kDAAgD;AAChD,wDAAsD;AACtD,wDAAsD;AACtD,wDAAsD;AACtD,2DAAyD;AACzD,wCAAwC;AAExC,6BAAgC;AAAvB,8FAAA,OAAO,OAAA;AAGhB,iCAAuC;AAA9B,qGAAA,YAAY,OAAA","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 a meta-package, and these exist in to re-export *all* items from\n// the individual packages as individual _namespaces_, so wildcard exports are\n// appropriate here. Otherwise, it'd be a pain to enumerate and keep things\n// in-sync with all the upstream packages.\n\n/* eslint-disable no-restricted-syntax */\nexport * as api from '@opentelemetry/api';\nexport * as contextBase from '@opentelemetry/api';\nexport * as core from '@opentelemetry/core';\nexport * as logs from '@opentelemetry/sdk-logs';\nexport * as metrics from '@opentelemetry/sdk-metrics';\nexport * as node from '@opentelemetry/sdk-trace-node';\nexport * as resources from '@opentelemetry/resources';\nexport * as tracing from '@opentelemetry/sdk-trace-base';\n/* eslint-enable no-restricted-syntax */\n\nexport { NodeSDK } from './sdk';\nexport type { LoggerProviderConfig, MeterProviderConfig } from './sdk';\nexport type { NodeSDKConfiguration } from './types';\nexport { startNodeSDK } from './start';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2EAA2E;AAC3E,8EAA8E;AAC9E,2EAA2E;AAC3E,0CAA0C;AAE1C,yCAAyC;AACzC,4CAA0C;AAC1C,oDAAkD;AAClD,8CAA4C;AAC5C,kDAAgD;AAChD,wDAAsD;AACtD,wDAAsD;AACtD,wDAAsD;AACtD,2DAAyD;AACzD,wCAAwC;AAExC,6BAAgC;AAAvB,8FAAA,OAAO,OAAA;AAGhB,iCAAuC;AAA9B,qGAAA,YAAY,OAAA","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// This is a meta-package, and these exist in to re-export *all* items from\n// the individual packages as individual _namespaces_, so wildcard exports are\n// appropriate here. Otherwise, it'd be a pain to enumerate and keep things\n// in-sync with all the upstream packages.\n\n/* eslint-disable no-restricted-syntax */\nexport * as api from '@opentelemetry/api';\nexport * as contextBase from '@opentelemetry/api';\nexport * as core from '@opentelemetry/core';\nexport * as logs from '@opentelemetry/sdk-logs';\nexport * as metrics from '@opentelemetry/sdk-metrics';\nexport * as node from '@opentelemetry/sdk-trace-node';\nexport * as resources from '@opentelemetry/resources';\nexport * as tracing from '@opentelemetry/sdk-trace-base';\n/* eslint-enable no-restricted-syntax */\n\nexport { NodeSDK } from './sdk';\nexport type { LoggerProviderConfig, MeterProviderConfig } from './sdk';\nexport type { NodeSDKConfiguration } from './types';\nexport { startNodeSDK } from './start';\n"]}
@@ -1,6 +1,6 @@
1
- import { LogRecordProcessor } from '@opentelemetry/sdk-logs';
2
- import { IMetricReader, ViewOptions } from '@opentelemetry/sdk-metrics';
3
- import { NodeSDKConfiguration } from './types';
1
+ import type { LogRecordProcessor } from '@opentelemetry/sdk-logs';
2
+ import type { IMetricReader, ViewOptions } from '@opentelemetry/sdk-metrics';
3
+ import type { NodeSDKConfiguration } from './types';
4
4
  export type MeterProviderConfig = {
5
5
  /**
6
6
  * Reference to the MetricReader instances by the NodeSDK
package/build/src/sdk.js CHANGED
@@ -1,18 +1,7 @@
1
1
  "use strict";
2
2
  /*
3
3
  * Copyright The OpenTelemetry Authors
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * https://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
4
+ * SPDX-License-Identifier: Apache-2.0
16
5
  */
17
6
  Object.defineProperty(exports, "__esModule", { value: true });
18
7
  exports.NodeSDK = void 0;
@@ -214,14 +203,35 @@ class NodeSDK {
214
203
  : this._resource.merge((0, resources_1.resourceFromAttributes)({
215
204
  [semantic_conventions_1.ATTR_SERVICE_NAME]: this._serviceName,
216
205
  }));
206
+ if (this._meterProviderConfig?.readers &&
207
+ // only register if there is a reader, otherwise we waste compute/memory.
208
+ this._meterProviderConfig.readers.length > 0) {
209
+ const meterProvider = new sdk_metrics_1.MeterProvider({
210
+ resource: this._resource,
211
+ views: this._meterProviderConfig?.views ?? [],
212
+ readers: this._meterProviderConfig.readers,
213
+ });
214
+ this._meterProvider = meterProvider;
215
+ api_1.metrics.setGlobalMeterProvider(meterProvider);
216
+ // TODO: This is a workaround to fix https://github.com/open-telemetry/opentelemetry-js/issues/3609
217
+ // If the MeterProvider is not yet registered when instrumentations are registered, all metrics are dropped.
218
+ // This code is obsolete once https://github.com/open-telemetry/opentelemetry-js/issues/3622 is implemented.
219
+ for (const instrumentation of this._instrumentations) {
220
+ instrumentation.setMeterProvider(api_1.metrics.getMeterProvider());
221
+ }
222
+ }
217
223
  const spanProcessors = this._tracerProviderConfig
218
224
  ? this._tracerProviderConfig.spanProcessors
219
225
  : (0, utils_1.getSpanProcessorsFromEnv)();
220
226
  // Only register if there is a span processor
221
227
  if (spanProcessors.length > 0) {
228
+ // While SDK metrics are unstable, we require an opt-in.
229
+ // https://opentelemetry.io/docs/specs/semconv/otel/sdk-metrics/
230
+ const sdkMetricsEnabled = (0, core_1.getBooleanFromEnv)('OTEL_NODE_EXPERIMENTAL_SDK_METRICS');
222
231
  this._tracerProvider = new sdk_trace_node_1.NodeTracerProvider({
223
232
  ...this._configuration,
224
233
  resource: this._resource,
234
+ meterProvider: sdkMetricsEnabled ? this._meterProvider : undefined,
225
235
  spanProcessors,
226
236
  });
227
237
  api_1.trace.setGlobalTracerProvider(this._tracerProvider);
@@ -235,23 +245,6 @@ class NodeSDK {
235
245
  this._loggerProvider = loggerProvider;
236
246
  api_logs_1.logs.setGlobalLoggerProvider(loggerProvider);
237
247
  }
238
- if (this._meterProviderConfig?.readers &&
239
- // only register if there is a reader, otherwise we waste compute/memory.
240
- this._meterProviderConfig.readers.length > 0) {
241
- const meterProvider = new sdk_metrics_1.MeterProvider({
242
- resource: this._resource,
243
- views: this._meterProviderConfig?.views ?? [],
244
- readers: this._meterProviderConfig.readers,
245
- });
246
- this._meterProvider = meterProvider;
247
- api_1.metrics.setGlobalMeterProvider(meterProvider);
248
- // TODO: This is a workaround to fix https://github.com/open-telemetry/opentelemetry-js/issues/3609
249
- // If the MeterProvider is not yet registered when instrumentations are registered, all metrics are dropped.
250
- // This code is obsolete once https://github.com/open-telemetry/opentelemetry-js/issues/3622 is implemented.
251
- for (const instrumentation of this._instrumentations) {
252
- instrumentation.setMeterProvider(api_1.metrics.getMeterProvider());
253
- }
254
- }
255
248
  }
256
249
  shutdown() {
257
250
  const promises = [];
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA6E;AAC7E,sDAA+C;AAC/C,oEAGwC;AACxC,wDAUkC;AAClC,sDAMiC;AACjC,oFAAgG;AAChG,oFAAgG;AAChG,sFAAkG;AAClG,4EAAoG;AACpG,4DAMoC;AACpC,kEAGuC;AACvC,kEAGuC;AACvC,8EAAwE;AAExE,8CAK6B;AAC7B,mCAUiB;AAyBjB;;;GAGG;AACH,SAAS,uBAAuB;IAC9B,MAAM,aAAa,GAAoB,EAAE,CAAC;IAC1C,MAAM,gBAAgB,GAAG,KAAK,CAAC,IAAI,CACjC,IAAI,GAAG,CAAC,IAAA,2BAAoB,EAAC,uBAAuB,CAAC,IAAI,EAAE,CAAC,CAC7D,CAAC;IAEF,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE;QACjC,UAAI,CAAC,KAAK,CAAC,8DAA8D,CAAC,CAAC;QAC3E,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KAC/B;IAED,IAAI,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACrC,UAAI,CAAC,IAAI,CACP,iFAAiF,CAClF,CAAC;QACF,OAAO,aAAa,CAAC;KACtB;IAED,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAClC,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,aAAa,CAAC,IAAI,CAChB,IAAA,+CAAuC,EAAC,IAAA,oCAA4B,GAAE,CAAC,CACxE,CAAC;SACH;aAAM,IAAI,QAAQ,KAAK,SAAS,EAAE;YACj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SAAS,CAAC,IAAI,CAAC,IAAI,0CAAoB,EAAE,CAAC,CAAC;wBAC3C,MAAM;oBACR;wBACE,UAAI,CAAC,IAAI,CACP,oCAAoC,QAAQ,yBAAyB,CACtE,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,QAAQ,CAAC,CAAC;qBAC/C;yBAAM;wBACL,OAAO,IAAA,yCAAiC,EAAC,QAAQ,CAAC,CAAC;qBACpD;gBACH,CAAC,CAAC;aACH,CAAC;SACH;IACH,CAAC;CACF;AAvSD,0BAuSC","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 { metrics, trace, diag, DiagConsoleLogger } from '@opentelemetry/api';\nimport { logs } from '@opentelemetry/api-logs';\nimport {\n Instrumentation,\n registerInstrumentations,\n} from '@opentelemetry/instrumentation';\nimport {\n defaultResource,\n detectResources,\n envDetector,\n hostDetector,\n Resource,\n processDetector,\n ResourceDetectionConfig,\n ResourceDetector,\n resourceFromAttributes,\n} from '@opentelemetry/resources';\nimport {\n LogRecordProcessor,\n LoggerProvider,\n ConsoleLogRecordExporter,\n LogRecordExporter,\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 {\n MeterProvider,\n IMetricReader,\n ViewOptions,\n ConsoleMetricExporter,\n PeriodicExportingMetricReader,\n} 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 { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';\nimport { 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';\n\ntype TracerProviderConfig = {\n tracerConfig: NodeTracerConfig;\n spanProcessors: SpanProcessor[];\n};\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 _tracerProviderConfig?: TracerProviderConfig;\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?: NodeTracerProvider;\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 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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n new BatchSpanProcessor(configuration.traceExporter!);\n\n const spanProcessors = configuration.spanProcessors ?? [spanProcessor];\n\n this._tracerProviderConfig = {\n tracerConfig: tracerProviderConfig,\n spanProcessors,\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 } else {\n this.configureLoggerProviderFromEnv();\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 const spanProcessors = this._tracerProviderConfig\n ? this._tracerProviderConfig.spanProcessors\n : getSpanProcessorsFromEnv();\n\n // Only register if there is a span processor\n if (spanProcessors.length > 0) {\n this._tracerProvider = new NodeTracerProvider({\n ...this._configuration,\n resource: this._resource,\n spanProcessors,\n });\n trace.setGlobalTracerProvider(this._tracerProvider);\n }\n\n if (this._loggerProviderConfig) {\n const loggerProvider = new LoggerProvider({\n ...getLoggerProviderConfigFromEnv(),\n resource: this._resource,\n processors: this._loggerProviderConfig.logRecordProcessors,\n });\n\n this._loggerProvider = loggerProvider;\n\n logs.setGlobalLoggerProvider(loggerProvider);\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 });\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\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(): 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(exporter);\n } else {\n return getBatchLogRecordProcessorFromEnv(exporter);\n }\n }),\n };\n }\n }\n}\n"]}
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,kEAAmE;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C,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,QAAQ,CAAC,CAAC;qBAC/C;yBAAM;wBACL,OAAO,IAAA,yCAAiC,EAAC,QAAQ,CAAC,CAAC;qBACpD;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-base';\nimport { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';\nimport type { NodeTracerConfig } from '@opentelemetry/sdk-trace-node';\nimport { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';\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';\n\ntype TracerProviderConfig = {\n tracerConfig: NodeTracerConfig;\n spanProcessors: SpanProcessor[];\n};\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 _tracerProviderConfig?: TracerProviderConfig;\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?: NodeTracerProvider;\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 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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n new BatchSpanProcessor(configuration.traceExporter!);\n\n const spanProcessors = configuration.spanProcessors ?? [spanProcessor];\n\n this._tracerProviderConfig = {\n tracerConfig: tracerProviderConfig,\n spanProcessors,\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 } else {\n this.configureLoggerProviderFromEnv();\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 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 });\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 const spanProcessors = this._tracerProviderConfig\n ? this._tracerProviderConfig.spanProcessors\n : getSpanProcessorsFromEnv();\n\n // Only register if there is a span processor\n if (spanProcessors.length > 0) {\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 this._tracerProvider = new NodeTracerProvider({\n ...this._configuration,\n resource: this._resource,\n meterProvider: sdkMetricsEnabled ? this._meterProvider : undefined,\n spanProcessors,\n });\n trace.setGlobalTracerProvider(this._tracerProvider);\n }\n\n if (this._loggerProviderConfig) {\n const loggerProvider = new LoggerProvider({\n ...getLoggerProviderConfigFromEnv(),\n resource: this._resource,\n processors: this._loggerProviderConfig.logRecordProcessors,\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(): 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(exporter);\n } else {\n return getBatchLogRecordProcessorFromEnv(exporter);\n }\n }),\n };\n }\n }\n}\n"]}
@@ -0,0 +1,62 @@
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
@@ -0,0 +1,74 @@
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
@@ -0,0 +1 @@
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,4 +1,6 @@
1
+ import type { ConfigurationModel } from '@opentelemetry/configuration';
1
2
  import type { SDKOptions } from './types';
3
+ import type { Resource } from '@opentelemetry/resources';
2
4
  /**
3
5
  * @experimental Function to start the OpenTelemetry Node SDK
4
6
  * @param sdkOptions
@@ -6,4 +8,5 @@ import type { SDKOptions } from './types';
6
8
  export declare function startNodeSDK(sdkOptions: SDKOptions): {
7
9
  shutdown: () => Promise<void>;
8
10
  };
11
+ export declare function setupResource(config: ConfigurationModel, sdkOptions: SDKOptions): Resource;
9
12
  //# sourceMappingURL=start.d.ts.map
@@ -1,25 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startNodeSDK = void 0;
4
- /*
5
- * Copyright The OpenTelemetry Authors
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * https://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
3
+ exports.setupResource = exports.startNodeSDK = void 0;
19
4
  const configuration_1 = require("@opentelemetry/configuration");
20
5
  const api_1 = require("@opentelemetry/api");
21
6
  const utils_1 = require("./utils");
22
7
  const instrumentation_1 = require("@opentelemetry/instrumentation");
8
+ const sdk_logs_1 = require("@opentelemetry/sdk-logs");
9
+ const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
10
+ const api_logs_1 = require("@opentelemetry/api-logs");
11
+ const resources_1 = require("@opentelemetry/resources");
12
+ const context_async_hooks_1 = require("@opentelemetry/context-async-hooks");
13
+ const semconv_1 = require("./semconv");
23
14
  /**
24
15
  * @experimental Function to start the OpenTelemetry Node SDK
25
16
  * @param sdkOptions
@@ -37,13 +28,25 @@ function startNodeSDK(sdkOptions) {
37
28
  (0, instrumentation_1.registerInstrumentations)({
38
29
  instrumentations: sdkOptions?.instrumentations?.flat() ?? [],
39
30
  });
40
- (0, utils_1.setupDefaultContextManager)();
41
- (0, utils_1.setupPropagator)(sdkOptions?.textMapPropagator === null
42
- ? null // null means don't set.
43
- : (sdkOptions?.textMapPropagator ??
44
- (0, utils_1.getPropagatorFromConfiguration)(config)));
31
+ const components = create(config, sdkOptions);
32
+ api_1.context.setGlobalContextManager(components.contextManager);
33
+ if (components.loggerProvider) {
34
+ api_logs_1.logs.setGlobalLoggerProvider(components.loggerProvider);
35
+ }
36
+ if (components.meterProvider) {
37
+ api_1.metrics.setGlobalMeterProvider(components.meterProvider);
38
+ }
39
+ if (components.propagator) {
40
+ api_1.propagation.setGlobalPropagator(components.propagator);
41
+ }
45
42
  const shutdownFn = async () => {
46
43
  const promises = [];
44
+ if (components.loggerProvider) {
45
+ promises.push(components.loggerProvider.shutdown());
46
+ }
47
+ if (components.meterProvider) {
48
+ promises.push(components.meterProvider.shutdown());
49
+ }
47
50
  await Promise.all(promises);
48
51
  };
49
52
  return { shutdown: shutdownFn };
@@ -52,4 +55,66 @@ exports.startNodeSDK = startNodeSDK;
52
55
  const NOOP_SDK = {
53
56
  shutdown: async () => { },
54
57
  };
58
+ /**
59
+ * Interpret configuration model and return SDK components.
60
+ */
61
+ function create(config, sdkOptions) {
62
+ const defaultContextManager = new context_async_hooks_1.AsyncLocalStorageContextManager();
63
+ defaultContextManager.enable();
64
+ const components = {
65
+ contextManager: defaultContextManager,
66
+ };
67
+ const resource = setupResource(config, sdkOptions);
68
+ const propagator = sdkOptions?.textMapPropagator === null
69
+ ? null
70
+ : (sdkOptions?.textMapPropagator ??
71
+ (0, utils_1.getPropagatorFromConfiguration)(config));
72
+ if (propagator) {
73
+ components.propagator = propagator;
74
+ }
75
+ const logProcessors = (0, utils_1.getLogRecordProcessorsFromConfiguration)(config);
76
+ if (logProcessors) {
77
+ const loggerProvider = new sdk_logs_1.LoggerProvider({
78
+ resource: resource,
79
+ processors: logProcessors,
80
+ });
81
+ components.loggerProvider = loggerProvider;
82
+ }
83
+ const meterReaders = (0, utils_1.getMeterReadersFromConfiguration)(config);
84
+ if (meterReaders) {
85
+ const meterViews = (0, utils_1.getMeterViewsFromConfiguration)(config);
86
+ const meterProvider = new sdk_metrics_1.MeterProvider({
87
+ resource: resource,
88
+ readers: meterReaders,
89
+ views: meterViews ?? [],
90
+ });
91
+ components.meterProvider = meterProvider;
92
+ }
93
+ return components;
94
+ }
95
+ function setupResource(config, sdkOptions) {
96
+ let resource = (0, utils_1.getResourceFromConfiguration)(config) ?? (0, resources_1.defaultResource)();
97
+ let resourceDetectors = [];
98
+ if (sdkOptions.resourceDetectors != null) {
99
+ resourceDetectors = sdkOptions.resourceDetectors;
100
+ }
101
+ else if (config.resource?.['detection/development']?.detectors) {
102
+ resourceDetectors = (0, utils_1.getResourceDetectorsFromConfiguration)(config);
103
+ }
104
+ if (resourceDetectors.length > 0) {
105
+ const internalConfig = {
106
+ detectors: resourceDetectors,
107
+ };
108
+ resource = resource.merge((0, resources_1.detectResources)(internalConfig));
109
+ }
110
+ const instanceId = (0, utils_1.getInstanceID)(config);
111
+ resource =
112
+ instanceId === undefined
113
+ ? resource
114
+ : resource.merge((0, resources_1.resourceFromAttributes)({
115
+ [semconv_1.ATTR_SERVICE_INSTANCE_ID]: instanceId,
116
+ }));
117
+ return resource;
118
+ }
119
+ exports.setupResource = setupResource;
55
120
  //# sourceMappingURL=start.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/start.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,gEAGsC;AACtC,4CAA6D;AAC7D,mCAIiB;AACjB,oEAA0E;AAG1E;;;GAGG;AACH,SAAgB,YAAY,CAAC,UAAsB;IAGjD,MAAM,aAAa,GAAkB,IAAA,mCAAmB,GAAE,CAAC;IAC3D,MAAM,MAAM,GAAG,aAAa,CAAC,cAAc,EAAE,CAAC;IAE9C,IAAI,MAAM,CAAC,QAAQ,EAAE;QACnB,UAAI,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QAC3C,OAAO,QAAQ,CAAC;KACjB;IACD,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI,EAAE;QAC5B,UAAI,CAAC,SAAS,CAAC,IAAI,uBAAiB,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;KACzE;IAED,IAAA,0CAAwB,EAAC;QACvB,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE;KAC7D,CAAC,CAAC;IACH,IAAA,kCAA0B,GAAE,CAAC;IAC7B,IAAA,uBAAe,EACb,UAAU,EAAE,iBAAiB,KAAK,IAAI;QACpC,CAAC,CAAC,IAAI,CAAC,wBAAwB;QAC/B,CAAC,CAAC,CAAC,UAAU,EAAE,iBAAiB;YAC5B,IAAA,sCAA8B,EAAC,MAAM,CAAC,CAAC,CAC9C,CAAC;IAEF,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;QAC5B,MAAM,QAAQ,GAAuB,EAAE,CAAC;QACxC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;AAClC,CAAC;AA9BD,oCA8BC;AACD,MAAM,QAAQ,GAAG;IACf,QAAQ,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;CACzB,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 */\nimport {\n ConfigFactory,\n createConfigFactory,\n} from '@opentelemetry/configuration';\nimport { diag, DiagConsoleLogger } from '@opentelemetry/api';\nimport {\n getPropagatorFromConfiguration,\n setupDefaultContextManager,\n setupPropagator,\n} from './utils';\nimport { registerInstrumentations } from '@opentelemetry/instrumentation';\nimport type { SDKOptions } from './types';\n\n/**\n * @experimental Function to start the OpenTelemetry Node SDK\n * @param sdkOptions\n */\nexport function startNodeSDK(sdkOptions: SDKOptions): {\n shutdown: () => Promise<void>;\n} {\n const configFactory: ConfigFactory = createConfigFactory();\n const config = configFactory.getConfigModel();\n\n if (config.disabled) {\n diag.info('OpenTelemetry SDK is disabled');\n return NOOP_SDK;\n }\n if (config.log_level != null) {\n diag.setLogger(new DiagConsoleLogger(), { logLevel: config.log_level });\n }\n\n registerInstrumentations({\n instrumentations: sdkOptions?.instrumentations?.flat() ?? [],\n });\n setupDefaultContextManager();\n setupPropagator(\n sdkOptions?.textMapPropagator === null\n ? null // null means don't set.\n : (sdkOptions?.textMapPropagator ??\n getPropagatorFromConfiguration(config))\n );\n\n const shutdownFn = async () => {\n const promises: Promise<unknown>[] = [];\n await Promise.all(promises);\n };\n return { shutdown: shutdownFn };\n}\nconst NOOP_SDK = {\n shutdown: async () => {},\n};\n"]}
1
+ {"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/start.ts"],"names":[],"mappings":";;;AAQA,gEAAmE;AACnE,4CAM4B;AAC5B,mCAQiB;AACjB,oEAA0E;AAE1E,sDAAyD;AACzD,4DAA2D;AAC3D,sDAA+C;AAM/C,wDAIkC;AAClC,4EAAqF;AACrF,uCAAqD;AAErD;;;GAGG;AACH,SAAgB,YAAY,CAAC,UAAsB;IAGjD,MAAM,aAAa,GAAkB,IAAA,mCAAmB,GAAE,CAAC;IAC3D,MAAM,MAAM,GAAG,aAAa,CAAC,cAAc,EAAE,CAAC;IAE9C,IAAI,MAAM,CAAC,QAAQ,EAAE;QACnB,UAAI,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QAC3C,OAAO,QAAQ,CAAC;KACjB;IACD,IA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MAA0B,EAC1B,UAAsB;IAEtB,IAAI,QAAQ,GACV,IAAA,oCAA4B,EAAC,MAAM,CAAC,IAAI,IAAA,2BAAe,GAAE,CAAC;IAC5D,IAAI,iBAAiB,GAAuB,EAAE,CAAC;IAE/C,IAAI,UAAU,CAAC,iBAAiB,IAAI,IAAI,EAAE;QACxC,iBAAiB,GAAG,UAAU,CAAC,iBAAiB,CAAC;KAClD;SAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,uBAAuB,CAAC,EAAE,SAAS,EAAE;QAChE,iBAAiB,GAAG,IAAA,6CAAqC,EAAC,MAAM,CAAC,CAAC;KACnE;IAED,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;QAChC,MAAM,cAAc,GAA4B;YAC9C,SAAS,EAAE,iBAAiB;SAC7B,CAAC;QACF,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAA,2BAAe,EAAC,cAAc,CAAC,CAAC,CAAC;KAC5D;IAED,MAAM,UAAU,GAAG,IAAA,qBAAa,EAAC,MAAM,CAAC,CAAC;IACzC,QAAQ;QACN,UAAU,KAAK,SAAS;YACtB,CAAC,CAAC,QAAQ;YACV,CAAC,CAAC,QAAQ,CAAC,KAAK,CACZ,IAAA,kCAAsB,EAAC;gBACrB,CAAC,kCAAwB,CAAC,EAAE,UAAU;aACvC,CAAC,CACH,CAAC;IAER,OAAO,QAAQ,CAAC;AAClB,CAAC;AAhCD,sCAgCC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type {\n ConfigFactory,\n ConfigurationModel,\n} from '@opentelemetry/configuration';\nimport { createConfigFactory } from '@opentelemetry/configuration';\nimport {\n context,\n diag,\n DiagConsoleLogger,\n metrics,\n propagation,\n} from '@opentelemetry/api';\nimport {\n getInstanceID,\n getLogRecordProcessorsFromConfiguration,\n getMeterReadersFromConfiguration,\n getMeterViewsFromConfiguration,\n getPropagatorFromConfiguration,\n getResourceDetectorsFromConfiguration,\n getResourceFromConfiguration,\n} from './utils';\nimport { registerInstrumentations } from '@opentelemetry/instrumentation';\nimport type { SDKComponents, SDKOptions } from './types';\nimport { LoggerProvider } from '@opentelemetry/sdk-logs';\nimport { MeterProvider } from '@opentelemetry/sdk-metrics';\nimport { logs } from '@opentelemetry/api-logs';\nimport type {\n Resource,\n ResourceDetectionConfig,\n ResourceDetector,\n} from '@opentelemetry/resources';\nimport {\n defaultResource,\n detectResources,\n resourceFromAttributes,\n} from '@opentelemetry/resources';\nimport { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';\nimport { ATTR_SERVICE_INSTANCE_ID } from './semconv';\n\n/**\n * @experimental Function to start the OpenTelemetry Node SDK\n * @param sdkOptions\n */\nexport function startNodeSDK(sdkOptions: SDKOptions): {\n shutdown: () => Promise<void>;\n} {\n const configFactory: ConfigFactory = createConfigFactory();\n const config = configFactory.getConfigModel();\n\n if (config.disabled) {\n diag.info('OpenTelemetry SDK is disabled');\n return NOOP_SDK;\n }\n if (config.log_level != null) {\n diag.setLogger(new DiagConsoleLogger(), { logLevel: config.log_level });\n }\n\n registerInstrumentations({\n instrumentations: sdkOptions?.instrumentations?.flat() ?? [],\n });\n\n const components = create(config, sdkOptions);\n context.setGlobalContextManager(components.contextManager);\n if (components.loggerProvider) {\n logs.setGlobalLoggerProvider(components.loggerProvider);\n }\n if (components.meterProvider) {\n metrics.setGlobalMeterProvider(components.meterProvider);\n }\n if (components.propagator) {\n propagation.setGlobalPropagator(components.propagator);\n }\n\n const shutdownFn = async () => {\n const promises: Promise<unknown>[] = [];\n if (components.loggerProvider) {\n promises.push(components.loggerProvider.shutdown());\n }\n if (components.meterProvider) {\n promises.push(components.meterProvider.shutdown());\n }\n await Promise.all(promises);\n };\n return { shutdown: shutdownFn };\n}\nconst NOOP_SDK = {\n shutdown: async () => {},\n};\n\n/**\n * Interpret configuration model and return SDK components.\n */\nfunction create(\n config: ConfigurationModel,\n sdkOptions: SDKOptions\n): SDKComponents {\n const defaultContextManager = new AsyncLocalStorageContextManager();\n defaultContextManager.enable();\n const components: SDKComponents = {\n contextManager: defaultContextManager,\n };\n const resource = setupResource(config, sdkOptions);\n\n const propagator =\n sdkOptions?.textMapPropagator === null\n ? null\n : (sdkOptions?.textMapPropagator ??\n getPropagatorFromConfiguration(config));\n if (propagator) {\n components.propagator = propagator;\n }\n\n const logProcessors = getLogRecordProcessorsFromConfiguration(config);\n if (logProcessors) {\n const loggerProvider = new LoggerProvider({\n resource: resource,\n processors: logProcessors,\n });\n components.loggerProvider = loggerProvider;\n }\n\n const meterReaders = getMeterReadersFromConfiguration(config);\n if (meterReaders) {\n const meterViews = getMeterViewsFromConfiguration(config);\n const meterProvider = new MeterProvider({\n resource: resource,\n readers: meterReaders,\n views: meterViews ?? [],\n });\n components.meterProvider = meterProvider;\n }\n\n return components;\n}\n\nexport function setupResource(\n config: ConfigurationModel,\n sdkOptions: SDKOptions\n): Resource {\n let resource: Resource =\n getResourceFromConfiguration(config) ?? defaultResource();\n let resourceDetectors: ResourceDetector[] = [];\n\n if (sdkOptions.resourceDetectors != null) {\n resourceDetectors = sdkOptions.resourceDetectors;\n } else if (config.resource?.['detection/development']?.detectors) {\n resourceDetectors = getResourceDetectorsFromConfiguration(config);\n }\n\n if (resourceDetectors.length > 0) {\n const internalConfig: ResourceDetectionConfig = {\n detectors: resourceDetectors,\n };\n resource = resource.merge(detectResources(internalConfig));\n }\n\n const instanceId = getInstanceID(config);\n resource =\n instanceId === undefined\n ? resource\n : resource.merge(\n resourceFromAttributes({\n [ATTR_SERVICE_INSTANCE_ID]: instanceId,\n })\n );\n\n return resource;\n}\n"]}