Add support to send DataDog traces via Unix Socket

This commit is contained in:
Philipp Trulson 2023-03-20 17:16:08 +01:00 committed by GitHub
parent 6e460cd652
commit 99d779a546
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 5 deletions

View file

@ -23,24 +23,46 @@ tracing:
#### `localAgentHostPort` #### `localAgentHostPort`
_Required, Default="127.0.0.1:8126"_ _Optional, Default="localhost:8126"_
Local Agent Host Port instructs the reporter to send spans to the Datadog Agent at this address (host:port). Local Agent Host Port instructs the reporter to send spans to the Datadog Agent at this address (host:port).
```yaml tab="File (YAML)" ```yaml tab="File (YAML)"
tracing: tracing:
datadog: datadog:
localAgentHostPort: 127.0.0.1:8126 localAgentHostPort: localhost:8126
``` ```
```toml tab="File (TOML)" ```toml tab="File (TOML)"
[tracing] [tracing]
[tracing.datadog] [tracing.datadog]
localAgentHostPort = "127.0.0.1:8126" localAgentHostPort = "localhost:8126"
``` ```
```bash tab="CLI" ```bash tab="CLI"
--tracing.datadog.localAgentHostPort=127.0.0.1:8126 --tracing.datadog.localAgentHostPort=localhost:8126
```
#### `localAgentSocket`
_Optional, Default=""_
Local Agent Socket instructs the reporter to send spans to the Datadog Agent at this UNIX socket.
```yaml tab="File (YAML)"
tracing:
datadog:
localAgentSocket: /var/run/datadog/apm.socket
```
```toml tab="File (TOML)"
[tracing]
[tracing.datadog]
localAgentSocket = "/var/run/datadog/apm.socket"
```
```bash tab="CLI"
--tracing.datadog.localAgentSocket=/var/run/datadog/apm.socket
``` ```
#### `debug` #### `debug`

View file

@ -990,6 +990,9 @@ Sets a list of key:value tags on all spans.
`--tracing.datadog.localagenthostport`: `--tracing.datadog.localagenthostport`:
Sets the Datadog Agent host:port. (Default: ```localhost:8126```) Sets the Datadog Agent host:port. (Default: ```localhost:8126```)
`--tracing.datadog.localagentsocket`:
Sets the socket for the Datadog Agent.
`--tracing.datadog.parentidheadername`: `--tracing.datadog.parentidheadername`:
Sets the header name used to store the parent ID. Sets the header name used to store the parent ID.

View file

@ -990,6 +990,9 @@ Sets a list of key:value tags on all spans.
`TRAEFIK_TRACING_DATADOG_LOCALAGENTHOSTPORT`: `TRAEFIK_TRACING_DATADOG_LOCALAGENTHOSTPORT`:
Sets the Datadog Agent host:port. (Default: ```localhost:8126```) Sets the Datadog Agent host:port. (Default: ```localhost:8126```)
`TRAEFIK_TRACING_DATADOG_LOCALAGENTSOCKET`:
Sets the socket for the Datadog Agent.
`TRAEFIK_TRACING_DATADOG_PARENTIDHEADERNAME`: `TRAEFIK_TRACING_DATADOG_PARENTIDHEADERNAME`:
Sets the header name used to store the parent ID. Sets the header name used to store the parent ID.

View file

@ -365,6 +365,7 @@
sampleRate = 42.0 sampleRate = 42.0
[tracing.datadog] [tracing.datadog]
localAgentHostPort = "foobar" localAgentHostPort = "foobar"
localAgentSocket = "foobar"
globalTag = "foobar" globalTag = "foobar"
[tracing.datadog.globalTags] [tracing.datadog.globalTags]
tag1 = "foobar" tag1 = "foobar"

View file

@ -389,6 +389,7 @@ tracing:
sampleRate: 42 sampleRate: 42
datadog: datadog:
localAgentHostPort: foobar localAgentHostPort: foobar
localAgentSocket: foobar
globalTag: foobar globalTag: foobar
globalTags: globalTags:
tag1: foobar tag1: foobar

View file

@ -171,6 +171,7 @@
samplingType = "foobar" samplingType = "foobar"
samplingParam = 42.0 samplingParam = 42.0
localAgentHostPort = "foobar" localAgentHostPort = "foobar"
localAgentSocket = "foobar"
gen128Bit = true gen128Bit = true
propagation = "foobar" propagation = "foobar"
traceContextHeaderName = "foobar" traceContextHeaderName = "foobar"
@ -182,6 +183,7 @@
sampleRate = 42.0 sampleRate = 42.0
[tracing.datadog] [tracing.datadog]
localAgentHostPort = "foobar" localAgentHostPort = "foobar"
localAgentSocket = "foobar"
globalTag = "foobar" globalTag = "foobar"
debug = true debug = true
prioritySampling = true prioritySampling = true

View file

@ -899,6 +899,7 @@ func TestDo_staticConfiguration(t *testing.T) {
}, },
Datadog: &datadog.Config{ Datadog: &datadog.Config{
LocalAgentHostPort: "foobar", LocalAgentHostPort: "foobar",
LocalAgentSocket: "foobar",
GlobalTag: "foobar", GlobalTag: "foobar",
Debug: true, Debug: true,
PrioritySampling: true, PrioritySampling: true,

View file

@ -390,6 +390,7 @@
}, },
"datadog": { "datadog": {
"localAgentHostPort": "xxxx", "localAgentHostPort": "xxxx",
"localAgentSocket": "xxxx",
"globalTag": "foobar", "globalTag": "foobar",
"debug": true, "debug": true,
"prioritySampling": true, "prioritySampling": true,

View file

@ -18,6 +18,7 @@ const Name = "datadog"
// Config provides configuration settings for a datadog tracer. // Config provides configuration settings for a datadog tracer.
type Config struct { type Config struct {
LocalAgentHostPort string `description:"Sets the Datadog Agent host:port." json:"localAgentHostPort,omitempty" toml:"localAgentHostPort,omitempty" yaml:"localAgentHostPort,omitempty"` LocalAgentHostPort string `description:"Sets the Datadog Agent host:port." json:"localAgentHostPort,omitempty" toml:"localAgentHostPort,omitempty" yaml:"localAgentHostPort,omitempty"`
LocalAgentSocket string `description:"Sets the socket for the Datadog Agent." json:"localAgentSocket,omitempty" toml:"localAgentSocket,omitempty" yaml:"localAgentSocket,omitempty"`
// Deprecated: use GlobalTags instead. // Deprecated: use GlobalTags instead.
GlobalTag string `description:"Sets a key:value tag on all spans." json:"globalTag,omitempty" toml:"globalTag,omitempty" yaml:"globalTag,omitempty" export:"true"` GlobalTag string `description:"Sets a key:value tag on all spans." json:"globalTag,omitempty" toml:"globalTag,omitempty" yaml:"globalTag,omitempty" export:"true"`
GlobalTags map[string]string `description:"Sets a list of key:value tags on all spans." json:"globalTags,omitempty" toml:"globalTags,omitempty" yaml:"globalTags,omitempty" export:"true"` GlobalTags map[string]string `description:"Sets a list of key:value tags on all spans." json:"globalTags,omitempty" toml:"globalTags,omitempty" yaml:"globalTags,omitempty" export:"true"`
@ -47,7 +48,6 @@ func (c *Config) SetDefaults() {
// Setup sets up the tracer. // Setup sets up the tracer.
func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error) { func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error) {
opts := []datadog.StartOption{ opts := []datadog.StartOption{
datadog.WithAgentAddr(c.LocalAgentHostPort),
datadog.WithServiceName(serviceName), datadog.WithServiceName(serviceName),
datadog.WithDebugMode(c.Debug), datadog.WithDebugMode(c.Debug),
datadog.WithPropagator(datadog.NewPropagator(&datadog.PropagatorConfig{ datadog.WithPropagator(datadog.NewPropagator(&datadog.PropagatorConfig{
@ -58,6 +58,12 @@ func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error
})), })),
} }
if c.LocalAgentSocket != "" {
opts = append(opts, datadog.WithUDS(c.LocalAgentSocket))
} else {
opts = append(opts, datadog.WithAgentAddr(c.LocalAgentHostPort))
}
for k, v := range c.GlobalTags { for k, v := range c.GlobalTags {
opts = append(opts, datadog.WithGlobalTag(k, v)) opts = append(opts, datadog.WithGlobalTag(k, v))
} }