Skip to content

NodeSDK support for OTEL_TRACES_EXPORTER, ... #2873

@francisdb

Description

@francisdb

Is your feature request related to a problem? Please describe.

To consolidate configuration for all our services we would like to configure the node sdk fully through the use of env vars like we do for the java/ruby sdk

see the related specs here:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#otlp-exporter
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md

Describe the solution you'd like

One example would be the following

// import buildTraceExporterFromEnv from somewhere
// configure the exporters you want to allow somewhere?

const sdk = new opentelemetry.NodeSDK({
    resource: new Resource({
        [SemanticResourceAttributes.SERVICE_NAME]: 'myservice',
    }),
    traceExporter: buildTraceExporterFromEnv(),
    instrumentations: [getNodeAutoInstrumentations()]
})

that buildTraceExporterFromEnv could also be the default for traceExporter

In the code we register a number of exporters we want to support

OTEL_TRACES_EXPORTER=otlp
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://..../v1/traces"

Describe alternatives you've considered

We currently have to do handle the OTEL_TRACES_EXPORTER / OTEL_EXPORTER_OTLP_PROTOCOL to exporter selection manually.

Additional context

Current situation:

  • if you don't set a traceExporter on the NodeSDK tracing will be disabled

  • When using BasicTracerProvider the exporter is configured through OTEL_TRACES_EXPORTER as in the spec

    protected _buildExporterFromEnv(): SpanExporter | undefined {
    const exporterName = getEnv().OTEL_TRACES_EXPORTER;
    if (exporterName === 'none') return;
    const exporter = this._getSpanExporter(exporterName);
    if (!exporter) {
    diag.error(
    `Exporter "${exporterName}" requested through environment variable is unavailable.`
    );
    }
    return exporter;
    }

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions