forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
marshaler.go
45 lines (37 loc) · 1.22 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package rabbitmqexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/rabbitmqexporter"
import (
"fmt"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
)
type marshaler struct {
logsMarshaler plog.Marshaler
tracesMarshaler ptrace.Marshaler
metricsMarshaler pmetric.Marshaler
}
func newMarshaler(encoding *component.ID, host component.Host) (*marshaler, error) {
var (
logsMarshaler plog.Marshaler = &plog.ProtoMarshaler{}
tracesMarshaler ptrace.Marshaler = &ptrace.ProtoMarshaler{}
metricsMarshaler pmetric.Marshaler = &pmetric.ProtoMarshaler{}
)
if encoding != nil {
ext, ok := host.GetExtensions()[*encoding]
if !ok {
return nil, fmt.Errorf("unknown encoding %q", encoding)
}
logsMarshaler, _ = ext.(plog.Marshaler)
tracesMarshaler, _ = ext.(ptrace.Marshaler)
metricsMarshaler, _ = ext.(pmetric.Marshaler)
}
m := marshaler{
logsMarshaler: logsMarshaler,
tracesMarshaler: tracesMarshaler,
metricsMarshaler: metricsMarshaler,
}
return &m, nil
}