-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
sapm.go
77 lines (66 loc) · 2.47 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
74
75
76
77
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package datareceivers // import "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/datareceivers"
import (
"context"
"fmt"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receivertest"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed"
)
// SapmDataReceiver implements Sapm format receiver.
type SapmDataReceiver struct {
testbed.DataReceiverBase
receiver receiver.Traces
compression string
}
// NewSapmDataReceiver creates a new SapmDataReceiver.
func NewSapmDataReceiver(port int, compression string) *SapmDataReceiver {
return &SapmDataReceiver{DataReceiverBase: testbed.DataReceiverBase{Port: port}, compression: compression}
}
// Start the receiver.
func (sr *SapmDataReceiver) Start(tc consumer.Traces, _ consumer.Metrics, _ consumer.Logs) error {
sapmCfg := sapmreceiver.Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: fmt.Sprintf("127.0.0.1:%d", sr.Port),
},
AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{AccessTokenPassthrough: true},
}
var err error
params := receivertest.NewNopCreateSettings()
sr.receiver, err = sapmreceiver.NewFactory().CreateTracesReceiver(context.Background(), params, &sapmCfg, tc)
if err != nil {
return err
}
return sr.receiver.Start(context.Background(), componenttest.NewNopHost())
}
// Stop the receiver.
func (sr *SapmDataReceiver) Stop() error {
if sr.receiver != nil {
return sr.receiver.Shutdown(context.Background())
}
return nil
}
// GenConfigYAMLStr returns exporter config for the agent.
func (sr *SapmDataReceiver) GenConfigYAMLStr() string {
disableCompression := false
if sr.compression == "" {
disableCompression = true
}
// Note that this generates an exporter config for agent.
return fmt.Sprintf(`
sapm:
endpoint: "http://127.0.0.1:%d/v2/trace"
disable_compression: %v
compression: %s
access_token_passthrough: true`, sr.Port, disableCompression, sr.compression)
}
// ProtocolName returns protocol name as it is specified in Collector config.
func (sr *SapmDataReceiver) ProtocolName() string {
return "sapm"
}