From 2bc0b1979b30820401d30b36606fd84d252cdf50 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 14 Jun 2021 19:02:33 +0300 Subject: [PATCH] Use the new Marshaler in the OTLP HTTP exporter (#3433) Updates #3104 Signed-off-by: Bogdan Drutu bogdandrutu@gmail.com --- exporter/otlphttpexporter/otlp.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/exporter/otlphttpexporter/otlp.go b/exporter/otlphttpexporter/otlp.go index 6c3c8f8322ad..18cd923e6cdb 100644 --- a/exporter/otlphttpexporter/otlp.go +++ b/exporter/otlphttpexporter/otlp.go @@ -38,6 +38,7 @@ import ( "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/internal/middleware" + "go.opentelemetry.io/collector/internal/otlp" ) type exporter struct { @@ -50,6 +51,12 @@ type exporter struct { logger *zap.Logger } +var ( + tracesMarshaler = otlp.NewProtobufTracesMarshaler() + metricsMarshaler = otlp.NewProtobufMetricsMarshaler() + logsMarshaler = otlp.NewProtobufLogsMarshaler() +) + const ( headerRetryAfter = "Retry-After" maxHTTPResponseReadBytes = 64 * 1024 @@ -92,8 +99,8 @@ func (e *exporter) start(_ context.Context, host component.Host) error { return nil } -func (e *exporter) pushTraces(ctx context.Context, traces pdata.Traces) error { - request, err := traces.ToOtlpProtoBytes() +func (e *exporter) pushTraces(ctx context.Context, td pdata.Traces) error { + request, err := tracesMarshaler.Marshal(td) if err != nil { return consumererror.Permanent(err) } @@ -101,16 +108,16 @@ func (e *exporter) pushTraces(ctx context.Context, traces pdata.Traces) error { return e.export(ctx, e.tracesURL, request) } -func (e *exporter) pushMetrics(ctx context.Context, metrics pdata.Metrics) error { - request, err := metrics.ToOtlpProtoBytes() +func (e *exporter) pushMetrics(ctx context.Context, md pdata.Metrics) error { + request, err := metricsMarshaler.Marshal(md) if err != nil { return consumererror.Permanent(err) } return e.export(ctx, e.metricsURL, request) } -func (e *exporter) pushLogs(ctx context.Context, logs pdata.Logs) error { - request, err := logs.ToOtlpProtoBytes() +func (e *exporter) pushLogs(ctx context.Context, ld pdata.Logs) error { + request, err := logsMarshaler.Marshal(ld) if err != nil { return consumererror.Permanent(err) }