Skip to content

Commit

Permalink
feat(exporter): Support OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf for…
Browse files Browse the repository at this point in the history
… exporting traces via http

Closes open-telemetry#3412
  • Loading branch information
atsu85 committed Nov 1, 2024
1 parent b563a6e commit 3074445
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion autoinstrumentation/nodejs/src/autoinstrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { OTLPTraceExporter as OTLPTraceExporterHTTP } from '@opentelemetry/exporter-trace-otlp-http';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
Expand All @@ -12,6 +13,19 @@ import { diag } from '@opentelemetry/api';

import { NodeSDK } from '@opentelemetry/sdk-node';

function getTraceExporter() {
switch (process.env.OTEL_EXPORTER_OTLP_PROTOCOL) {
case undefined:
case '':
case 'grpc':
return new OTLPTraceExporter();
case 'http/protobuf':
return new OTLPTraceExporterHTTP();
default:
throw Error(`Using exporter based on environment variable OTEL_EXPORTER_OTLP_PROTOCOL: ${process.env.OTEL_EXPORTER_OTLP_PROTOCOL} is not implemented!`);
}
}

function getMetricReader() {
switch (process.env.OTEL_METRICS_EXPORTER) {
case undefined:
Expand All @@ -35,7 +49,7 @@ function getMetricReader() {
const sdk = new NodeSDK({
autoDetectResources: true,
instrumentations: [getNodeAutoInstrumentations()],
traceExporter: new OTLPTraceExporter(),
traceExporter: getTraceExporter(),
metricReader: getMetricReader(),
resourceDetectors:
[
Expand Down

0 comments on commit 3074445

Please sign in to comment.