@opentelemetry/sdk-node 0.212.0 → 0.213.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
@@ -228,6 +228,21 @@ Additionally, you can specify other applicable environment variables that apply
228
228
  - [OTLP exporter environment configuration](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options)
229
229
  - [Zipkin exporter environment configuration](https://github.com/open-telemetry/opentelemetry-specification/blob/6ce62202e5407518e19c56c445c13682ef51a51d/specification/sdk-environment-variables.md#zipkin-exporter)
230
230
 
231
+ ## Enable OpenTelemetry SDK internal metrics from environment
232
+
233
+ OpenTelemetry defines [metrics for monitoring SDK components](https://opentelemetry.io/docs/specs/semconv/otel/sdk-metrics/).
234
+ Until this spec is stabilized, the following environment variable must be used
235
+ to enable these metrics:
236
+
237
+ ```bash
238
+ OTEL_NODE_EXPERIMENTAL_SDK_METRICS=true
239
+ ```
240
+
241
+ Currently a subset of the specified metrics are implemented. See the following
242
+ linkes for details:
243
+
244
+ - Span metrics: [TracerMetrics.ts](../../../packages/opentelemetry-sdk-trace-base/src/TracerMetrics.ts)
245
+
231
246
  ## Useful links
232
247
 
233
248
  - 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"]}
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,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AI,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;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,K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soleLogger } 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 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 { ConfigurationModel } from '@opentelemetry/configuration';
1
2
  import type { SDKOptions } from './types';
3
+ import { 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,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startNodeSDK = void 0;
3
+ exports.setupResource = exports.startNodeSDK = void 0;
4
4
  /*
5
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.
6
+ * SPDX-License-Identifier: Apache-2.0
18
7
  */
19
8
  const configuration_1 = require("@opentelemetry/configuration");
20
9
  const api_1 = require("@opentelemetry/api");
21
10
  const utils_1 = require("./utils");
22
11
  const instrumentation_1 = require("@opentelemetry/instrumentation");
12
+ const sdk_logs_1 = require("@opentelemetry/sdk-logs");
13
+ const api_logs_1 = require("@opentelemetry/api-logs");
14
+ const resources_1 = require("@opentelemetry/resources");
15
+ const context_async_hooks_1 = require("@opentelemetry/context-async-hooks");
16
+ const semconv_1 = require("./semconv");
23
17
  /**
24
18
  * @experimental Function to start the OpenTelemetry Node SDK
25
19
  * @param sdkOptions
@@ -37,13 +31,19 @@ function startNodeSDK(sdkOptions) {
37
31
  (0, instrumentation_1.registerInstrumentations)({
38
32
  instrumentations: sdkOptions?.instrumentations?.flat() ?? [],
39
33
  });
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)));
34
+ const components = create(config, sdkOptions);
35
+ api_1.context.setGlobalContextManager(components.contextManager);
36
+ if (components.loggerProvider) {
37
+ api_logs_1.logs.setGlobalLoggerProvider(components.loggerProvider);
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
47
  await Promise.all(promises);
48
48
  };
49
49
  return { shutdown: shutdownFn };
@@ -52,4 +52,56 @@ exports.startNodeSDK = startNodeSDK;
52
52
  const NOOP_SDK = {
53
53
  shutdown: async () => { },
54
54
  };
55
+ /**
56
+ * Interpret configuration model and return SDK components.
57
+ */
58
+ function create(config, sdkOptions) {
59
+ const defaultContextManager = new context_async_hooks_1.AsyncLocalStorageContextManager();
60
+ defaultContextManager.enable();
61
+ const components = {
62
+ contextManager: defaultContextManager,
63
+ };
64
+ const resource = setupResource(config, sdkOptions);
65
+ const propagator = sdkOptions?.textMapPropagator === null
66
+ ? null
67
+ : (sdkOptions?.textMapPropagator ??
68
+ (0, utils_1.getPropagatorFromConfiguration)(config));
69
+ if (propagator) {
70
+ components.propagator = propagator;
71
+ }
72
+ const logProcessors = (0, utils_1.getLogRecordProcessorsFromConfiguration)(config);
73
+ if (logProcessors) {
74
+ const loggerProvider = new sdk_logs_1.LoggerProvider({
75
+ resource: resource,
76
+ processors: logProcessors,
77
+ });
78
+ components.loggerProvider = loggerProvider;
79
+ }
80
+ return components;
81
+ }
82
+ function setupResource(config, sdkOptions) {
83
+ let resource = (0, utils_1.getResourceFromConfiguration)(config) ?? (0, resources_1.defaultResource)();
84
+ let resourceDetectors = [];
85
+ if (sdkOptions.resourceDetectors != null) {
86
+ resourceDetectors = sdkOptions.resourceDetectors;
87
+ }
88
+ else if (config.node_resource_detectors) {
89
+ resourceDetectors = (0, utils_1.getResourceDetectorsFromConfiguration)(config);
90
+ }
91
+ if (resourceDetectors.length > 0) {
92
+ const internalConfig = {
93
+ detectors: resourceDetectors,
94
+ };
95
+ resource = resource.merge((0, resources_1.detectResources)(internalConfig));
96
+ }
97
+ const instanceId = (0, utils_1.getInstanceID)(config);
98
+ resource =
99
+ instanceId === undefined
100
+ ? resource
101
+ : resource.merge((0, resources_1.resourceFromAttributes)({
102
+ [semconv_1.ATTR_SERVICE_INSTANCE_ID]: instanceId,
103
+ }));
104
+ return resource;
105
+ }
106
+ exports.setupResource = setupResource;
55
107
  //# 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":";;;AAAA;;;GAGG;AACH,gEAIsC;AACtC,4CAK4B;AAC5B,mCAMiB;AACjB,oEAA0E;AAE1E,sDAAyD;AACzD,sDAA+C;AAC/C,wDAOkC;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,U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,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 {\n ConfigFactory,\n ConfigurationModel,\n createConfigFactory,\n} from '@opentelemetry/configuration';\nimport {\n context,\n diag,\n DiagConsoleLogger,\n propagation,\n} from '@opentelemetry/api';\nimport {\n getInstanceID,\n getLogRecordProcessorsFromConfiguration,\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 { logs } from '@opentelemetry/api-logs';\nimport {\n defaultResource,\n detectResources,\n Resource,\n ResourceDetectionConfig,\n ResourceDetector,\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.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 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 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.node_resource_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"]}
@@ -2,7 +2,7 @@ import type { ContextManager } from '@opentelemetry/api';
2
2
  import { TextMapPropagator } from '@opentelemetry/api';
3
3
  import { Instrumentation } from '@opentelemetry/instrumentation';
4
4
  import { Resource, ResourceDetector } from '@opentelemetry/resources';
5
- import { LogRecordProcessor } from '@opentelemetry/sdk-logs';
5
+ import { LoggerProvider, LogRecordProcessor } from '@opentelemetry/sdk-logs';
6
6
  import { IMetricReader, ViewOptions } from '@opentelemetry/sdk-metrics';
7
7
  import { Sampler, SpanExporter, SpanLimits, SpanProcessor, IdGenerator } from '@opentelemetry/sdk-trace-base';
8
8
  export interface NodeSDKConfiguration {
@@ -33,6 +33,12 @@ export interface NodeSDKConfiguration {
33
33
  */
34
34
  export interface SDKOptions {
35
35
  instrumentations?: (Instrumentation | Instrumentation[])[];
36
+ resourceDetectors?: ResourceDetector[];
36
37
  textMapPropagator?: TextMapPropagator | null;
37
38
  }
39
+ export interface SDKComponents {
40
+ contextManager: ContextManager;
41
+ loggerProvider?: LoggerProvider;
42
+ propagator?: TextMapPropagator;
43
+ }
38
44
  //# sourceMappingURL=types.d.ts.map
@@ -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
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ContextManager } from '@opentelemetry/api';\nimport { TextMapPropagator } from '@opentelemetry/api';\nimport { Instrumentation } from '@opentelemetry/instrumentation';\nimport { Resource, ResourceDetector } from '@opentelemetry/resources';\nimport { LogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { IMetricReader, ViewOptions } from '@opentelemetry/sdk-metrics';\nimport {\n Sampler,\n SpanExporter,\n SpanLimits,\n SpanProcessor,\n IdGenerator,\n} from '@opentelemetry/sdk-trace-base';\n\nexport interface NodeSDKConfiguration {\n autoDetectResources: boolean;\n contextManager: ContextManager;\n textMapPropagator: TextMapPropagator | null;\n /** @deprecated use logRecordProcessors instead*/\n logRecordProcessor: LogRecordProcessor;\n logRecordProcessors?: LogRecordProcessor[];\n /** @deprecated use metricReaders instead*/\n metricReader: IMetricReader;\n metricReaders?: IMetricReader[];\n views: ViewOptions[];\n instrumentations: (Instrumentation | Instrumentation[])[];\n resource: Resource;\n resourceDetectors: Array<ResourceDetector>;\n sampler: Sampler;\n serviceName?: string;\n /** @deprecated use spanProcessors instead*/\n spanProcessor?: SpanProcessor;\n spanProcessors?: SpanProcessor[];\n traceExporter: SpanExporter;\n spanLimits: SpanLimits;\n idGenerator: IdGenerator;\n}\n/**\n * @experimental Options for new experimental SDK setup\n */\nexport interface SDKOptions {\n instrumentations?: (Instrumentation | Instrumentation[])[];\n textMapPropagator?: TextMapPropagator | null;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ContextManager } from '@opentelemetry/api';\nimport { TextMapPropagator } from '@opentelemetry/api';\nimport { Instrumentation } from '@opentelemetry/instrumentation';\nimport { Resource, ResourceDetector } from '@opentelemetry/resources';\nimport { LoggerProvider, LogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { IMetricReader, ViewOptions } from '@opentelemetry/sdk-metrics';\nimport {\n Sampler,\n SpanExporter,\n SpanLimits,\n SpanProcessor,\n IdGenerator,\n} from '@opentelemetry/sdk-trace-base';\n\nexport interface NodeSDKConfiguration {\n autoDetectResources: boolean;\n contextManager: ContextManager;\n textMapPropagator: TextMapPropagator | null;\n /** @deprecated use logRecordProcessors instead*/\n logRecordProcessor: LogRecordProcessor;\n logRecordProcessors?: LogRecordProcessor[];\n /** @deprecated use metricReaders instead*/\n metricReader: IMetricReader;\n metricReaders?: IMetricReader[];\n views: ViewOptions[];\n instrumentations: (Instrumentation | Instrumentation[])[];\n resource: Resource;\n resourceDetectors: Array<ResourceDetector>;\n sampler: Sampler;\n serviceName?: string;\n /** @deprecated use spanProcessors instead*/\n spanProcessor?: SpanProcessor;\n spanProcessors?: SpanProcessor[];\n traceExporter: SpanExporter;\n spanLimits: SpanLimits;\n idGenerator: IdGenerator;\n}\n/**\n * @experimental Options for new experimental SDK setup\n */\nexport interface SDKOptions {\n instrumentations?: (Instrumentation | Instrumentation[])[];\n resourceDetectors?: ResourceDetector[];\n textMapPropagator?: TextMapPropagator | null;\n}\n\nexport interface SDKComponents {\n contextManager: ContextManager;\n loggerProvider?: LoggerProvider;\n propagator?: TextMapPropagator;\n}\n"]}
@@ -1,10 +1,12 @@
1
1
  import { ContextManager, TextMapPropagator } from '@opentelemetry/api';
2
- import { ResourceDetector } from '@opentelemetry/resources';
2
+ import { Resource, ResourceDetector } from '@opentelemetry/resources';
3
3
  import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
4
- import { ConfigurationModel } from '@opentelemetry/configuration';
4
+ import { ConfigurationModel, LogRecordExporterModel } from '@opentelemetry/configuration';
5
5
  import { IMetricReader, PushMetricExporter } from '@opentelemetry/sdk-metrics';
6
- import { BatchLogRecordProcessor, BufferConfig, LogRecordExporter, LoggerProviderConfig } from '@opentelemetry/sdk-logs';
6
+ import { BatchLogRecordProcessor, BufferConfig, LogRecordExporter, LoggerProviderConfig, LogRecordProcessor } from '@opentelemetry/sdk-logs';
7
+ export declare function getResourceFromConfiguration(config: ConfigurationModel): Resource | undefined;
7
8
  export declare function getResourceDetectorsFromEnv(): Array<ResourceDetector>;
9
+ export declare function getResourceDetectorsFromConfiguration(config: ConfigurationModel): Array<ResourceDetector>;
8
10
  export declare function getOtlpProtocolFromEnv(): string;
9
11
  export declare function getSpanProcessorsFromEnv(): SpanProcessor[];
10
12
  /**
@@ -16,7 +18,6 @@ export declare function getPropagatorFromEnv(): TextMapPropagator | null | undef
16
18
  */
17
19
  export declare function getPropagatorFromConfiguration(config: ConfigurationModel): TextMapPropagator | null | undefined;
18
20
  export declare function setupContextManager(contextManager: ContextManager | null | undefined): void;
19
- export declare function setupDefaultContextManager(): void;
20
21
  export declare function setupPropagator(propagator: TextMapPropagator | null | undefined): void;
21
22
  export declare function getKeyListFromObjectArray(obj: object[] | undefined): string[] | undefined;
22
23
  export declare function getNonNegativeNumberFromEnv(envVarName: string): number | undefined;
@@ -31,4 +32,7 @@ export declare function getLoggerProviderConfigFromEnv(): LoggerProviderConfig;
31
32
  */
32
33
  export declare function getBatchLogRecordProcessorConfigFromEnv(): BufferConfig;
33
34
  export declare function getBatchLogRecordProcessorFromEnv(exporter: LogRecordExporter): BatchLogRecordProcessor;
35
+ export declare function getLogRecordExporter(exporter: LogRecordExporterModel): LogRecordExporter | undefined;
36
+ export declare function getLogRecordProcessorsFromConfiguration(config: ConfigurationModel): LogRecordProcessor[] | undefined;
37
+ export declare function getInstanceID(config: ConfigurationModel): string | undefined;
34
38
  //# sourceMappingURL=utils.d.ts.map
@@ -1,21 +1,10 @@
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
- exports.getBatchLogRecordProcessorFromEnv = exports.getBatchLogRecordProcessorConfigFromEnv = exports.getLoggerProviderConfigFromEnv = exports.getOtlpMetricExporterFromEnv = exports.getPeriodicExportingMetricReaderFromEnv = exports.getNonNegativeNumberFromEnv = exports.getKeyListFromObjectArray = exports.setupPropagator = exports.setupDefaultContextManager = exports.setupContextManager = exports.getPropagatorFromConfiguration = exports.getPropagatorFromEnv = exports.getSpanProcessorsFromEnv = exports.getOtlpProtocolFromEnv = exports.getResourceDetectorsFromEnv = void 0;
7
+ exports.getInstanceID = exports.getLogRecordProcessorsFromConfiguration = exports.getLogRecordExporter = exports.getBatchLogRecordProcessorFromEnv = exports.getBatchLogRecordProcessorConfigFromEnv = exports.getLoggerProviderConfigFromEnv = exports.getOtlpMetricExporterFromEnv = exports.getPeriodicExportingMetricReaderFromEnv = exports.getNonNegativeNumberFromEnv = exports.getKeyListFromObjectArray = exports.setupPropagator = exports.setupContextManager = exports.getPropagatorFromConfiguration = exports.getPropagatorFromEnv = exports.getSpanProcessorsFromEnv = exports.getOtlpProtocolFromEnv = exports.getResourceDetectorsFromConfiguration = exports.getResourceDetectorsFromEnv = exports.getResourceFromConfiguration = void 0;
19
8
  const api_1 = require("@opentelemetry/api");
20
9
  const core_1 = require("@opentelemetry/core");
21
10
  const exporter_trace_otlp_proto_1 = require("@opentelemetry/exporter-trace-otlp-proto");
@@ -27,6 +16,10 @@ const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
27
16
  const propagator_b3_1 = require("@opentelemetry/propagator-b3");
28
17
  const propagator_jaeger_1 = require("@opentelemetry/propagator-jaeger");
29
18
  const context_async_hooks_1 = require("@opentelemetry/context-async-hooks");
19
+ const exporter_logs_otlp_http_1 = require("@opentelemetry/exporter-logs-otlp-http");
20
+ const exporter_logs_otlp_grpc_1 = require("@opentelemetry/exporter-logs-otlp-grpc");
21
+ const exporter_logs_otlp_proto_1 = require("@opentelemetry/exporter-logs-otlp-proto");
22
+ const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
30
23
  const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
31
24
  const exporter_metrics_otlp_grpc_1 = require("@opentelemetry/exporter-metrics-otlp-grpc");
32
25
  const exporter_metrics_otlp_http_1 = require("@opentelemetry/exporter-metrics-otlp-http");
@@ -37,6 +30,20 @@ const RESOURCE_DETECTOR_HOST = 'host';
37
30
  const RESOURCE_DETECTOR_OS = 'os';
38
31
  const RESOURCE_DETECTOR_PROCESS = 'process';
39
32
  const RESOURCE_DETECTOR_SERVICE_INSTANCE_ID = 'serviceinstance';
33
+ function getResourceFromConfiguration(config) {
34
+ if (config.resource && config.resource.attributes) {
35
+ const attr = {};
36
+ for (let i = 0; i < config.resource.attributes.length; i++) {
37
+ const a = config.resource.attributes[i];
38
+ attr[a.name] = a.value;
39
+ }
40
+ return (0, resources_1.resourceFromAttributes)(attr, {
41
+ schemaUrl: config.resource.schema_url,
42
+ });
43
+ }
44
+ return undefined;
45
+ }
46
+ exports.getResourceFromConfiguration = getResourceFromConfiguration;
40
47
  function getResourceDetectorsFromEnv() {
41
48
  // When updating this list, make sure to also update the section `resourceDetectors` on README.
42
49
  const resourceDetectors = new Map([
@@ -62,6 +69,31 @@ function getResourceDetectorsFromEnv() {
62
69
  });
63
70
  }
64
71
  exports.getResourceDetectorsFromEnv = getResourceDetectorsFromEnv;
72
+ function getResourceDetectorsFromConfiguration(config) {
73
+ // When updating this list, make sure to also update the section `resourceDetectors` on README.
74
+ const resourceDetectors = new Map([
75
+ [RESOURCE_DETECTOR_HOST, resources_1.hostDetector],
76
+ [RESOURCE_DETECTOR_OS, resources_1.osDetector],
77
+ [RESOURCE_DETECTOR_SERVICE_INSTANCE_ID, resources_1.serviceInstanceIdDetector],
78
+ [RESOURCE_DETECTOR_PROCESS, resources_1.processDetector],
79
+ [RESOURCE_DETECTOR_ENVIRONMENT, resources_1.envDetector],
80
+ ]);
81
+ const resourceDetectorsFromConfig = config.node_resource_detectors ?? [];
82
+ if (resourceDetectorsFromConfig.includes('all')) {
83
+ return [...resourceDetectors.values()].flat();
84
+ }
85
+ if (resourceDetectorsFromConfig.includes('none')) {
86
+ return [];
87
+ }
88
+ return resourceDetectorsFromConfig.flatMap(detector => {
89
+ const resourceDetector = resourceDetectors.get(detector);
90
+ if (!resourceDetector) {
91
+ api_1.diag.warn(`Invalid resource detector "${detector}" specified`);
92
+ }
93
+ return resourceDetector || [];
94
+ });
95
+ }
96
+ exports.getResourceDetectorsFromConfiguration = getResourceDetectorsFromConfiguration;
65
97
  function getOtlpProtocolFromEnv() {
66
98
  return ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_PROTOCOL') ??
67
99
  (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_PROTOCOL') ??
@@ -242,12 +274,6 @@ function setupContextManager(contextManager) {
242
274
  api_1.context.setGlobalContextManager(contextManager);
243
275
  }
244
276
  exports.setupContextManager = setupContextManager;
245
- function setupDefaultContextManager() {
246
- const defaultContextManager = new context_async_hooks_1.AsyncLocalStorageContextManager();
247
- defaultContextManager.enable();
248
- api_1.context.setGlobalContextManager(defaultContextManager);
249
- }
250
- exports.setupDefaultContextManager = setupDefaultContextManager;
251
277
  function setupPropagator(propagator) {
252
278
  // null means 'do not register'
253
279
  if (propagator === null) {
@@ -363,4 +389,81 @@ function getBatchLogRecordProcessorFromEnv(exporter) {
363
389
  return new sdk_logs_1.BatchLogRecordProcessor(exporter, getBatchLogRecordProcessorConfigFromEnv());
364
390
  }
365
391
  exports.getBatchLogRecordProcessorFromEnv = getBatchLogRecordProcessorFromEnv;
392
+ function getLogRecordExporter(exporter) {
393
+ if (exporter.otlp_http) {
394
+ const encoding = exporter.otlp_http.encoding;
395
+ if (encoding === 'json') {
396
+ return new exporter_logs_otlp_http_1.OTLPLogExporter({
397
+ compression: exporter.otlp_http.compression === 'gzip'
398
+ ? otlp_exporter_base_1.CompressionAlgorithm.GZIP
399
+ : otlp_exporter_base_1.CompressionAlgorithm.NONE,
400
+ });
401
+ }
402
+ if (encoding === 'protobuf') {
403
+ return new exporter_logs_otlp_proto_1.OTLPLogExporter({
404
+ compression: exporter.otlp_http.compression === 'gzip'
405
+ ? otlp_exporter_base_1.CompressionAlgorithm.GZIP
406
+ : otlp_exporter_base_1.CompressionAlgorithm.NONE,
407
+ });
408
+ }
409
+ api_1.diag.warn(`Unsupported OTLP logs encoding: ${encoding}. Using http/protobuf.`);
410
+ return new exporter_logs_otlp_proto_1.OTLPLogExporter({
411
+ compression: exporter.otlp_http.compression === 'gzip'
412
+ ? otlp_exporter_base_1.CompressionAlgorithm.GZIP
413
+ : otlp_exporter_base_1.CompressionAlgorithm.NONE,
414
+ });
415
+ }
416
+ else if (exporter.otlp_grpc) {
417
+ return new exporter_logs_otlp_grpc_1.OTLPLogExporter({
418
+ compression: exporter.otlp_grpc.compression === 'gzip'
419
+ ? otlp_exporter_base_1.CompressionAlgorithm.GZIP
420
+ : otlp_exporter_base_1.CompressionAlgorithm.NONE,
421
+ });
422
+ }
423
+ else if (exporter.console) {
424
+ return new sdk_logs_1.ConsoleLogRecordExporter();
425
+ }
426
+ api_1.diag.warn(`Unsupported Exporter value. No Log Record Exporter registered`);
427
+ return undefined;
428
+ }
429
+ exports.getLogRecordExporter = getLogRecordExporter;
430
+ function getLogRecordProcessorsFromConfiguration(config) {
431
+ const logRecordProcessors = [];
432
+ config.logger_provider?.processors?.forEach(processor => {
433
+ if (processor.batch) {
434
+ const exporter = getLogRecordExporter(processor.batch.exporter);
435
+ if (exporter) {
436
+ logRecordProcessors.push(new sdk_logs_1.BatchLogRecordProcessor(exporter, {
437
+ maxQueueSize: processor.batch.max_queue_size,
438
+ maxExportBatchSize: processor.batch.max_export_batch_size,
439
+ scheduledDelayMillis: processor.batch.schedule_delay,
440
+ exportTimeoutMillis: processor.batch.export_timeout,
441
+ }));
442
+ }
443
+ }
444
+ if (processor.simple) {
445
+ const exporter = getLogRecordExporter(processor.simple.exporter);
446
+ if (exporter) {
447
+ logRecordProcessors.push(new sdk_logs_1.SimpleLogRecordProcessor(exporter));
448
+ }
449
+ }
450
+ });
451
+ if (logRecordProcessors.length > 0) {
452
+ return logRecordProcessors;
453
+ }
454
+ return undefined;
455
+ }
456
+ exports.getLogRecordProcessorsFromConfiguration = getLogRecordProcessorsFromConfiguration;
457
+ function getInstanceID(config) {
458
+ if (config.resource?.attributes) {
459
+ for (let i = 0; i < config.resource.attributes.length; i++) {
460
+ const element = config.resource.attributes[i];
461
+ if (element.name === 'service.instance.id') {
462
+ return element.value?.toString();
463
+ }
464
+ }
465
+ }
466
+ return undefined;
467
+ }
468
+ exports.getInstanceID = getInstanceID;
366
469
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAM4B;AAC5B,8CAO6B;AAC7B,wFAAuG;AACvG,sFAAqG;AACrG,sFAAqG;AACrG,oEAAgE;AAChE,wDAOkC;AAClC,kEAMuC;AACvC,gEAA8E;AA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AAuB,EAAE,CAAC;KACxC;IAED,UAAI,CAAC,IAAI,CACP,uCAAuC,QAAQ,yBAAyB,CACzE,CAAC;IACF,OAAO,IAAI,gDAAuB,EAAE,CAAC;AACvC,CAAC;AApBD,oEAoBC;AAED;;GAEG;AACH,SAAgB,8BAA8B;IAC5C,OAAO;QACL,eAAe,EAAE;YACf,mBAAmB,EACjB,2BAA2B,CAAC,sCAAsC,CAAC;gBACnE,2BAA2B,CAAC,4BAA4B,CAAC;YAC3D,yBAAyB,EACvB,2BAA2B,CACzB,6CAA6C,CAC9C,IAAI,2BAA2B,CAAC,mCAAmC,CAAC;SACxE;KACF,CAAC;AACJ,CAAC;AAZD,wEAYC;AAED;;GAEG;AACH,SAAgB,uCAAuC;IACrD,OAAO;QACL,YAAY,EAAE,2BAA2B,CAAC,0BAA0B,CAAC;QACrE,oBAAoB,EAAE,2BAA2B,CAC/C,0BAA0B,CAC3B;QACD,mBAAmB,EAAE,2BAA2B,CAC9C,0BAA0B,CAC3B;QACD,kBAAkB,EAAE,2BAA2B,CAC7C,iCAAiC,CAClC;KACF,CAAC;AACJ,CAAC;AAbD,0FAaC;AAED,SAAgB,iCAAiC,CAC/C,QAA2B;IAE3B,OAAO,IAAI,kCAAuB,CAChC,QAAQ,EACR,uCAAuC,EAAE,CAC1C,CAAC;AACJ,CAAC;AAPD,8EAOC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n context,\n ContextManager,\n diag,\n propagation,\n TextMapPropagator,\n} from '@opentelemetry/api';\nimport {\n CompositePropagator,\n getNumberFromEnv,\n getStringFromEnv,\n getStringListFromEnv,\n W3CBaggagePropagator,\n W3CTraceContextPropagator,\n} from '@opentelemetry/core';\nimport { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';\nimport { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\nimport { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';\nimport { ZipkinExporter } from '@opentelemetry/exporter-zipkin';\nimport {\n envDetector,\n hostDetector,\n osDetector,\n processDetector,\n ResourceDetector,\n serviceInstanceIdDetector,\n} from '@opentelemetry/resources';\nimport {\n BatchSpanProcessor,\n ConsoleSpanExporter,\n SimpleSpanProcessor,\n SpanExporter,\n SpanProcessor,\n} from '@opentelemetry/sdk-trace-base';\nimport { B3InjectEncoding, B3Propagator } from '@opentelemetry/propagator-b3';\nimport { JaegerPropagator } from '@opentelemetry/propagator-jaeger';\nimport { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';\nimport { ConfigurationModel } from '@opentelemetry/configuration';\nimport {\n IMetricReader,\n PeriodicExportingMetricReader,\n PushMetricExporter,\n} from '@opentelemetry/sdk-metrics';\nimport { OTLPMetricExporter as OTLPGrpcMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';\nimport { OTLPMetricExporter as OTLPHttpMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';\nimport { OTLPMetricExporter as OTLPProtoMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto';\nimport {\n BatchLogRecordProcessor,\n BufferConfig,\n LogRecordExporter,\n LoggerProviderConfig,\n} from '@opentelemetry/sdk-logs';\n\nconst RESOURCE_DETECTOR_ENVIRONMENT = 'env';\nconst RESOURCE_DETECTOR_HOST = 'host';\nconst RESOURCE_DETECTOR_OS = 'os';\nconst RESOURCE_DETECTOR_PROCESS = 'process';\nconst RESOURCE_DETECTOR_SERVICE_INSTANCE_ID = 'serviceinstance';\n\nexport function getResourceDetectorsFromEnv(): Array<ResourceDetector> {\n // When updating this list, make sure to also update the section `resourceDetectors` on README.\n const resourceDetectors = new Map<string, ResourceDetector>([\n [RESOURCE_DETECTOR_HOST, hostDetector],\n [RESOURCE_DETECTOR_OS, osDetector],\n [RESOURCE_DETECTOR_SERVICE_INSTANCE_ID, serviceInstanceIdDetector],\n [RESOURCE_DETECTOR_PROCESS, processDetector],\n [RESOURCE_DETECTOR_ENVIRONMENT, envDetector],\n ]);\n\n const resourceDetectorsFromEnv = getStringListFromEnv(\n 'OTEL_NODE_RESOURCE_DETECTORS'\n ) ?? ['all'];\n\n if (resourceDetectorsFromEnv.includes('all')) {\n return [...resourceDetectors.values()].flat();\n }\n\n if (resourceDetectorsFromEnv.includes('none')) {\n return [];\n }\n\n return resourceDetectorsFromEnv.flatMap(detector => {\n const resourceDetector = resourceDetectors.get(detector);\n if (!resourceDetector) {\n diag.warn(\n `Invalid resource detector \"${detector}\" specified in the environment variable OTEL_NODE_RESOURCE_DETECTORS`\n );\n }\n return resourceDetector || [];\n });\n}\n\nexport function getOtlpProtocolFromEnv(): string {\n return (\n getStringFromEnv('OTEL_EXPORTER_OTLP_TRACES_PROTOCOL') ??\n getStringFromEnv('OTEL_EXPORTER_OTLP_PROTOCOL') ??\n 'http/protobuf'\n );\n}\n\nfunction getOtlpExporterFromEnv(): SpanExporter {\n const protocol = getOtlpProtocolFromEnv();\n\n switch (protocol) {\n case 'grpc':\n return new OTLPGrpcTraceExporter();\n case 'http/json':\n return new OTLPHttpTraceExporter();\n case 'http/protobuf':\n return new OTLPProtoTraceExporter();\n default:\n diag.warn(\n `Unsupported OTLP traces protocol: ${protocol}. Using http/protobuf.`\n );\n return new OTLPProtoTraceExporter();\n }\n}\n\nexport function getSpanProcessorsFromEnv(): SpanProcessor[] {\n const exportersMap = new Map<string, () => SpanExporter>([\n ['otlp', () => getOtlpExporterFromEnv()],\n ['zipkin', () => new ZipkinExporter()],\n ['console', () => new ConsoleSpanExporter()],\n ]);\n const exporters: SpanExporter[] = [];\n const processors: SpanProcessor[] = [];\n let traceExportersList = Array.from(\n new Set(getStringListFromEnv('OTEL_TRACES_EXPORTER'))\n ).filter(s => s !== 'null');\n\n if (traceExportersList[0] === 'none') {\n diag.warn(\n 'OTEL_TRACES_EXPORTER contains \"none\". SDK will not be initialized.'\n );\n return [];\n }\n\n if (traceExportersList.length === 0) {\n diag.debug('OTEL_TRACES_EXPORTER is empty. Using default otlp exporter.');\n traceExportersList = ['otlp'];\n } else if (\n traceExportersList.length > 1 &&\n traceExportersList.includes('none')\n ) {\n diag.warn(\n 'OTEL_TRACES_EXPORTER contains \"none\" along with other exporters. Using default otlp exporter.'\n );\n traceExportersList = ['otlp'];\n }\n\n for (const name of traceExportersList) {\n const exporter = exportersMap.get(name)?.();\n if (exporter) {\n exporters.push(exporter);\n } else {\n diag.warn(`Unrecognized OTEL_TRACES_EXPORTER value: ${name}.`);\n }\n }\n\n for (const exp of exporters) {\n if (exp instanceof ConsoleSpanExporter) {\n processors.push(new SimpleSpanProcessor(exp));\n } else {\n processors.push(new BatchSpanProcessor(exp));\n }\n }\n\n if (exporters.length === 0) {\n diag.warn(\n 'Unable to set up trace exporter(s) due to invalid exporter and/or protocol values.'\n );\n }\n\n return processors;\n}\n\n/**\n * Get a propagator as defined by environment variables\n */\nexport function getPropagatorFromEnv(): TextMapPropagator | null | undefined {\n // Empty and undefined MUST be treated equal.\n const propagatorsEnvVarValue = getStringListFromEnv('OTEL_PROPAGATORS');\n if (propagatorsEnvVarValue == null) {\n // return undefined to fall back to default\n return undefined;\n }\n\n if (propagatorsEnvVarValue.includes('none')) {\n return null;\n }\n\n // Implementation note: this only contains specification required propagators that are actually hosted in this repo.\n // Any other propagators (like aws, aws-lambda, should go into `@opentelemetry/auto-configuration-propagators` instead).\n const propagatorsFactory = new Map<string, () => TextMapPropagator>([\n ['tracecontext', () => new W3CTraceContextPropagator()],\n ['baggage', () => new W3CBaggagePropagator()],\n ['b3', () => new B3Propagator()],\n [\n 'b3multi',\n () => new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }),\n ],\n ['jaeger', () => new JaegerPropagator()],\n ]);\n\n // Values MUST be deduplicated in order to register a Propagator only once.\n const uniquePropagatorNames = Array.from(new Set(propagatorsEnvVarValue));\n const validPropagators: TextMapPropagator[] = [];\n\n uniquePropagatorNames.forEach(name => {\n const propagator = propagatorsFactory.get(name)?.();\n if (!propagator) {\n diag.warn(\n `Propagator \"${name}\" requested through environment variable is unavailable.`\n );\n return;\n }\n\n validPropagators.push(propagator);\n });\n\n if (validPropagators.length === 0) {\n // null to signal that the default should **not** be used in its place.\n return null;\n } else if (uniquePropagatorNames.length === 1) {\n return validPropagators[0];\n } else {\n return new CompositePropagator({\n propagators: validPropagators,\n });\n }\n}\n\n/**\n * Get a propagator as defined by configuration model from configuration\n */\nexport function getPropagatorFromConfiguration(\n config: ConfigurationModel\n): TextMapPropagator | null | undefined {\n const propagatorsValue = getKeyListFromObjectArray(\n config.propagator?.composite\n );\n if (propagatorsValue == null) {\n // return undefined to fall back to default\n return undefined;\n }\n\n if (propagatorsValue.includes('none')) {\n return null;\n }\n\n // Implementation note: this only contains specification required propagators that are actually hosted in this repo.\n // Any other propagators (like aws, aws-lambda, should go into `@opentelemetry/auto-configuration-propagators` instead).\n const propagatorsFactory = new Map<string, () => TextMapPropagator>([\n ['tracecontext', () => new W3CTraceContextPropagator()],\n ['baggage', () => new W3CBaggagePropagator()],\n ['b3', () => new B3Propagator()],\n [\n 'b3multi',\n () => new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }),\n ],\n ['jaeger', () => new JaegerPropagator()],\n ]);\n\n // Values MUST be deduplicated in order to register a Propagator only once.\n const uniquePropagatorNames = Array.from(new Set(propagatorsValue));\n const validPropagators: TextMapPropagator[] = [];\n\n uniquePropagatorNames.forEach(name => {\n const propagator = propagatorsFactory.get(name)?.();\n if (!propagator) {\n diag.warn(\n `Propagator \"${name}\" requested through configuration is unavailable.`\n );\n return;\n }\n\n validPropagators.push(propagator);\n });\n\n if (validPropagators.length === 0) {\n // null to signal that the default should **not** be used in its place.\n return null;\n } else if (uniquePropagatorNames.length === 1) {\n return validPropagators[0];\n } else {\n return new CompositePropagator({\n propagators: validPropagators,\n });\n }\n}\n\nexport function setupContextManager(\n contextManager: ContextManager | null | undefined\n) {\n // null means 'do not register'\n if (contextManager === null) {\n return;\n }\n\n // undefined means 'register default'\n if (contextManager === undefined) {\n const defaultContextManager = new AsyncLocalStorageContextManager();\n defaultContextManager.enable();\n context.setGlobalContextManager(defaultContextManager);\n return;\n }\n\n contextManager.enable();\n context.setGlobalContextManager(contextManager);\n}\n\nexport function setupDefaultContextManager() {\n const defaultContextManager = new AsyncLocalStorageContextManager();\n defaultContextManager.enable();\n context.setGlobalContextManager(defaultContextManager);\n}\n\nexport function setupPropagator(\n propagator: TextMapPropagator | null | undefined\n) {\n // null means 'do not register'\n if (propagator === null) {\n return;\n }\n\n // undefined means 'register default'\n if (propagator === undefined) {\n propagation.setGlobalPropagator(\n new CompositePropagator({\n propagators: [\n new W3CTraceContextPropagator(),\n new W3CBaggagePropagator(),\n ],\n })\n );\n return;\n }\n\n propagation.setGlobalPropagator(propagator);\n}\n\nexport function getKeyListFromObjectArray(\n obj: object[] | undefined\n): string[] | undefined {\n if (!obj || obj.length === 0) {\n return undefined;\n }\n return obj\n .map(item => Object.keys(item))\n .reduce((prev, curr) => prev.concat(curr), []);\n}\n\nexport function getNonNegativeNumberFromEnv(\n envVarName: string\n): number | undefined {\n const value = getNumberFromEnv(envVarName);\n if (value != null && value <= 0) {\n diag.warn(\n `${envVarName} (${value}) is invalid, expected number greater than 0, using default.`\n );\n return undefined;\n }\n return value;\n}\n\nexport function getPeriodicExportingMetricReaderFromEnv(\n exporter: PushMetricExporter\n): IMetricReader {\n const defaultTimeoutMillis = 30_000;\n const defaultIntervalMillis = 60_000;\n\n const rawExportIntervalMillis = getNonNegativeNumberFromEnv(\n 'OTEL_METRIC_EXPORT_INTERVAL'\n );\n const rawExportTimeoutMillis = getNonNegativeNumberFromEnv(\n 'OTEL_METRIC_EXPORT_TIMEOUT'\n );\n\n // Apply defaults\n const exportIntervalMillis = rawExportIntervalMillis ?? defaultIntervalMillis;\n let exportTimeoutMillis = rawExportTimeoutMillis ?? defaultTimeoutMillis;\n\n // Ensure timeout doesn't exceed interval\n if (exportTimeoutMillis > exportIntervalMillis) {\n // determine which env vars were set and which ones defaulted for logging purposes\n const timeoutSource =\n rawExportTimeoutMillis != null\n ? rawExportTimeoutMillis.toString()\n : `${defaultTimeoutMillis}, default`;\n const intervalSource =\n rawExportIntervalMillis != null\n ? rawExportIntervalMillis.toString()\n : `${defaultIntervalMillis}, default`;\n\n const bothSetByUser =\n rawExportTimeoutMillis != null && rawExportIntervalMillis != null;\n const logMessage = `OTEL_METRIC_EXPORT_TIMEOUT (${timeoutSource}) is greater than OTEL_METRIC_EXPORT_INTERVAL (${intervalSource}). Clamping timeout to interval value.`;\n\n // only bother users if they explicitly set both values.\n if (bothSetByUser) {\n diag.warn(logMessage);\n } else {\n diag.info(logMessage);\n }\n\n exportTimeoutMillis = exportIntervalMillis;\n }\n\n return new PeriodicExportingMetricReader({\n exportTimeoutMillis,\n exportIntervalMillis,\n exporter,\n });\n}\n\nexport function getOtlpMetricExporterFromEnv(): PushMetricExporter {\n const protocol =\n (\n getStringFromEnv('OTEL_EXPORTER_OTLP_METRICS_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 return new OTLPGrpcMetricExporter();\n case 'http/json':\n return new OTLPHttpMetricExporter();\n case 'http/protobuf':\n return new OTLPProtoMetricExporter();\n }\n\n diag.warn(\n `Unsupported OTLP metrics protocol: \"${protocol}\". Using http/protobuf.`\n );\n return new OTLPProtoMetricExporter();\n}\n\n/**\n * Get LoggerProviderConfig from environment variables.\n */\nexport function getLoggerProviderConfigFromEnv(): LoggerProviderConfig {\n return {\n logRecordLimits: {\n attributeCountLimit:\n getNonNegativeNumberFromEnv('OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT') ??\n getNonNegativeNumberFromEnv('OTEL_ATTRIBUTE_COUNT_LIMIT'),\n attributeValueLengthLimit:\n getNonNegativeNumberFromEnv(\n 'OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT'\n ) ?? getNonNegativeNumberFromEnv('OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT'),\n },\n };\n}\n\n/**\n * Get configuration for BatchLogRecordProcessor from environment variables.\n */\nexport function getBatchLogRecordProcessorConfigFromEnv(): BufferConfig {\n return {\n maxQueueSize: getNonNegativeNumberFromEnv('OTEL_BLRP_MAX_QUEUE_SIZE'),\n scheduledDelayMillis: getNonNegativeNumberFromEnv(\n 'OTEL_BLRP_SCHEDULE_DELAY'\n ),\n exportTimeoutMillis: getNonNegativeNumberFromEnv(\n 'OTEL_BLRP_EXPORT_TIMEOUT'\n ),\n maxExportBatchSize: getNonNegativeNumberFromEnv(\n 'OTEL_BLRP_MAX_EXPORT_BATCH_SIZE'\n ),\n };\n}\n\nexport function getBatchLogRecordProcessorFromEnv(\n exporter: LogRecordExporter\n): BatchLogRecordProcessor {\n return new BatchLogRecordProcessor(\n exporter,\n getBatchLogRecordProcessorConfigFromEnv()\n );\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAM4B;AAC5B,8CAO6B;AAC7B,wFAAuG;AACvG,sFAAqG;AACrG,sFAAqG;AACrG,oEAAgE;AAChE,wDAUkC;AAClC,kEAMuC;AACvC,gEAA8E;AAC9E,wEAAoE;AACpE,4EAAqF;AACrF,oFAAgG;AAChG,oFAAgG;AAChG,sFAAkG;AAClG,0EAAyE;AAKzE,4DAIoC;AACpC,0FAAyG;AACzG,0FAAyG;AACzG,4FAA2G;AAC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ation,\n TextMapPropagator,\n} from '@opentelemetry/api';\nimport {\n CompositePropagator,\n getNumberFromEnv,\n getStringFromEnv,\n getStringListFromEnv,\n W3CBaggagePropagator,\n W3CTraceContextPropagator,\n} from '@opentelemetry/core';\nimport { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';\nimport { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\nimport { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';\nimport { ZipkinExporter } from '@opentelemetry/exporter-zipkin';\nimport {\n DetectedResourceAttributes,\n envDetector,\n hostDetector,\n osDetector,\n processDetector,\n Resource,\n ResourceDetector,\n resourceFromAttributes,\n serviceInstanceIdDetector,\n} from '@opentelemetry/resources';\nimport {\n BatchSpanProcessor,\n ConsoleSpanExporter,\n SimpleSpanProcessor,\n SpanExporter,\n SpanProcessor,\n} from '@opentelemetry/sdk-trace-base';\nimport { B3InjectEncoding, B3Propagator } from '@opentelemetry/propagator-b3';\nimport { JaegerPropagator } from '@opentelemetry/propagator-jaeger';\nimport { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';\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 { CompressionAlgorithm } from '@opentelemetry/otlp-exporter-base';\nimport {\n ConfigurationModel,\n LogRecordExporterModel,\n} from '@opentelemetry/configuration';\nimport {\n IMetricReader,\n PeriodicExportingMetricReader,\n PushMetricExporter,\n} from '@opentelemetry/sdk-metrics';\nimport { OTLPMetricExporter as OTLPGrpcMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';\nimport { OTLPMetricExporter as OTLPHttpMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';\nimport { OTLPMetricExporter as OTLPProtoMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto';\nimport {\n BatchLogRecordProcessor,\n BufferConfig,\n ConsoleLogRecordExporter,\n LogRecordExporter,\n LoggerProviderConfig,\n LogRecordProcessor,\n SimpleLogRecordProcessor,\n} from '@opentelemetry/sdk-logs';\n\nconst RESOURCE_DETECTOR_ENVIRONMENT = 'env';\nconst RESOURCE_DETECTOR_HOST = 'host';\nconst RESOURCE_DETECTOR_OS = 'os';\nconst RESOURCE_DETECTOR_PROCESS = 'process';\nconst RESOURCE_DETECTOR_SERVICE_INSTANCE_ID = 'serviceinstance';\n\nexport function getResourceFromConfiguration(\n config: ConfigurationModel\n): Resource | undefined {\n if (config.resource && config.resource.attributes) {\n const attr: DetectedResourceAttributes = {};\n for (let i = 0; i < config.resource.attributes.length; i++) {\n const a = config.resource.attributes[i];\n attr[a.name] = a.value;\n }\n return resourceFromAttributes(attr, {\n schemaUrl: config.resource.schema_url,\n });\n }\n return undefined;\n}\n\nexport function getResourceDetectorsFromEnv(): Array<ResourceDetector> {\n // When updating this list, make sure to also update the section `resourceDetectors` on README.\n const resourceDetectors = new Map<string, ResourceDetector>([\n [RESOURCE_DETECTOR_HOST, hostDetector],\n [RESOURCE_DETECTOR_OS, osDetector],\n [RESOURCE_DETECTOR_SERVICE_INSTANCE_ID, serviceInstanceIdDetector],\n [RESOURCE_DETECTOR_PROCESS, processDetector],\n [RESOURCE_DETECTOR_ENVIRONMENT, envDetector],\n ]);\n\n const resourceDetectorsFromEnv = getStringListFromEnv(\n 'OTEL_NODE_RESOURCE_DETECTORS'\n ) ?? ['all'];\n\n if (resourceDetectorsFromEnv.includes('all')) {\n return [...resourceDetectors.values()].flat();\n }\n\n if (resourceDetectorsFromEnv.includes('none')) {\n return [];\n }\n\n return resourceDetectorsFromEnv.flatMap(detector => {\n const resourceDetector = resourceDetectors.get(detector);\n if (!resourceDetector) {\n diag.warn(\n `Invalid resource detector \"${detector}\" specified in the environment variable OTEL_NODE_RESOURCE_DETECTORS`\n );\n }\n return resourceDetector || [];\n });\n}\n\nexport function getResourceDetectorsFromConfiguration(\n config: ConfigurationModel\n): Array<ResourceDetector> {\n // When updating this list, make sure to also update the section `resourceDetectors` on README.\n const resourceDetectors = new Map<string, ResourceDetector>([\n [RESOURCE_DETECTOR_HOST, hostDetector],\n [RESOURCE_DETECTOR_OS, osDetector],\n [RESOURCE_DETECTOR_SERVICE_INSTANCE_ID, serviceInstanceIdDetector],\n [RESOURCE_DETECTOR_PROCESS, processDetector],\n [RESOURCE_DETECTOR_ENVIRONMENT, envDetector],\n ]);\n\n const resourceDetectorsFromConfig = config.node_resource_detectors ?? [];\n\n if (resourceDetectorsFromConfig.includes('all')) {\n return [...resourceDetectors.values()].flat();\n }\n\n if (resourceDetectorsFromConfig.includes('none')) {\n return [];\n }\n\n return resourceDetectorsFromConfig.flatMap(detector => {\n const resourceDetector = resourceDetectors.get(detector);\n if (!resourceDetector) {\n diag.warn(`Invalid resource detector \"${detector}\" specified`);\n }\n return resourceDetector || [];\n });\n}\n\nexport function getOtlpProtocolFromEnv(): string {\n return (\n getStringFromEnv('OTEL_EXPORTER_OTLP_TRACES_PROTOCOL') ??\n getStringFromEnv('OTEL_EXPORTER_OTLP_PROTOCOL') ??\n 'http/protobuf'\n );\n}\n\nfunction getOtlpExporterFromEnv(): SpanExporter {\n const protocol = getOtlpProtocolFromEnv();\n\n switch (protocol) {\n case 'grpc':\n return new OTLPGrpcTraceExporter();\n case 'http/json':\n return new OTLPHttpTraceExporter();\n case 'http/protobuf':\n return new OTLPProtoTraceExporter();\n default:\n diag.warn(\n `Unsupported OTLP traces protocol: ${protocol}. Using http/protobuf.`\n );\n return new OTLPProtoTraceExporter();\n }\n}\n\nexport function getSpanProcessorsFromEnv(): SpanProcessor[] {\n const exportersMap = new Map<string, () => SpanExporter>([\n ['otlp', () => getOtlpExporterFromEnv()],\n ['zipkin', () => new ZipkinExporter()],\n ['console', () => new ConsoleSpanExporter()],\n ]);\n const exporters: SpanExporter[] = [];\n const processors: SpanProcessor[] = [];\n let traceExportersList = Array.from(\n new Set(getStringListFromEnv('OTEL_TRACES_EXPORTER'))\n ).filter(s => s !== 'null');\n\n if (traceExportersList[0] === 'none') {\n diag.warn(\n 'OTEL_TRACES_EXPORTER contains \"none\". SDK will not be initialized.'\n );\n return [];\n }\n\n if (traceExportersList.length === 0) {\n diag.debug('OTEL_TRACES_EXPORTER is empty. Using default otlp exporter.');\n traceExportersList = ['otlp'];\n } else if (\n traceExportersList.length > 1 &&\n traceExportersList.includes('none')\n ) {\n diag.warn(\n 'OTEL_TRACES_EXPORTER contains \"none\" along with other exporters. Using default otlp exporter.'\n );\n traceExportersList = ['otlp'];\n }\n\n for (const name of traceExportersList) {\n const exporter = exportersMap.get(name)?.();\n if (exporter) {\n exporters.push(exporter);\n } else {\n diag.warn(`Unrecognized OTEL_TRACES_EXPORTER value: ${name}.`);\n }\n }\n\n for (const exp of exporters) {\n if (exp instanceof ConsoleSpanExporter) {\n processors.push(new SimpleSpanProcessor(exp));\n } else {\n processors.push(new BatchSpanProcessor(exp));\n }\n }\n\n if (exporters.length === 0) {\n diag.warn(\n 'Unable to set up trace exporter(s) due to invalid exporter and/or protocol values.'\n );\n }\n\n return processors;\n}\n\n/**\n * Get a propagator as defined by environment variables\n */\nexport function getPropagatorFromEnv(): TextMapPropagator | null | undefined {\n // Empty and undefined MUST be treated equal.\n const propagatorsEnvVarValue = getStringListFromEnv('OTEL_PROPAGATORS');\n if (propagatorsEnvVarValue == null) {\n // return undefined to fall back to default\n return undefined;\n }\n\n if (propagatorsEnvVarValue.includes('none')) {\n return null;\n }\n\n // Implementation note: this only contains specification required propagators that are actually hosted in this repo.\n // Any other propagators (like aws, aws-lambda, should go into `@opentelemetry/auto-configuration-propagators` instead).\n const propagatorsFactory = new Map<string, () => TextMapPropagator>([\n ['tracecontext', () => new W3CTraceContextPropagator()],\n ['baggage', () => new W3CBaggagePropagator()],\n ['b3', () => new B3Propagator()],\n [\n 'b3multi',\n () => new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }),\n ],\n ['jaeger', () => new JaegerPropagator()],\n ]);\n\n // Values MUST be deduplicated in order to register a Propagator only once.\n const uniquePropagatorNames = Array.from(new Set(propagatorsEnvVarValue));\n const validPropagators: TextMapPropagator[] = [];\n\n uniquePropagatorNames.forEach(name => {\n const propagator = propagatorsFactory.get(name)?.();\n if (!propagator) {\n diag.warn(\n `Propagator \"${name}\" requested through environment variable is unavailable.`\n );\n return;\n }\n\n validPropagators.push(propagator);\n });\n\n if (validPropagators.length === 0) {\n // null to signal that the default should **not** be used in its place.\n return null;\n } else if (uniquePropagatorNames.length === 1) {\n return validPropagators[0];\n } else {\n return new CompositePropagator({\n propagators: validPropagators,\n });\n }\n}\n\n/**\n * Get a propagator as defined by configuration model from configuration\n */\nexport function getPropagatorFromConfiguration(\n config: ConfigurationModel\n): TextMapPropagator | null | undefined {\n const propagatorsValue = getKeyListFromObjectArray(\n config.propagator?.composite\n );\n if (propagatorsValue == null) {\n // return undefined to fall back to default\n return undefined;\n }\n\n if (propagatorsValue.includes('none')) {\n return null;\n }\n\n // Implementation note: this only contains specification required propagators that are actually hosted in this repo.\n // Any other propagators (like aws, aws-lambda, should go into `@opentelemetry/auto-configuration-propagators` instead).\n const propagatorsFactory = new Map<string, () => TextMapPropagator>([\n ['tracecontext', () => new W3CTraceContextPropagator()],\n ['baggage', () => new W3CBaggagePropagator()],\n ['b3', () => new B3Propagator()],\n [\n 'b3multi',\n () => new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }),\n ],\n ['jaeger', () => new JaegerPropagator()],\n ]);\n\n // Values MUST be deduplicated in order to register a Propagator only once.\n const uniquePropagatorNames = Array.from(new Set(propagatorsValue));\n const validPropagators: TextMapPropagator[] = [];\n\n uniquePropagatorNames.forEach(name => {\n const propagator = propagatorsFactory.get(name)?.();\n if (!propagator) {\n diag.warn(\n `Propagator \"${name}\" requested through configuration is unavailable.`\n );\n return;\n }\n\n validPropagators.push(propagator);\n });\n\n if (validPropagators.length === 0) {\n // null to signal that the default should **not** be used in its place.\n return null;\n } else if (uniquePropagatorNames.length === 1) {\n return validPropagators[0];\n } else {\n return new CompositePropagator({\n propagators: validPropagators,\n });\n }\n}\n\nexport function setupContextManager(\n contextManager: ContextManager | null | undefined\n) {\n // null means 'do not register'\n if (contextManager === null) {\n return;\n }\n\n // undefined means 'register default'\n if (contextManager === undefined) {\n const defaultContextManager = new AsyncLocalStorageContextManager();\n defaultContextManager.enable();\n context.setGlobalContextManager(defaultContextManager);\n return;\n }\n\n contextManager.enable();\n context.setGlobalContextManager(contextManager);\n}\n\nexport function setupPropagator(\n propagator: TextMapPropagator | null | undefined\n) {\n // null means 'do not register'\n if (propagator === null) {\n return;\n }\n\n // undefined means 'register default'\n if (propagator === undefined) {\n propagation.setGlobalPropagator(\n new CompositePropagator({\n propagators: [\n new W3CTraceContextPropagator(),\n new W3CBaggagePropagator(),\n ],\n })\n );\n return;\n }\n\n propagation.setGlobalPropagator(propagator);\n}\n\nexport function getKeyListFromObjectArray(\n obj: object[] | undefined\n): string[] | undefined {\n if (!obj || obj.length === 0) {\n return undefined;\n }\n return obj\n .map(item => Object.keys(item))\n .reduce((prev, curr) => prev.concat(curr), []);\n}\n\nexport function getNonNegativeNumberFromEnv(\n envVarName: string\n): number | undefined {\n const value = getNumberFromEnv(envVarName);\n if (value != null && value <= 0) {\n diag.warn(\n `${envVarName} (${value}) is invalid, expected number greater than 0, using default.`\n );\n return undefined;\n }\n return value;\n}\n\nexport function getPeriodicExportingMetricReaderFromEnv(\n exporter: PushMetricExporter\n): IMetricReader {\n const defaultTimeoutMillis = 30_000;\n const defaultIntervalMillis = 60_000;\n\n const rawExportIntervalMillis = getNonNegativeNumberFromEnv(\n 'OTEL_METRIC_EXPORT_INTERVAL'\n );\n const rawExportTimeoutMillis = getNonNegativeNumberFromEnv(\n 'OTEL_METRIC_EXPORT_TIMEOUT'\n );\n\n // Apply defaults\n const exportIntervalMillis = rawExportIntervalMillis ?? defaultIntervalMillis;\n let exportTimeoutMillis = rawExportTimeoutMillis ?? defaultTimeoutMillis;\n\n // Ensure timeout doesn't exceed interval\n if (exportTimeoutMillis > exportIntervalMillis) {\n // determine which env vars were set and which ones defaulted for logging purposes\n const timeoutSource =\n rawExportTimeoutMillis != null\n ? rawExportTimeoutMillis.toString()\n : `${defaultTimeoutMillis}, default`;\n const intervalSource =\n rawExportIntervalMillis != null\n ? rawExportIntervalMillis.toString()\n : `${defaultIntervalMillis}, default`;\n\n const bothSetByUser =\n rawExportTimeoutMillis != null && rawExportIntervalMillis != null;\n const logMessage = `OTEL_METRIC_EXPORT_TIMEOUT (${timeoutSource}) is greater than OTEL_METRIC_EXPORT_INTERVAL (${intervalSource}). Clamping timeout to interval value.`;\n\n // only bother users if they explicitly set both values.\n if (bothSetByUser) {\n diag.warn(logMessage);\n } else {\n diag.info(logMessage);\n }\n\n exportTimeoutMillis = exportIntervalMillis;\n }\n\n return new PeriodicExportingMetricReader({\n exportTimeoutMillis,\n exportIntervalMillis,\n exporter,\n });\n}\n\nexport function getOtlpMetricExporterFromEnv(): PushMetricExporter {\n const protocol =\n (\n getStringFromEnv('OTEL_EXPORTER_OTLP_METRICS_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 return new OTLPGrpcMetricExporter();\n case 'http/json':\n return new OTLPHttpMetricExporter();\n case 'http/protobuf':\n return new OTLPProtoMetricExporter();\n }\n\n diag.warn(\n `Unsupported OTLP metrics protocol: \"${protocol}\". Using http/protobuf.`\n );\n return new OTLPProtoMetricExporter();\n}\n\n/**\n * Get LoggerProviderConfig from environment variables.\n */\nexport function getLoggerProviderConfigFromEnv(): LoggerProviderConfig {\n return {\n logRecordLimits: {\n attributeCountLimit:\n getNonNegativeNumberFromEnv('OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT') ??\n getNonNegativeNumberFromEnv('OTEL_ATTRIBUTE_COUNT_LIMIT'),\n attributeValueLengthLimit:\n getNonNegativeNumberFromEnv(\n 'OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT'\n ) ?? getNonNegativeNumberFromEnv('OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT'),\n },\n };\n}\n\n/**\n * Get configuration for BatchLogRecordProcessor from environment variables.\n */\nexport function getBatchLogRecordProcessorConfigFromEnv(): BufferConfig {\n return {\n maxQueueSize: getNonNegativeNumberFromEnv('OTEL_BLRP_MAX_QUEUE_SIZE'),\n scheduledDelayMillis: getNonNegativeNumberFromEnv(\n 'OTEL_BLRP_SCHEDULE_DELAY'\n ),\n exportTimeoutMillis: getNonNegativeNumberFromEnv(\n 'OTEL_BLRP_EXPORT_TIMEOUT'\n ),\n maxExportBatchSize: getNonNegativeNumberFromEnv(\n 'OTEL_BLRP_MAX_EXPORT_BATCH_SIZE'\n ),\n };\n}\n\nexport function getBatchLogRecordProcessorFromEnv(\n exporter: LogRecordExporter\n): BatchLogRecordProcessor {\n return new BatchLogRecordProcessor(\n exporter,\n getBatchLogRecordProcessorConfigFromEnv()\n );\n}\n\nexport function getLogRecordExporter(\n exporter: LogRecordExporterModel\n): LogRecordExporter | undefined {\n if (exporter.otlp_http) {\n const encoding = exporter.otlp_http.encoding;\n if (encoding === 'json') {\n return new OTLPHttpLogExporter({\n compression:\n exporter.otlp_http.compression === 'gzip'\n ? CompressionAlgorithm.GZIP\n : CompressionAlgorithm.NONE,\n });\n }\n if (encoding === 'protobuf') {\n return new OTLPProtoLogExporter({\n compression:\n exporter.otlp_http.compression === 'gzip'\n ? CompressionAlgorithm.GZIP\n : CompressionAlgorithm.NONE,\n });\n }\n diag.warn(\n `Unsupported OTLP logs encoding: ${encoding}. Using http/protobuf.`\n );\n return new OTLPProtoLogExporter({\n compression:\n exporter.otlp_http.compression === 'gzip'\n ? CompressionAlgorithm.GZIP\n : CompressionAlgorithm.NONE,\n });\n } else if (exporter.otlp_grpc) {\n return new OTLPGrpcLogExporter({\n compression:\n exporter.otlp_grpc.compression === 'gzip'\n ? CompressionAlgorithm.GZIP\n : CompressionAlgorithm.NONE,\n });\n } else if (exporter.console) {\n return new ConsoleLogRecordExporter();\n }\n diag.warn(`Unsupported Exporter value. No Log Record Exporter registered`);\n return undefined;\n}\n\nexport function getLogRecordProcessorsFromConfiguration(\n config: ConfigurationModel\n): LogRecordProcessor[] | undefined {\n const logRecordProcessors: LogRecordProcessor[] = [];\n config.logger_provider?.processors?.forEach(processor => {\n if (processor.batch) {\n const exporter = getLogRecordExporter(processor.batch.exporter);\n if (exporter) {\n logRecordProcessors.push(\n new BatchLogRecordProcessor(exporter, {\n maxQueueSize: processor.batch.max_queue_size,\n maxExportBatchSize: processor.batch.max_export_batch_size,\n scheduledDelayMillis: processor.batch.schedule_delay,\n exportTimeoutMillis: processor.batch.export_timeout,\n })\n );\n }\n }\n if (processor.simple) {\n const exporter = getLogRecordExporter(processor.simple.exporter);\n if (exporter) {\n logRecordProcessors.push(new SimpleLogRecordProcessor(exporter));\n }\n }\n });\n if (logRecordProcessors.length > 0) {\n return logRecordProcessors;\n }\n return undefined;\n}\n\nexport function getInstanceID(config: ConfigurationModel): string | undefined {\n if (config.resource?.attributes) {\n for (let i = 0; i < config.resource.attributes.length; i++) {\n const element = config.resource.attributes[i];\n if (element.name === 'service.instance.id') {\n return element.value?.toString();\n }\n }\n }\n return undefined;\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.212.0";
1
+ export declare const VERSION = "0.213.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -17,5 +17,5 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.VERSION = '0.212.0';
20
+ exports.VERSION = '0.213.0';
21
21
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.212.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.213.0';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/sdk-node",
3
- "version": "0.212.0",
3
+ "version": "0.213.0",
4
4
  "description": "OpenTelemetry SDK for Node.js",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -43,29 +43,29 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "@opentelemetry/api-logs": "0.212.0",
47
- "@opentelemetry/configuration": "0.212.0",
48
- "@opentelemetry/context-async-hooks": "2.5.1",
49
- "@opentelemetry/core": "2.5.1",
50
- "@opentelemetry/exporter-logs-otlp-grpc": "0.212.0",
51
- "@opentelemetry/exporter-logs-otlp-http": "0.212.0",
52
- "@opentelemetry/exporter-logs-otlp-proto": "0.212.0",
53
- "@opentelemetry/exporter-metrics-otlp-grpc": "0.212.0",
54
- "@opentelemetry/exporter-metrics-otlp-http": "0.212.0",
55
- "@opentelemetry/exporter-metrics-otlp-proto": "0.212.0",
56
- "@opentelemetry/exporter-prometheus": "0.212.0",
57
- "@opentelemetry/exporter-trace-otlp-grpc": "0.212.0",
58
- "@opentelemetry/exporter-trace-otlp-http": "0.212.0",
59
- "@opentelemetry/exporter-trace-otlp-proto": "0.212.0",
60
- "@opentelemetry/exporter-zipkin": "2.5.1",
61
- "@opentelemetry/instrumentation": "0.212.0",
62
- "@opentelemetry/propagator-b3": "2.5.1",
63
- "@opentelemetry/propagator-jaeger": "2.5.1",
64
- "@opentelemetry/resources": "2.5.1",
65
- "@opentelemetry/sdk-logs": "0.212.0",
66
- "@opentelemetry/sdk-metrics": "2.5.1",
67
- "@opentelemetry/sdk-trace-base": "2.5.1",
68
- "@opentelemetry/sdk-trace-node": "2.5.1",
46
+ "@opentelemetry/api-logs": "0.213.0",
47
+ "@opentelemetry/configuration": "0.213.0",
48
+ "@opentelemetry/context-async-hooks": "2.6.0",
49
+ "@opentelemetry/core": "2.6.0",
50
+ "@opentelemetry/exporter-logs-otlp-grpc": "0.213.0",
51
+ "@opentelemetry/exporter-logs-otlp-http": "0.213.0",
52
+ "@opentelemetry/exporter-logs-otlp-proto": "0.213.0",
53
+ "@opentelemetry/exporter-metrics-otlp-grpc": "0.213.0",
54
+ "@opentelemetry/exporter-metrics-otlp-http": "0.213.0",
55
+ "@opentelemetry/exporter-metrics-otlp-proto": "0.213.0",
56
+ "@opentelemetry/exporter-prometheus": "0.213.0",
57
+ "@opentelemetry/exporter-trace-otlp-grpc": "0.213.0",
58
+ "@opentelemetry/exporter-trace-otlp-http": "0.213.0",
59
+ "@opentelemetry/exporter-trace-otlp-proto": "0.213.0",
60
+ "@opentelemetry/exporter-zipkin": "2.6.0",
61
+ "@opentelemetry/instrumentation": "0.213.0",
62
+ "@opentelemetry/propagator-b3": "2.6.0",
63
+ "@opentelemetry/propagator-jaeger": "2.6.0",
64
+ "@opentelemetry/resources": "2.6.0",
65
+ "@opentelemetry/sdk-logs": "0.213.0",
66
+ "@opentelemetry/sdk-metrics": "2.6.0",
67
+ "@opentelemetry/sdk-trace-base": "2.6.0",
68
+ "@opentelemetry/sdk-trace-node": "2.6.0",
69
69
  "@opentelemetry/semantic-conventions": "^1.29.0"
70
70
  },
71
71
  "peerDependencies": {
@@ -84,5 +84,5 @@
84
84
  },
85
85
  "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-sdk-node",
86
86
  "sideEffects": false,
87
- "gitHead": "ad92be4c2c1094745a85b0b7eeff1444a11b1b4a"
87
+ "gitHead": "541e1b4ad83ad2093459794a18283228fe58d199"
88
88
  }