Skip to content

Commit

Permalink
fix(sdk): use headers from env if available (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirga authored Aug 27, 2024
1 parent dfd418b commit 31aa015
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/traceloop-sdk/src/lib/tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
BatchSpanProcessor,
SpanProcessor,
} from "@opentelemetry/sdk-trace-node";
import { baggageUtils } from "@opentelemetry/core";
import { Span, context, diag } from "@opentelemetry/api";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { Resource } from "@opentelemetry/resources";
Expand Down Expand Up @@ -246,11 +247,15 @@ export const startTracing = (options: InitializeOptions) => {
});
}

const headers = process.env.TRACELOOP_HEADERS
? baggageUtils.parseKeyPairsIntoRecord(process.env.TRACELOOP_HEADERS)
: { Authorization: `Bearer ${options.apiKey}` };

const traceExporter =
options.exporter ??
new OTLPTraceExporter({
url: `${options.baseUrl}/v1/traces`,
headers: { Authorization: `Bearer ${options.apiKey}` },
headers,
});
_spanProcessor = options.disableBatch
? new SimpleSpanProcessor(traceExporter)
Expand Down

0 comments on commit 31aa015

Please sign in to comment.