Skip to content

Commit a22b2d5

Browse files
committed
feat(exporter): Support OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf for exporting traces via http
Closes #3412
1 parent a21f949 commit a22b2d5

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: auto-instrumentation
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Support `http/json` and `http/protobuf` via OTEL_EXPORTER_OTLP_PROTOCOL environment variable in addition to default `grpc` for exporting traces
9+
10+
# One or more tracking issues related to the change
11+
issues: [3412]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

autoinstrumentation/nodejs/src/autoinstrumentation.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
2+
import { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
3+
import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
24
import { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
35
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
46
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
@@ -13,7 +15,19 @@ import { diag } from '@opentelemetry/api';
1315
import { NodeSDK } from '@opentelemetry/sdk-node';
1416

1517
function getTraceExporter() {
18+
let protocol = process.env.OTEL_EXPORTER_OTLP_PROTOCOL;
19+
switch (protocol) {
20+
case undefined:
21+
case '':
22+
case 'grpc':
1623
return new OTLPGrpcTraceExporter();
24+
case 'http/json':
25+
return new OTLPHttpTraceExporter();
26+
case 'http/protobuf':
27+
return new OTLPProtoTraceExporter();
28+
default:
29+
throw Error(`Creating traces exporter based on "${protocol}" protocol (configured via environment variable OTEL_EXPORTER_OTLP_PROTOCOL) is not implemented!`);
30+
}
1731
}
1832

1933
function getMetricReader() {

0 commit comments

Comments
 (0)