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 #3412
  • Loading branch information
atsu85 committed Nov 1, 2024
1 parent ca43ff4 commit b951f71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .chloggen/issue-3412-support-http-protocol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: auto-instrumentation

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Support `http/json` and `http/protobuf` via OTEL_EXPORTER_OTLP_PROTOCOL environment variable in addition to default `grpc` for exporting traces

# One or more tracking issues related to the change
issues: [3412]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
14 changes: 14 additions & 0 deletions autoinstrumentation/nodejs/src/autoinstrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
Expand All @@ -13,7 +15,19 @@ import { diag } from '@opentelemetry/api';
import { NodeSDK } from '@opentelemetry/sdk-node';

function getTraceExporter() {
let protocol = process.env.OTEL_EXPORTER_OTLP_PROTOCOL;
switch (protocol) {
case undefined:
case '':
case 'grpc':
return new OTLPGrpcTraceExporter();
case 'http/json':
return new OTLPHttpTraceExporter();
case 'http/protobuf':
return new OTLPProtoTraceExporter();
default:
throw Error(`Creating traces exporter based on "${protocol}" protocol (configured via environment variable OTEL_EXPORTER_OTLP_PROTOCOL) is not implemented!`);
}
}

function getMetricReader() {
Expand Down

0 comments on commit b951f71

Please sign in to comment.