Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Datadog Trace Export Configuration #1181

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exporter/datadogexporter/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Datadog Exporter

This exporter sends metric data to [Datadog](https://datadoghq.com).
This exporter sends metric and trace data to [Datadog](https://datadoghq.com).

## Configuration

Expand Down
23 changes: 23 additions & 0 deletions exporter/datadogexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ type MetricsConfig struct {
confignet.TCPAddr `mapstructure:",squash"`
}

// TracesConfig defines the traces exporter specific configuration options
type TracesConfig struct {
// TCPAddr.Endpoint is the host of the Datadog intake server to send traces to.
// If unset, the value is obtained from the Site.
confignet.TCPAddr `mapstructure:",squash"`

// SampleRate is the rate at which to sample this event. Default is 1,
// meaning no sampling. If you want to send one event out of every 250
// times Send() is called, you would specify 250 here.
SampleRate uint `mapstructure:"sample_rate"`
}

// TagsConfig defines the tag-related configuration
// It is embedded in the configuration
type TagsConfig struct {
Expand Down Expand Up @@ -121,6 +133,9 @@ type Config struct {

// Metrics defines the Metrics exporter specific configuration
Metrics MetricsConfig `mapstructure:"metrics"`

// Traces defines the Traces exporter specific configuration
Traces TracesConfig `mapstructure:"traces"`
}

// Sanitize tries to sanitize a given configuration
Expand All @@ -130,6 +145,10 @@ func (c *Config) Sanitize() error {
c.Metrics.Namespace = c.Metrics.Namespace + "."
}

if c.TagsConfig.Env == "" {
c.TagsConfig.Env = "none"
}

if c.API.Key == "" {
return errUnsetAPIKey
}
Expand All @@ -141,5 +160,9 @@ func (c *Config) Sanitize() error {
c.Metrics.TCPAddr.Endpoint = fmt.Sprintf("https://api.%s", c.API.Site)
}

if c.Traces.TCPAddr.Endpoint == "" {
c.Traces.TCPAddr.Endpoint = fmt.Sprintf("https://trace.agent.%s", c.API.Site)
}

return nil
}
7 changes: 7 additions & 0 deletions exporter/datadogexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func TestLoadConfig(t *testing.T) {
Endpoint: "https://api.datadoghq.eu",
},
},

Traces: TracesConfig{
SampleRate: 1,
TCPAddr: confignet.TCPAddr{
Endpoint: "https://trace.agent.datadoghq.eu",
},
},
}, apiConfig)

invalidConfig2 := cfg.Exporters["datadog/invalid"].(*Config)
Expand Down
18 changes: 18 additions & 0 deletions exporter/datadogexporter/example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ exporters:
#
# endpoint: https://api.datadoghq.com

## @param traces - custom object - optional
## Trace exporter specific configuration.
#
# traces:
## @param sample_rate - integer - optional - default: 1
# The rate at which to sample traces. Default is 1 (Always Sample),
# meaning no sampling. If you want to send one event out of every 250
# you would specify 250.
#
# sample_rate: 1

## @param endpoint - string - optional
## The host of the Datadog intake server to send traces to.
## If unset the value is obtained through the `site` parameter in the `api` section.
#
# endpoint: https://api.datadoghq.com


service:
pipelines:
traces:
Expand Down
7 changes: 7 additions & 0 deletions exporter/datadogexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,12 @@ func createDefaultConfig() configmodels.Exporter {
Endpoint: "", // set during config sanitization
},
},

Traces: TracesConfig{
SampleRate: 1,
TCPAddr: confignet.TCPAddr{
Endpoint: "", // set during config sanitization
},
},
}
}
3 changes: 3 additions & 0 deletions exporter/datadogexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func TestCreateDefaultConfig(t *testing.T) {
},

API: APIConfig{Site: "datadoghq.com"},
Traces: TracesConfig{
SampleRate: 1,
},
}, cfg, "failed to create default config")

assert.NoError(t, configcheck.ValidateConfig(cfg))
Expand Down
11 changes: 11 additions & 0 deletions exporter/datadogexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,24 @@ exporters:
metrics:
namespace: opentelemetry

traces:
sample_rate: 1

datadog/invalid:
metrics:
endpoint: "invalid:"

traces:
endpoint: "invalid:"

service:
pipelines:
metrics:
receivers: [examplereceiver]
processors: [exampleprocessor]
exporters: [datadog/api, datadog/invalid]

traces:
receivers: [examplereceiver]
processors: [exampleprocessor]
exporters: [datadog/api, datadog/invalid]