Add Datadog GlobalTags support
This commit is contained in:
parent
52df1d63fe
commit
10528c973a
6 changed files with 71 additions and 20 deletions
|
@ -67,24 +67,53 @@ tracing:
|
||||||
|
|
||||||
#### `globalTag`
|
#### `globalTag`
|
||||||
|
|
||||||
|
??? warning "Deprecated in favor of the [`globalTags`](#globaltags) option."
|
||||||
|
|
||||||
|
_Optional, Default=empty_
|
||||||
|
|
||||||
|
Applies a shared key:value tag on all spans.
|
||||||
|
|
||||||
|
```yaml tab="File (YAML)"
|
||||||
|
tracing:
|
||||||
|
datadog:
|
||||||
|
globalTag: sample
|
||||||
|
```
|
||||||
|
|
||||||
|
```toml tab="File (TOML)"
|
||||||
|
[tracing]
|
||||||
|
[tracing.datadog]
|
||||||
|
globalTag = "sample"
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash tab="CLI"
|
||||||
|
--tracing.datadog.globalTag=sample
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `globalTags`
|
||||||
|
|
||||||
_Optional, Default=empty_
|
_Optional, Default=empty_
|
||||||
|
|
||||||
Applies a shared key:value tag on all spans.
|
Applies a list of shared key:value tags on all spans.
|
||||||
|
|
||||||
```yaml tab="File (YAML)"
|
```yaml tab="File (YAML)"
|
||||||
tracing:
|
tracing:
|
||||||
datadog:
|
datadog:
|
||||||
globalTag: sample
|
globalTags:
|
||||||
|
tag1: foo
|
||||||
|
tag2: bar
|
||||||
```
|
```
|
||||||
|
|
||||||
```toml tab="File (TOML)"
|
```toml tab="File (TOML)"
|
||||||
[tracing]
|
[tracing]
|
||||||
[tracing.datadog]
|
[tracing.datadog]
|
||||||
globalTag = "sample"
|
[tracing.datadog.globalTags]
|
||||||
|
tag1 = "foo"
|
||||||
|
tag2 = "bar"
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash tab="CLI"
|
```bash tab="CLI"
|
||||||
--tracing.datadog.globalTag=sample
|
--tracing.datadog.globalTags.tag1=foo
|
||||||
|
--tracing.datadog.globalTags.tag2=bar
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `prioritySampling`
|
#### `prioritySampling`
|
||||||
|
|
|
@ -1014,6 +1014,9 @@ Enables Datadog debug. (Default: ```false```)
|
||||||
`--tracing.datadog.globaltag`:
|
`--tracing.datadog.globaltag`:
|
||||||
Sets a key:value tag on all spans.
|
Sets a key:value tag on all spans.
|
||||||
|
|
||||||
|
`--tracing.datadog.globaltags.<name>`:
|
||||||
|
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```)
|
||||||
|
|
||||||
|
|
|
@ -1014,6 +1014,9 @@ Enables Datadog debug. (Default: ```false```)
|
||||||
`TRAEFIK_TRACING_DATADOG_GLOBALTAG`:
|
`TRAEFIK_TRACING_DATADOG_GLOBALTAG`:
|
||||||
Sets a key:value tag on all spans.
|
Sets a key:value tag on all spans.
|
||||||
|
|
||||||
|
`TRAEFIK_TRACING_DATADOG_GLOBALTAGS_<NAME>`:
|
||||||
|
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```)
|
||||||
|
|
||||||
|
|
|
@ -373,6 +373,9 @@
|
||||||
[tracing.datadog]
|
[tracing.datadog]
|
||||||
localAgentHostPort = "foobar"
|
localAgentHostPort = "foobar"
|
||||||
globalTag = "foobar"
|
globalTag = "foobar"
|
||||||
|
[tracing.datadog.globalTags]
|
||||||
|
tag1 = "foobar"
|
||||||
|
tag2 = "foobar"
|
||||||
debug = true
|
debug = true
|
||||||
prioritySampling = true
|
prioritySampling = true
|
||||||
traceIDHeaderName = "foobar"
|
traceIDHeaderName = "foobar"
|
||||||
|
|
|
@ -398,6 +398,9 @@ tracing:
|
||||||
datadog:
|
datadog:
|
||||||
localAgentHostPort: foobar
|
localAgentHostPort: foobar
|
||||||
globalTag: foobar
|
globalTag: foobar
|
||||||
|
globalTags:
|
||||||
|
tag1: foobar
|
||||||
|
tag2: foobar
|
||||||
debug: true
|
debug: true
|
||||||
prioritySampling: true
|
prioritySampling: true
|
||||||
traceIDHeaderName: foobar
|
traceIDHeaderName: foobar
|
||||||
|
|
|
@ -17,14 +17,16 @@ 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"`
|
||||||
GlobalTag string `description:"Sets a key:value tag on all spans." json:"globalTag,omitempty" toml:"globalTag,omitempty" yaml:"globalTag,omitempty" export:"true"`
|
// Deprecated: use GlobalTags instead.
|
||||||
Debug bool `description:"Enables Datadog debug." json:"debug,omitempty" toml:"debug,omitempty" yaml:"debug,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"`
|
||||||
PrioritySampling bool `description:"Enables priority sampling. When using distributed tracing, this option must be enabled in order to get all the parts of a distributed trace sampled." json:"prioritySampling,omitempty" toml:"prioritySampling,omitempty" yaml:"prioritySampling,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"`
|
||||||
TraceIDHeaderName string `description:"Sets the header name used to store the trace ID." json:"traceIDHeaderName,omitempty" toml:"traceIDHeaderName,omitempty" yaml:"traceIDHeaderName,omitempty" export:"true"`
|
Debug bool `description:"Enables Datadog debug." json:"debug,omitempty" toml:"debug,omitempty" yaml:"debug,omitempty" export:"true"`
|
||||||
ParentIDHeaderName string `description:"Sets the header name used to store the parent ID." json:"parentIDHeaderName,omitempty" toml:"parentIDHeaderName,omitempty" yaml:"parentIDHeaderName,omitempty" export:"true"`
|
PrioritySampling bool `description:"Enables priority sampling. When using distributed tracing, this option must be enabled in order to get all the parts of a distributed trace sampled." json:"prioritySampling,omitempty" toml:"prioritySampling,omitempty" yaml:"prioritySampling,omitempty" export:"true"`
|
||||||
SamplingPriorityHeaderName string `description:"Sets the header name used to store the sampling priority." json:"samplingPriorityHeaderName,omitempty" toml:"samplingPriorityHeaderName,omitempty" yaml:"samplingPriorityHeaderName,omitempty" export:"true"`
|
TraceIDHeaderName string `description:"Sets the header name used to store the trace ID." json:"traceIDHeaderName,omitempty" toml:"traceIDHeaderName,omitempty" yaml:"traceIDHeaderName,omitempty" export:"true"`
|
||||||
BagagePrefixHeaderName string `description:"Sets the header name prefix used to store baggage items in a map." json:"bagagePrefixHeaderName,omitempty" toml:"bagagePrefixHeaderName,omitempty" yaml:"bagagePrefixHeaderName,omitempty" export:"true"`
|
ParentIDHeaderName string `description:"Sets the header name used to store the parent ID." json:"parentIDHeaderName,omitempty" toml:"parentIDHeaderName,omitempty" yaml:"parentIDHeaderName,omitempty" export:"true"`
|
||||||
|
SamplingPriorityHeaderName string `description:"Sets the header name used to store the sampling priority." json:"samplingPriorityHeaderName,omitempty" toml:"samplingPriorityHeaderName,omitempty" yaml:"samplingPriorityHeaderName,omitempty" export:"true"`
|
||||||
|
BagagePrefixHeaderName string `description:"Sets the header name prefix used to store baggage items in a map." json:"bagagePrefixHeaderName,omitempty" toml:"bagagePrefixHeaderName,omitempty" yaml:"bagagePrefixHeaderName,omitempty" export:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaults sets the default values.
|
// SetDefaults sets the default values.
|
||||||
|
@ -44,17 +46,9 @@ 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) {
|
||||||
tag := strings.SplitN(c.GlobalTag, ":", 2)
|
|
||||||
|
|
||||||
value := ""
|
|
||||||
if len(tag) == 2 {
|
|
||||||
value = tag[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := []datadog.StartOption{
|
opts := []datadog.StartOption{
|
||||||
datadog.WithAgentAddr(c.LocalAgentHostPort),
|
datadog.WithAgentAddr(c.LocalAgentHostPort),
|
||||||
datadog.WithServiceName(serviceName),
|
datadog.WithServiceName(serviceName),
|
||||||
datadog.WithGlobalTag(tag[0], value),
|
|
||||||
datadog.WithDebugMode(c.Debug),
|
datadog.WithDebugMode(c.Debug),
|
||||||
datadog.WithPropagator(datadog.NewPropagator(&datadog.PropagatorConfig{
|
datadog.WithPropagator(datadog.NewPropagator(&datadog.PropagatorConfig{
|
||||||
TraceHeader: c.TraceIDHeaderName,
|
TraceHeader: c.TraceIDHeaderName,
|
||||||
|
@ -63,6 +57,22 @@ func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error
|
||||||
BaggagePrefix: c.BagagePrefixHeaderName,
|
BaggagePrefix: c.BagagePrefixHeaderName,
|
||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for k, v := range c.GlobalTags {
|
||||||
|
opts = append(opts, datadog.WithGlobalTag(k, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.GlobalTag != "" {
|
||||||
|
log.WithoutContext().Warn(`Datadog: option "globalTag" is deprecated, please use "globalTags" instead.`)
|
||||||
|
|
||||||
|
key, value, _ := strings.Cut(c.GlobalTag, ":")
|
||||||
|
|
||||||
|
// Don't override a tag already defined with the new option.
|
||||||
|
if _, ok := c.GlobalTags[key]; !ok {
|
||||||
|
opts = append(opts, datadog.WithGlobalTag(key, value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if c.PrioritySampling {
|
if c.PrioritySampling {
|
||||||
opts = append(opts, datadog.WithPrioritySampling())
|
opts = append(opts, datadog.WithPrioritySampling())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue