-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
marshaler.go
74 lines (63 loc) · 2.59 KB
/
marshaler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package kafkaexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter"
import (
"github.com/Shopify/sarama"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
)
// TracesMarshaler marshals traces into Message array.
type TracesMarshaler interface {
// Marshal serializes spans into sarama's ProducerMessages
Marshal(traces ptrace.Traces, topic string) ([]*sarama.ProducerMessage, error)
// Encoding returns encoding name
Encoding() string
}
// MetricsMarshaler marshals metrics into Message array
type MetricsMarshaler interface {
// Marshal serializes metrics into sarama's ProducerMessages
Marshal(metrics pmetric.Metrics, topic string) ([]*sarama.ProducerMessage, error)
// Encoding returns encoding name
Encoding() string
}
// LogsMarshaler marshals logs into Message array
type LogsMarshaler interface {
// Marshal serializes logs into sarama's ProducerMessages
Marshal(logs plog.Logs, topic string) ([]*sarama.ProducerMessage, error)
// Encoding returns encoding name
Encoding() string
}
// tracesMarshalers returns map of supported encodings with TracesMarshaler.
func tracesMarshalers() map[string]TracesMarshaler {
otlpPb := newPdataTracesMarshaler(&ptrace.ProtoMarshaler{}, defaultEncoding)
otlpJSON := newPdataTracesMarshaler(&ptrace.JSONMarshaler{}, "otlp_json")
jaegerProto := jaegerMarshaler{marshaler: jaegerProtoSpanMarshaler{}}
jaegerJSON := jaegerMarshaler{marshaler: newJaegerJSONMarshaler()}
return map[string]TracesMarshaler{
otlpPb.Encoding(): otlpPb,
otlpJSON.Encoding(): otlpJSON,
jaegerProto.Encoding(): jaegerProto,
jaegerJSON.Encoding(): jaegerJSON,
}
}
// metricsMarshalers returns map of supported encodings and MetricsMarshaler
func metricsMarshalers() map[string]MetricsMarshaler {
otlpPb := newPdataMetricsMarshaler(&pmetric.ProtoMarshaler{}, defaultEncoding)
otlpJSON := newPdataMetricsMarshaler(&pmetric.JSONMarshaler{}, "otlp_json")
return map[string]MetricsMarshaler{
otlpPb.Encoding(): otlpPb,
otlpJSON.Encoding(): otlpJSON,
}
}
// logsMarshalers returns map of supported encodings and LogsMarshaler
func logsMarshalers() map[string]LogsMarshaler {
otlpPb := newPdataLogsMarshaler(&plog.ProtoMarshaler{}, defaultEncoding)
otlpJSON := newPdataLogsMarshaler(&plog.JSONMarshaler{}, "otlp_json")
raw := newRawMarshaler()
return map[string]LogsMarshaler{
otlpPb.Encoding(): otlpPb,
otlpJSON.Encoding(): otlpJSON,
raw.Encoding(): raw,
}
}