|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package datadogconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector" |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "regexp" |
| 9 | + |
| 10 | + "go.opentelemetry.io/collector/component" |
| 11 | +) |
| 12 | + |
| 13 | +var _ component.Config = (*Config)(nil) |
| 14 | + |
| 15 | +// Config defines configuration for the Datadog connector. |
| 16 | +type Config struct { |
| 17 | + // Traces defines the Traces specific configuration |
| 18 | + Traces TracesConfig `mapstructure:"traces"` |
| 19 | +} |
| 20 | + |
| 21 | +// TracesConfig defines the traces specific configuration options |
| 22 | +type TracesConfig struct { |
| 23 | + // ignored resources |
| 24 | + // A blocklist of regular expressions can be provided to disable certain traces based on their resource name |
| 25 | + // all entries must be surrounded by double quotes and separated by commas. |
| 26 | + // ignore_resources: ["(GET|POST) /healthcheck"] |
| 27 | + IgnoreResources []string `mapstructure:"ignore_resources"` |
| 28 | + |
| 29 | + // SpanNameRemappings is the map of datadog span names and preferred name to map to. This can be used to |
| 30 | + // automatically map Datadog Span Operation Names to an updated value. All entries should be key/value pairs. |
| 31 | + // span_name_remappings: |
| 32 | + // io.opentelemetry.javaagent.spring.client: spring.client |
| 33 | + // instrumentation:express.server: express |
| 34 | + // go.opentelemetry.io_contrib_instrumentation_net_http_otelhttp.client: http.client |
| 35 | + SpanNameRemappings map[string]string `mapstructure:"span_name_remappings"` |
| 36 | + |
| 37 | + // If set to true the OpenTelemetry span name will used in the Datadog resource name. |
| 38 | + // If set to false the resource name will be filled with the instrumentation library name + span kind. |
| 39 | + // The default value is `false`. |
| 40 | + SpanNameAsResourceName bool `mapstructure:"span_name_as_resource_name"` |
| 41 | + |
| 42 | + // If set to true, enables an additional stats computation check on spans to see they have an eligible `span.kind` (server, consumer, client, producer). |
| 43 | + // If enabled, a span with an eligible `span.kind` will have stats computed. If disabled, only top-level and measured spans will have stats computed. |
| 44 | + // NOTE: For stats computed from OTel traces, only top-level spans are considered when this option is off. |
| 45 | + ComputeStatsBySpanKind bool `mapstructure:"compute_stats_by_span_kind"` |
| 46 | + |
| 47 | + // If set to true, enables aggregation of peer related tags (e.g., `peer.service`, `db.instance`, etc.) in the datadog connector. |
| 48 | + // If disabled, aggregated trace stats will not include these tags as dimensions on trace metrics. |
| 49 | + // For the best experience with peer tags, Datadog also recommends enabling `compute_stats_by_span_kind`. |
| 50 | + // If you are using an OTel tracer, it's best to have both enabled because client/producer spans with relevant peer tags |
| 51 | + // may not be marked by the datadog connector as top-level spans. |
| 52 | + // If enabling both causes the datadog connector to consume too many resources, try disabling `compute_stats_by_span_kind` first. |
| 53 | + // A high cardinality of peer tags or APM resources can also contribute to higher CPU and memory consumption. |
| 54 | + // You can check for the cardinality of these fields by making trace search queries in the Datadog UI. |
| 55 | + // The default list of peer tags can be found in https://github.com/DataDog/datadog-agent/blob/main/pkg/trace/stats/concentrator.go. |
| 56 | + PeerTagsAggregation bool `mapstructure:"peer_tags_aggregation"` |
| 57 | + |
| 58 | + // TraceBuffer specifies the number of Datadog Agent TracerPayloads to buffer before dropping. |
| 59 | + // The default value is 1000. |
| 60 | + TraceBuffer int `mapstructure:"trace_buffer"` |
| 61 | +} |
| 62 | + |
| 63 | +// Validate the configuration for errors. This is required by component.Config. |
| 64 | +func (c *Config) Validate() error { |
| 65 | + if c.Traces.IgnoreResources != nil { |
| 66 | + for _, entry := range c.Traces.IgnoreResources { |
| 67 | + _, err := regexp.Compile(entry) |
| 68 | + if err != nil { |
| 69 | + return fmt.Errorf("%q is not valid resource filter regular expression", entry) |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + if c.Traces.SpanNameRemappings != nil { |
| 75 | + for key, value := range c.Traces.SpanNameRemappings { |
| 76 | + if value == "" { |
| 77 | + return fmt.Errorf("%q is not valid value for span name remapping", value) |
| 78 | + } |
| 79 | + if key == "" { |
| 80 | + return fmt.Errorf("%q is not valid key for span name remapping", key) |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + if c.Traces.TraceBuffer < 0 { |
| 86 | + return fmt.Errorf("Trace buffer must be non-negative") |
| 87 | + } |
| 88 | + |
| 89 | + return nil |
| 90 | +} |
0 commit comments