-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
unmarshaler.go
88 lines (74 loc) · 3.13 KB
/
unmarshaler.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package kafkareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kafkareceiver"
import (
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.uber.org/zap"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/zipkinv1"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/zipkinv2"
)
// TracesUnmarshaler deserializes the message body.
type TracesUnmarshaler interface {
// Unmarshal deserializes the message body into traces.
Unmarshal([]byte) (ptrace.Traces, error)
// Encoding of the serialized messages.
Encoding() string
}
// MetricsUnmarshaler deserializes the message body
type MetricsUnmarshaler interface {
// Unmarshal deserializes the message body into traces
Unmarshal([]byte) (pmetric.Metrics, error)
// Encoding of the serialized messages
Encoding() string
}
// LogsUnmarshaler deserializes the message body.
type LogsUnmarshaler interface {
// Unmarshal deserializes the message body into traces.
Unmarshal([]byte) (plog.Logs, error)
// Encoding of the serialized messages.
Encoding() string
}
type LogsUnmarshalerWithEnc interface {
LogsUnmarshaler
// WithEnc sets the character encoding (UTF-8, GBK, etc.) of the unmarshaler.
WithEnc(string) (LogsUnmarshalerWithEnc, error)
}
// defaultTracesUnmarshalers returns map of supported encodings with TracesUnmarshaler.
func defaultTracesUnmarshalers() map[string]TracesUnmarshaler {
otlpPb := newPdataTracesUnmarshaler(&ptrace.ProtoUnmarshaler{}, defaultEncoding)
jaegerProto := jaegerProtoSpanUnmarshaler{}
jaegerJSON := jaegerJSONSpanUnmarshaler{}
zipkinProto := newPdataTracesUnmarshaler(zipkinv2.NewProtobufTracesUnmarshaler(false, false), "zipkin_proto")
zipkinJSON := newPdataTracesUnmarshaler(zipkinv2.NewJSONTracesUnmarshaler(false), "zipkin_json")
zipkinThrift := newPdataTracesUnmarshaler(zipkinv1.NewThriftTracesUnmarshaler(), "zipkin_thrift")
return map[string]TracesUnmarshaler{
otlpPb.Encoding(): otlpPb,
jaegerProto.Encoding(): jaegerProto,
jaegerJSON.Encoding(): jaegerJSON,
zipkinProto.Encoding(): zipkinProto,
zipkinJSON.Encoding(): zipkinJSON,
zipkinThrift.Encoding(): zipkinThrift,
}
}
func defaultMetricsUnmarshalers() map[string]MetricsUnmarshaler {
otlpPb := newPdataMetricsUnmarshaler(&pmetric.ProtoUnmarshaler{}, defaultEncoding)
return map[string]MetricsUnmarshaler{
otlpPb.Encoding(): otlpPb,
}
}
func defaultLogsUnmarshalers(version string, logger *zap.Logger) map[string]LogsUnmarshaler {
azureResourceLogs := newAzureResourceLogsUnmarshaler(version, logger)
otlpPb := newPdataLogsUnmarshaler(&plog.ProtoUnmarshaler{}, defaultEncoding)
raw := newRawLogsUnmarshaler()
text := newTextLogsUnmarshaler()
json := newJSONLogsUnmarshaler()
return map[string]LogsUnmarshaler{
azureResourceLogs.Encoding(): azureResourceLogs,
otlpPb.Encoding(): otlpPb,
raw.Encoding(): raw,
text.Encoding(): text,
json.Encoding(): json,
}
}