From 51edd0d5bc39fdcc55cdd110f563465cf254a9f0 Mon Sep 17 00:00:00 2001 From: Daniel Lamando Date: Fri, 24 May 2024 23:42:15 +0200 Subject: [PATCH] Fix metrics export 400 Bad Request issues --- otel-platform/otlp-json-exporters.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/otel-platform/otlp-json-exporters.ts b/otel-platform/otlp-json-exporters.ts index 8a9616d..22628ab 100644 --- a/otel-platform/otlp-json-exporters.ts +++ b/otel-platform/otlp-json-exporters.ts @@ -14,6 +14,7 @@ import { type IExportTraceServiceRequest, type IExportMetricsServiceRequest, type IExportLogsServiceRequest, + type OtlpEncodingOptions, } from "../opentelemetry/otlp-transformer.js"; import type { @@ -120,6 +121,11 @@ abstract class OTLPFetchExporterBase< } } +const otlpConfig: OtlpEncodingOptions = { + useHex: true, + useLongBits: false, +}; + /** * Collector Trace Exporter for Deno using fetch() */ @@ -136,10 +142,7 @@ export class OTLPTracesExporter } convert(spans: ReadableSpan[]) { - return createExportTraceServiceRequest(spans, { - useHex: true, - useLongBits: false, - }); + return createExportTraceServiceRequest(spans, otlpConfig); } } @@ -154,7 +157,10 @@ export class OTLPMetricsExporter envKey: 'METRICS', }); } - convert = createExportMetricsServiceRequest + + convert(logs: ResourceMetrics[]) { + return createExportMetricsServiceRequest(logs, otlpConfig); + } } export class OTLPLogsExporter @@ -170,10 +176,7 @@ export class OTLPLogsExporter } convert(logs: ReadableLogRecord[]) { - return createExportLogsServiceRequest(logs, { - useHex: true, - useLongBits: false, - }); + return createExportLogsServiceRequest(logs, otlpConfig); } } // btw, events are event.name and event.domain