-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
sapm.go
73 lines (61 loc) · 1.94 KB
/
sapm.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package datasenders // import "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/datasenders"
import (
"context"
"fmt"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.uber.org/zap"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sapmexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed"
)
// SapmDataSender implements TraceDataSender for SAPM protocol.
type SapmDataSender struct {
testbed.DataSenderBase
consumer.Traces
compression string
}
// Ensure SapmDataSender implements TraceDataSenderOld.
var _ testbed.TraceDataSender = (*SapmDataSender)(nil)
// NewSapmDataSender creates a new Sapm protocol sender that will send
// to the specified port after Start is called.
func NewSapmDataSender(port int, compression string) *SapmDataSender {
return &SapmDataSender{
DataSenderBase: testbed.DataSenderBase{
Port: port,
Host: testbed.DefaultHost,
},
compression: compression,
}
}
// Start the sender.
func (je *SapmDataSender) Start() error {
factory := sapmexporter.NewFactory()
cfg := &sapmexporter.Config{
Endpoint: fmt.Sprintf("http://%s/v2/trace", je.GetEndpoint()),
Compression: je.compression,
AccessToken: "MyToken",
}
if je.compression == "" {
cfg.DisableCompression = true
}
params := exportertest.NewNopCreateSettings()
params.Logger = zap.L()
exporter, err := factory.CreateTracesExporter(context.Background(), params, cfg)
if err != nil {
return err
}
je.Traces = exporter
return err
}
// GenConfigYAMLStr returns receiver config for the agent.
func (je *SapmDataSender) GenConfigYAMLStr() string {
return fmt.Sprintf(`
sapm:
endpoint: "%s"`, je.GetEndpoint())
}
// ProtocolName returns protocol name as it is specified in Collector config.
func (je *SapmDataSender) ProtocolName() string {
return "sapm"
}