diff --git a/docs/advanced-config.md b/docs/advanced-config.md index c402d8f8..3dc3a782 100644 --- a/docs/advanced-config.md +++ b/docs/advanced-config.md @@ -64,7 +64,7 @@ This distribution supports all the configuration options supported by the compon | `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` | | Stable | Maximum allowed attribute value size. Empty value is treated as infinity | `OTEL_SPAN_EVENT_COUNT_LIMIT` | `128` | Stable | | `OTEL_SPAN_LINK_COUNT_LIMIT` | `1000`\* | Stable | -| `OTEL_TRACES_EXPORTER`
`tracing.spanExporterFactory` | `otlp` | Stable | Chooses the trace exporters. Shortcut for setting `spanExporterFactory`. Comma-delimited list of exporters. Currently supported values: `otlp`, `console`. +| `OTEL_TRACES_EXPORTER`
`tracing.spanExporterFactory` | `otlp` | Stable | Chooses the trace exporters. Shortcut for setting `spanExporterFactory`. Comma-delimited list of exporters. Currently supported values: `otlp`, `console`, `none`. | `OTEL_TRACES_SAMPLER` | `parentbased_always_on` | Stable | Sampler to be used for traces. See [Sampling](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#sampling) | `OTEL_TRACES_SAMPLER_ARG` | | Stable | String value to be used as the sampler argument. Only be used if OTEL_TRACES_SAMPLER is set. | `SPLUNK_ACCESS_TOKEN`
`accessToken` | | Stable | The optional access token for exporting signal data directly to SignalFx API. @@ -99,7 +99,7 @@ The following config options can be set by passing them as tracing arguments to | `OTEL_SERVICE_NAME`
`serviceName` | `unnamed-node-service` | Stable | The service name of this Node service. | `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`
`endpoint` | `http://localhost:4317` | Stable | The OTLP endpoint to export to. | `OTEL_METRIC_EXPORT_INTERVAL`
`metrics.exportIntervalMillis` | `30000` | Stable | The interval, in milliseconds, of metrics collection and exporting. -| `OTEL_METRICS_EXPORTER`
`metrics.metricReaderFactory` | `otlp` | Stable | Chooses the metric exporters. Comma-delimited list of exporters. Currently supported values: `otlp`, `console`. +| `OTEL_METRICS_EXPORTER`
`metrics.metricReaderFactory` | `otlp` | Stable | Chooses the metric exporters. Comma-delimited list of exporters. Currently supported values: `otlp`, `console`, `none`. | `OTEL_EXPORTER_OTLP_METRICS_PROTOCOL`
`metrics.metricReaderFactory` | `grpc` | Stable | Chooses the metric exporter protocol. Currently supported values: `grpc`, `http/protobuf`. | `OTEL_RESOURCE_ATTRIBUTES` | | Stable | The resource attributes to metric data.
Environment variable example`key1=val1,key2=val2`
| `SPLUNK_METRICS_ENABLED`
n/a (enabled by calling `start`) | `false` | Experimental | Sets up the metrics pipeline (global meter provider, exporters). diff --git a/src/logging/index.ts b/src/logging/index.ts index 8eda5ae1..677c447e 100644 --- a/src/logging/index.ts +++ b/src/logging/index.ts @@ -116,13 +116,13 @@ export function _setDefaultOptions( }; } -const SUPPORTED_EXPORTER_TYPES = ['console', 'otlp']; +const SUPPORTED_EXPORTER_TYPES = ['console', 'otlp', 'none']; function areValidExporterTypes(types: string[]): boolean { return types.every((t) => SUPPORTED_EXPORTER_TYPES.includes(t)); } -function createExporters(options: LoggingOptions) { +export function createExporters(options: LoggingOptions) { const logExporters: string[] = getEnvArray('OTEL_LOGS_EXPORTER', ['otlp']); if (!areValidExporterTypes(logExporters)) { diff --git a/src/metrics/index.ts b/src/metrics/index.ts index 5311ac28..c12766bf 100644 --- a/src/metrics/index.ts +++ b/src/metrics/index.ts @@ -134,7 +134,7 @@ function areValidExporterTypes(types: string[]): boolean { return types.every((t) => SUPPORTED_EXPORTER_TYPES.includes(t)); } -function createOtlpExporter(options: MetricsOptions) { +export function createOtlpExporter(options: MetricsOptions) { let protocol = getEnvValueByPrecedence([ 'OTEL_EXPORTER_OTLP_METRICS_PROTOCOL', 'OTEL_EXPORTER_OTLP_PROTOCOL', diff --git a/src/tracing/options.ts b/src/tracing/options.ts index 6dafdd2c..d3821713 100644 --- a/src/tracing/options.ts +++ b/src/tracing/options.ts @@ -147,19 +147,16 @@ export function _setDefaultOptions(options: Partial = {}): Options { ...extraTracerConfig, }; - const exporterTypes = getExporterTypes(options); - - // factories if (options.spanExporterFactory === undefined) { - options.spanExporterFactory = resolveTraceExporters(exporterTypes); + options.spanExporterFactory = defaultSpanExporterFactory(options); } + options.spanProcessorFactory = options.spanProcessorFactory || defaultSpanProcessorFactory; options.propagatorFactory = options.propagatorFactory || defaultPropagatorFactory; - // instrumentations if (options.instrumentations === undefined) { options.instrumentations = getInstrumentations(); } @@ -190,13 +187,14 @@ export function _setDefaultOptions(options: Partial = {}): Options { }; } -const SUPPORTED_EXPORTER_TYPES = ['console', 'otlp']; +const SUPPORTED_EXPORTER_TYPES = ['console', 'otlp', 'none']; -type ExporterType = (typeof SUPPORTED_EXPORTER_TYPES)[number]; +export type ExporterType = (typeof SUPPORTED_EXPORTER_TYPES)[number]; const SpanExporterMap: Record = { console: consoleSpanExporterFactory, otlp: otlpSpanExporterFactory, + none: () => [], }; function containsSupportedRealmExporter(exporterTypes: string[]) { @@ -239,11 +237,14 @@ function getExporterTypes(options: Partial): ExporterType[] { return traceExporters; } -function resolveTraceExporters( - exporterTypes: ExporterType[] +export function defaultSpanExporterFactory( + options: Partial ): SpanExporterFactory { - const factories = exporterTypes.map((t) => SpanExporterMap[t]); - return (options) => factories.flatMap((factory) => factory(options)); + const exporterTypes = getExporterTypes(options); + return (options) => { + const factories = exporterTypes.map((t) => SpanExporterMap[t]); + return factories.flatMap((factory) => factory(options)); + }; } export function otlpSpanExporterFactory(options: Options): SpanExporter { diff --git a/test/options.test.ts b/test/options.test.ts index dd2f0bf5..603310da 100644 --- a/test/options.test.ts +++ b/test/options.test.ts @@ -280,6 +280,8 @@ describe('options', () => { }); describe('OTEL_TRACES_EXPORTER', () => { + beforeEach(utils.cleanEnvironment); + it('accepts a single key', () => { process.env.OTEL_TRACES_EXPORTER = 'console'; const options = _setDefaultOptions(); @@ -290,6 +292,15 @@ describe('options', () => { assert(exporters[0] instanceof ConsoleSpanExporter); }); + it('can be set to none', () => { + process.env.OTEL_TRACES_EXPORTER = 'none'; + const options = _setDefaultOptions(); + const exporters = options.spanExporterFactory(options); + + assert(Array.isArray(exporters)); + assert.deepStrictEqual(exporters.length, 0); + }); + it('accepts multiple keys', () => { process.env.OTEL_TRACES_EXPORTER = 'otlp,console'; const options = _setDefaultOptions(); @@ -404,9 +415,7 @@ describe('options', () => { }); describe('OTLP span exporter factory', () => { - beforeEach(() => { - beforeEach(utils.cleanEnvironment); - }); + beforeEach(utils.cleanEnvironment); it('throws when called with an unsupported OTLP protocol', () => { process.env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL = 'http/json';