Skip to content

Commit

Permalink
pkg/trace/api: OTLP: ensure behaviour and configuration is consistent…
Browse files Browse the repository at this point in the history
… with datadogexporter
  • Loading branch information
gbbr committed Apr 26, 2022
1 parent 6889990 commit aca042f
Show file tree
Hide file tree
Showing 17 changed files with 767 additions and 193 deletions.
8 changes: 5 additions & 3 deletions cmd/trace-agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,11 @@ func applyDatadogConfig(c *config.AgentConfig) error {
grpcPort = coreconfig.Datadog.GetInt(coreconfig.OTLPTracePort)
}
c.OTLPReceiver = &config.OTLP{
BindHost: c.ReceiverHost,
GRPCPort: grpcPort,
MaxRequestBytes: c.MaxRequestBytes,
BindHost: c.ReceiverHost,
GRPCPort: grpcPort,
MaxRequestBytes: c.MaxRequestBytes,
SpanNameRemappings: coreconfig.Datadog.GetStringMapString("otlp_config.traces.span_name_remappings"),
SpanNameAsResourceName: coreconfig.Datadog.GetBool("otlp_config.traces.span_name_as_resource_name"),
}

if coreconfig.Datadog.GetBool("apm_config.telemetry.enabled") {
Expand Down
10 changes: 6 additions & 4 deletions cmd/trace-agent/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ func TestFullYamlConfig(t *testing.T) {
assert.EqualValues(123.4, c.MaxMemory)
assert.Equal("0.0.0.0", c.ReceiverHost)
assert.True(c.LogThrottling)
assert.True(c.OTLPReceiver.SpanNameAsResourceName)
assert.Equal(map[string]string{"a": "b", "and:colons": "in:values", "c": "d", "with.dots": "in.side"}, c.OTLPReceiver.SpanNameRemappings)

noProxy := true
if _, ok := os.LookupEnv("NO_PROXY"); ok {
Expand Down Expand Up @@ -476,10 +478,10 @@ func TestFullYamlConfig(t *testing.T) {
assert.True(o.HTTP.RemoveQueryString)
assert.True(o.HTTP.RemovePathDigits)
assert.True(o.RemoveStackTraces)
assert.True(c.Obfuscation.Redis.Enabled)
assert.True(c.Obfuscation.Memcached.Enabled)
assert.True(c.Obfuscation.CreditCards.Enabled)
assert.True(c.Obfuscation.CreditCards.Luhn)
assert.True(o.Redis.Enabled)
assert.True(o.Memcached.Enabled)
assert.True(o.CreditCards.Enabled)
assert.True(o.CreditCards.Luhn)
}

func TestUndocumentedYamlConfig(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions cmd/trace-agent/config/testdata/full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ otlp_config:
receiver:
traces:
internal_port: 50053
span_name_remappings:
a: b
c: d
"with.dots": "in.side"
"and:colons": "in:values"
span_name_as_resource_name: true
apm_config:
enabled: false
log_file: abc
Expand Down
20 changes: 20 additions & 0 deletions pkg/config/config_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ api_key:
## @param receiver_port - integer - optional - default: 8126
## @env DD_APM_RECEIVER_PORT - integer - optional - default: 8126
## The port that the trace receiver should listen on.
## Set to 0 to disable the HTTP receiver.
#
# receiver_port: 8126

Expand Down Expand Up @@ -3254,3 +3255,22 @@ api_key:
## Whether to ingest traces through the OTLP endpoint. Set to false to disable OTLP traces ingest.
#
# enabled: true

## @param span_name_as_resource_name - boolean - optional - default: false
## @env DD_OTLP_CONFIG_SPAN_NAME_AS_RESOURCE_NAME - boolean - optional - default: false
## If set to true the OpenTelemetry span name will used in the Datadog resource name.
## If set to false the resource name will be filled with the instrumentation library name + span kind.
#
# span_name_as_resource_name: false

## @param span_name_remappings - map - optional
## @env DD_OTLP_CONFIG_SPAN_NAME_REMAPPINGS - boolean - optional
## Defines a map of span names and preferred names to map to. This can be used to automatically map Datadog Span
## Operation Names to an updated value.
## span_name_remappings:
## "io.opentelemetry.javaagent.spring.client": "spring.client"
## "instrumentation:express.server": "express"
## "go.opentelemetry.io_contrib_instrumentation_net_http_otelhttp.client": "http.client"
#
# span_name_remappings:
# <OLD_NAME>: <NEW_NAME>
4 changes: 4 additions & 0 deletions pkg/config/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func setupOTLPEnvironmentVariables(config Config) {
config.BindEnv(OTLPSection + ".receiver.protocols.grpc.write_buffer_size")
config.BindEnv(OTLPSection + ".receiver.protocols.grpc.include_metadata")

// Traces settingds
config.BindEnv("otlp_config.traces.span_name_remappings")
config.BindEnv("otlp_config.traces.span_name_as_resource_name")

// HTTP settings
config.BindEnv(OTLPSection + ".receiver.protocols.http.endpoint")
config.BindEnv(OTLPSection + ".receiver.protocols.http.max_request_body_size")
Expand Down
7 changes: 7 additions & 0 deletions pkg/trace/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func replyWithVersion(hash string, h http.Handler) http.Handler {

// Start starts doing the HTTP server and is ready to receive traces
func (r *HTTPReceiver) Start() {
if r.conf.ReceiverPort == 0 {
log.Debug("HTTP receiver disabled by config (apm_config.receiver_port: 0).")
return
}
mux := r.buildMux()

timeout := 5 * time.Second
Expand Down Expand Up @@ -278,6 +282,9 @@ func (r *HTTPReceiver) listenTCP(addr string) (net.Listener, error) {

// Stop stops the receiver and shuts down the HTTP server.
func (r *HTTPReceiver) Stop() error {
if r.conf.ReceiverPort == 0 {
return nil
}
r.exit <- struct{}{}
<-r.exit

Expand Down
6 changes: 4 additions & 2 deletions pkg/trace/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ func newTestReceiverConfig() *config.AgentConfig {

func TestMain(m *testing.M) {
defer func(old func(string, ...interface{})) { killProcess = old }(killProcess)
killProcess = func(_ string, _ ...interface{}) {}

killProcess = func(format string, args ...interface{}) {
fmt.Printf(format, args...)
fmt.Println()
}
os.Exit(m.Run())
}

Expand Down
Loading

0 comments on commit aca042f

Please sign in to comment.