Skip to content

Commit 0487e20

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

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
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 OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf for exporting traces via http
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

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
22
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
3+
import { OTLPTraceExporter as OTLPTraceExporterHTTP } from '@opentelemetry/exporter-trace-otlp-http';
34
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
45
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
56
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
@@ -12,6 +13,19 @@ import { diag } from '@opentelemetry/api';
1213

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

16+
function getTraceExporter() {
17+
switch (process.env.OTEL_EXPORTER_OTLP_PROTOCOL) {
18+
case undefined:
19+
case '':
20+
case 'grpc':
21+
return new OTLPTraceExporter();
22+
case 'http/protobuf':
23+
return new OTLPTraceExporterHTTP();
24+
default:
25+
throw Error(`Using exporter based on environment variable OTEL_EXPORTER_OTLP_PROTOCOL: ${process.env.OTEL_EXPORTER_OTLP_PROTOCOL} is not implemented!`);
26+
}
27+
}
28+
1529
function getMetricReader() {
1630
switch (process.env.OTEL_METRICS_EXPORTER) {
1731
case undefined:
@@ -35,7 +49,7 @@ function getMetricReader() {
3549
const sdk = new NodeSDK({
3650
autoDetectResources: true,
3751
instrumentations: [getNodeAutoInstrumentations()],
38-
traceExporter: new OTLPTraceExporter(),
52+
traceExporter: getTraceExporter(),
3953
metricReader: getMetricReader(),
4054
resourceDetectors:
4155
[

0 commit comments

Comments
 (0)