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

Create pkg/datadog module #35067

Merged
Merged
Show file tree
Hide file tree
Changes from 15 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
29 changes: 29 additions & 0 deletions .chloggen/dinesh.gurumurthy_datadog-config-pkg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement
mx-psi marked this conversation as resolved.
Show resolved Hide resolved

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/datadog

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: |
Create a new module for Datadog exporter configuration.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35067]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
This change introduces a new module for Datadog exporter configuration. The module is shared between the Datadog exporter and the Datadog Connector.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ internal/tools/ @open-teleme
pkg/batchperresourceattr/ @open-telemetry/collector-contrib-approvers @atoulme @dmitryax
pkg/batchpersignal/ @open-telemetry/collector-contrib-approvers @jpkrohling
pkg/experimentalmetricmetadata/ @open-telemetry/collector-contrib-approvers @rmfitzpatrick
pkg/datadog/ @open-telemetry/collector-contrib-approvers @mx-psi @dineshg13 @liustanley @songy23 @mackjmr @ankitpatel96
pkg/golden/ @open-telemetry/collector-contrib-approvers @djaglowski @atoulme
pkg/ottl/ @open-telemetry/collector-contrib-approvers @TylerHelmuth @kentquirk @bogdandrutu @evan-bradley
pkg/pdatatest/ @open-telemetry/collector-contrib-approvers @djaglowski @fatsheep9146
Expand Down
2 changes: 1 addition & 1 deletion cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,11 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/confmap/provider/s3provider => ../../confmap/provider/s3provider
- github.com/open-telemetry/opentelemetry-collector-contrib/confmap/provider/secretsmanagerprovider => ../../confmap/provider/secretsmanagerprovider
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling => ../../pkg/sampling
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog => ../../pkg/datadog
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil => ../../internal/pdatautil
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/otelarrowexporter => ../../exporter/otelarrowexporter
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/otelarrowreceiver => ../../receiver/otelarrowreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/cfgardenobserver => ../../extension/observer/cfgardenobserver
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/rabbitmqexporter => ../../exporter/rabbitmqexporter
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver => ../../receiver/githubreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/grpcutil => ../../internal/grpcutil

3 changes: 3 additions & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sqlquery v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchperresourceattr v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchpersignal v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog v0.0.0-00010101000000-000000000000 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.109.0 // indirect
Expand Down Expand Up @@ -1364,6 +1365,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/confmap/provid

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling => ../../pkg/sampling

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog => ../../pkg/datadog

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil => ../../internal/pdatautil

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/otelarrowexporter => ../../exporter/otelarrowexporter
Expand Down
103 changes: 6 additions & 97 deletions connector/datadogconnector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
package datadogconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector"

import (
"fmt"
"regexp"
"time"

"go.opentelemetry.io/collector/component"

datadogconfig "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog/config"
)

var _ component.Config = (*Config)(nil)
Expand All @@ -19,100 +17,11 @@ type Config struct {
Traces TracesConfig `mapstructure:"traces"`
}

// Deprecated: [v0.110.0] Use `datadog.TracesConnectorConfig` instead.
// TracesConfig defines the traces specific configuration options
type TracesConfig struct {
// ignored resources
// A blocklist of regular expressions can be provided to disable certain traces based on their resource name
// all entries must be surrounded by double quotes and separated by commas.
// ignore_resources: ["(GET|POST) /healthcheck"]
IgnoreResources []string `mapstructure:"ignore_resources"`

// SpanNameRemappings is the map of datadog span names and preferred name to map to. This can be used to
// automatically map Datadog Span Operation Names to an updated value. All entries should be key/value pairs.
// 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
SpanNameRemappings map[string]string `mapstructure:"span_name_remappings"`

// 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.
// The default value is `false`.
SpanNameAsResourceName bool `mapstructure:"span_name_as_resource_name"`

// If set to true, enables an additional stats computation check on spans to see they have an eligible `span.kind` (server, consumer, client, producer).
// 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.
// NOTE: For stats computed from OTel traces, only top-level spans are considered when this option is off.
// If you are sending OTel traces and want stats on non-top-level spans, this flag will need to be enabled.
// If you are sending OTel traces and do not want stats computed by span kind, you need to disable this flag and disable `compute_top_level_by_span_kind`.
ComputeStatsBySpanKind bool `mapstructure:"compute_stats_by_span_kind"`

// If set to true, root spans and spans with a server or consumer `span.kind` will be marked as top-level.
// Additionally, spans with a client or producer `span.kind` will have stats computed.
// Enabling this config option may increase the number of spans that generate trace metrics, and may change which spans appear as top-level in Datadog.
// ComputeTopLevelBySpanKind needs to be enabled in both the Datadog connector and Datadog exporter configs if both components are being used.
// The default value is `false`.
ComputeTopLevelBySpanKind bool `mapstructure:"compute_top_level_by_span_kind"`

// If set to true, enables aggregation of peer related tags (e.g., `peer.service`, `db.instance`, etc.) in the datadog connector.
// If disabled, aggregated trace stats will not include these tags as dimensions on trace metrics.
// For the best experience with peer tags, Datadog also recommends enabling `compute_stats_by_span_kind`.
// If you are using an OTel tracer, it's best to have both enabled because client/producer spans with relevant peer tags
// may not be marked by the datadog connector as top-level spans.
// If enabling both causes the datadog connector to consume too many resources, try disabling `compute_stats_by_span_kind` first.
// A high cardinality of peer tags or APM resources can also contribute to higher CPU and memory consumption.
// You can check for the cardinality of these fields by making trace search queries in the Datadog UI.
// The default list of peer tags can be found in https://github.com/DataDog/datadog-agent/blob/main/pkg/trace/stats/concentrator.go.
PeerTagsAggregation bool `mapstructure:"peer_tags_aggregation"`

// [BETA] Optional list of supplementary peer tags that go beyond the defaults. The Datadog backend validates all tags
// and will drop ones that are unapproved. The default set of peer tags can be found at
// https://github.com/DataDog/datadog-agent/blob/505170c4ac8c3cbff1a61cf5f84b28d835c91058/pkg/trace/stats/concentrator.go#L55.
PeerTags []string `mapstructure:"peer_tags"`
type TracesConfig = datadogconfig.TracesConnectorConfig

// TraceBuffer specifies the number of Datadog Agent TracerPayloads to buffer before dropping.
// The default value is 1000.
TraceBuffer int `mapstructure:"trace_buffer"`

// ResourceAttributesAsContainerTags specifies the list of resource attributes to be used as container tags.
ResourceAttributesAsContainerTags []string `mapstructure:"resource_attributes_as_container_tags"`

// BucketInterval specifies the time interval size of aggregation buckets that aggregate the Datadog trace metrics.
// It is also the time interval that Datadog trace metrics payloads are flushed to the pipeline.
// If you are concerned about the metric volume generated by the Datadog connector and the resulting networking egress, try increasing bucket_interval.
// Default is 10s if unset.
BucketInterval time.Duration `mapstructure:"bucket_interval"`
}

// Validate the configuration for errors. This is required by component.Config.
// Validate checks if the configuration is valid
func (c *Config) Validate() error {
if c.Traces.IgnoreResources != nil {
for _, entry := range c.Traces.IgnoreResources {
_, err := regexp.Compile(entry)
if err != nil {
return fmt.Errorf("%q is not valid resource filter regular expression", entry)
}
}
}

if c.Traces.SpanNameRemappings != nil {
for key, value := range c.Traces.SpanNameRemappings {
if value == "" {
return fmt.Errorf("%q is not valid value for span name remapping", value)
}
if key == "" {
return fmt.Errorf("%q is not valid key for span name remapping", key)
}
}
}

if c.Traces.TraceBuffer < 0 {
return fmt.Errorf("Trace buffer must be non-negative")
}

if c.Traces.BucketInterval < 0 {
return fmt.Errorf("bucket interval must be non-negative")
}

return nil
return c.Traces.Validate()
}
37 changes: 26 additions & 11 deletions connector/datadogconnector/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"time"

"github.com/stretchr/testify/assert"

datadogconfig "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog/config"
)

func TestValidate(t *testing.T) {

tests := []struct {
name string
cfg *Config
Expand All @@ -21,36 +22,46 @@ func TestValidate(t *testing.T) {
name: "span name remapping valid",
cfg: &Config{
Traces: TracesConfig{
SpanNameRemappings: map[string]string{"old.opentelemetryspan.name": "updated.name"},
TracesConfig: datadogconfig.TracesConfig{
SpanNameRemappings: map[string]string{"old.opentelemetryspan.name": "updated.name"},
},
},
},
},
{
name: "span name remapping empty val",
cfg: &Config{Traces: TracesConfig{
SpanNameRemappings: map[string]string{"oldname": ""},
TracesConfig: datadogconfig.TracesConfig{
SpanNameRemappings: map[string]string{"oldname": ""},
},
}},
err: "\"\" is not valid value for span name remapping",
err: "'' is not valid value for span name remapping",
},
{
name: "span name remapping empty key",
cfg: &Config{Traces: TracesConfig{
SpanNameRemappings: map[string]string{"": "newname"},
TracesConfig: datadogconfig.TracesConfig{
SpanNameRemappings: map[string]string{"": "newname"},
},
}},
err: "\"\" is not valid key for span name remapping",
err: "'' is not valid key for span name remapping",
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: "ignore resources valid",
cfg: &Config{Traces: TracesConfig{
IgnoreResources: []string{"[123]"},
TracesConfig: datadogconfig.TracesConfig{
IgnoreResources: []string{"[123]"},
},
}},
},
{
name: "ignore resources missing bracket",
cfg: &Config{Traces: TracesConfig{
IgnoreResources: []string{"[123"},
TracesConfig: datadogconfig.TracesConfig{
IgnoreResources: []string{"[123"},
},
}},
err: "\"[123\" is not valid resource filter regular expression",
err: "'[123' is not valid resource filter regular expression",
},
{
name: "With trace_buffer",
Expand All @@ -63,12 +74,16 @@ func TestValidate(t *testing.T) {
cfg: &Config{Traces: TracesConfig{
TraceBuffer: -10,
}},
err: "Trace buffer must be non-negative",
err: "trace buffer must be non-negative",
},
{
name: "With peer_tags",
cfg: &Config{
Traces: TracesConfig{PeerTags: []string{"tag1", "tag2"}},
Traces: TracesConfig{
TracesConfig: datadogconfig.TracesConfig{
PeerTags: []string{"tag1", "tag2"},
},
},
},
},
{
Expand Down
10 changes: 7 additions & 3 deletions connector/datadogconnector/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector/internal/metadata"
datadogconfig "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog/config"
)

const nativeIngestFeatureGateName = "connector.datadogconnector.NativeIngest"
Expand All @@ -43,9 +44,12 @@ func NewFactory() connector.Factory {
func createDefaultConfig() component.Config {
return &Config{
Traces: TracesConfig{
IgnoreResources: []string{},
TraceBuffer: 1000,
BucketInterval: 10 * time.Second,
TracesConfig: datadogconfig.TracesConfig{
IgnoreResources: []string{},
},

TraceBuffer: 1000,
BucketInterval: 10 * time.Second,
},
}
}
Expand Down
10 changes: 7 additions & 3 deletions connector/datadogconnector/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component/componenttest"

datadogconfig "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog/config"
)

func TestCreateDefaultConfig(t *testing.T) {
Expand All @@ -18,9 +20,11 @@ func TestCreateDefaultConfig(t *testing.T) {
assert.Equal(t,
&Config{
Traces: TracesConfig{
IgnoreResources: []string{},
TraceBuffer: 1000,
BucketInterval: 10 * time.Second,
TracesConfig: datadogconfig.TracesConfig{
IgnoreResources: []string{},
},
TraceBuffer: 1000,
BucketInterval: 10 * time.Second,
},
},
cfg, "failed to create default config")
Expand Down
3 changes: 3 additions & 0 deletions connector/datadogconnector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.20.0
github.com/google/go-cmp v0.6.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter v0.109.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.109.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -363,3 +364,5 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling =
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil => ../../internal/pdatautil

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata => ../../pkg/experimentalmetricmetadata

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog => ../../pkg/datadog
Loading
Loading