Skip to content

Commit

Permalink
Use the new Marshaler in the OTLP HTTP exporter (#3433)
Browse files Browse the repository at this point in the history
Updates #3104

Signed-off-by: Bogdan Drutu [email protected]
  • Loading branch information
bogdandrutu authored Jun 14, 2021
1 parent e8fbda8 commit 2bc0b19
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -92,25 +99,25 @@ 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)
}

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)
}
Expand Down

0 comments on commit 2bc0b19

Please sign in to comment.