Skip to content

Commit 9ae1a0f

Browse files
dineshg13songy23
andauthored
Create pkg/datadog module (#35067)
**Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> The PR creates `pkg/datadog` package with configuration for DD Exporter and DD connector. The PR currently retains tests in `exporter/datadogexporter` & `connector/datadogconnector` . These will be remove along with the configuration in exporter & connector. --------- Co-authored-by: Yang Song <[email protected]>
1 parent 09f959e commit 9ae1a0f

34 files changed

+2177
-1280
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pkg/datadog
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: |
11+
Create a new module for Datadog exporter configuration.
12+
13+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
14+
issues: [35067]
15+
16+
# (Optional) One or more lines of additional information to render under the primary note.
17+
# These lines will be padded with 2 spaces and then inserted directly into the document.
18+
# Use pipe (|) for multiline entries.
19+
subtext: |
20+
This change introduces a new module for Datadog exporter configuration. The module is shared between the Datadog exporter and the Datadog Connector.
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: [api]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: datadogexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: |
11+
The datadog exporter config has been deprecated in favor of the new `datadog/config` package. The new package is shared between the Datadog exporter and the Datadog Connector.
12+
13+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
14+
issues: [35067]
15+
16+
# (Optional) One or more lines of additional information to render under the primary note.
17+
# These lines will be padded with 2 spaces and then inserted directly into the document.
18+
# Use pipe (|) for multiline entries.
19+
subtext: |
20+
The new `datadog/config` package is a shared module for Datadog exporter configuration. The module is shared between the Datadog exporter and the Datadog Connector.
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: [api]

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ internal/tools/ @open-teleme
147147
pkg/batchperresourceattr/ @open-telemetry/collector-contrib-approvers @atoulme @dmitryax
148148
pkg/batchpersignal/ @open-telemetry/collector-contrib-approvers @jpkrohling
149149
pkg/experimentalmetricmetadata/ @open-telemetry/collector-contrib-approvers @rmfitzpatrick
150+
pkg/datadog/ @open-telemetry/collector-contrib-approvers @mx-psi @dineshg13 @liustanley @songy23 @mackjmr @ankitpatel96
150151
pkg/golden/ @open-telemetry/collector-contrib-approvers @djaglowski @atoulme
151152
pkg/ottl/ @open-telemetry/collector-contrib-approvers @TylerHelmuth @kentquirk @bogdandrutu @evan-bradley
152153
pkg/pdatatest/ @open-telemetry/collector-contrib-approvers @djaglowski @fatsheep9146

cmd/otelcontribcol/builder-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,11 @@ replaces:
490490
- github.com/open-telemetry/opentelemetry-collector-contrib/confmap/provider/s3provider => ../../confmap/provider/s3provider
491491
- github.com/open-telemetry/opentelemetry-collector-contrib/confmap/provider/secretsmanagerprovider => ../../confmap/provider/secretsmanagerprovider
492492
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling => ../../pkg/sampling
493+
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog => ../../pkg/datadog
493494
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil => ../../internal/pdatautil
494495
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/otelarrowexporter => ../../exporter/otelarrowexporter
495496
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/otelarrowreceiver => ../../receiver/otelarrowreceiver
496497
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/cfgardenobserver => ../../extension/observer/cfgardenobserver
497498
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/rabbitmqexporter => ../../exporter/rabbitmqexporter
498499
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver => ../../receiver/githubreceiver
499500
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/grpcutil => ../../internal/grpcutil
500-

cmd/otelcontribcol/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ require (
656656
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sqlquery v0.109.0 // indirect
657657
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchperresourceattr v0.109.0 // indirect
658658
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchpersignal v0.109.0 // indirect
659+
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog v0.0.0-00010101000000-000000000000 // indirect
659660
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata v0.109.0 // indirect
660661
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.109.0 // indirect
661662
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.109.0 // indirect
@@ -1364,6 +1365,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/confmap/provid
13641365

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

1368+
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog => ../../pkg/datadog
1369+
13671370
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil => ../../internal/pdatautil
13681371

13691372
replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/otelarrowexporter => ../../exporter/otelarrowexporter

connector/datadogconnector/config.go

Lines changed: 6 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
package datadogconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector"
55

66
import (
7-
"fmt"
8-
"regexp"
9-
"time"
10-
117
"go.opentelemetry.io/collector/component"
8+
9+
datadogconfig "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog/config"
1210
)
1311

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

20+
// Deprecated: [v0.110.0] Use `datadog.TracesConnectorConfig` instead.
2221
// TracesConfig defines the traces specific configuration options
23-
type TracesConfig struct {
24-
// ignored resources
25-
// A blocklist of regular expressions can be provided to disable certain traces based on their resource name
26-
// all entries must be surrounded by double quotes and separated by commas.
27-
// ignore_resources: ["(GET|POST) /healthcheck"]
28-
IgnoreResources []string `mapstructure:"ignore_resources"`
29-
30-
// SpanNameRemappings is the map of datadog span names and preferred name to map to. This can be used to
31-
// automatically map Datadog Span Operation Names to an updated value. All entries should be key/value pairs.
32-
// span_name_remappings:
33-
// io.opentelemetry.javaagent.spring.client: spring.client
34-
// instrumentation:express.server: express
35-
// go.opentelemetry.io_contrib_instrumentation_net_http_otelhttp.client: http.client
36-
SpanNameRemappings map[string]string `mapstructure:"span_name_remappings"`
37-
38-
// If set to true the OpenTelemetry span name will used in the Datadog resource name.
39-
// If set to false the resource name will be filled with the instrumentation library name + span kind.
40-
// The default value is `false`.
41-
SpanNameAsResourceName bool `mapstructure:"span_name_as_resource_name"`
42-
43-
// If set to true, enables an additional stats computation check on spans to see they have an eligible `span.kind` (server, consumer, client, producer).
44-
// 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.
45-
// NOTE: For stats computed from OTel traces, only top-level spans are considered when this option is off.
46-
// If you are sending OTel traces and want stats on non-top-level spans, this flag will need to be enabled.
47-
// 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`.
48-
ComputeStatsBySpanKind bool `mapstructure:"compute_stats_by_span_kind"`
49-
50-
// If set to true, root spans and spans with a server or consumer `span.kind` will be marked as top-level.
51-
// Additionally, spans with a client or producer `span.kind` will have stats computed.
52-
// 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.
53-
// ComputeTopLevelBySpanKind needs to be enabled in both the Datadog connector and Datadog exporter configs if both components are being used.
54-
// The default value is `false`.
55-
ComputeTopLevelBySpanKind bool `mapstructure:"compute_top_level_by_span_kind"`
56-
57-
// If set to true, enables aggregation of peer related tags (e.g., `peer.service`, `db.instance`, etc.) in the datadog connector.
58-
// If disabled, aggregated trace stats will not include these tags as dimensions on trace metrics.
59-
// For the best experience with peer tags, Datadog also recommends enabling `compute_stats_by_span_kind`.
60-
// If you are using an OTel tracer, it's best to have both enabled because client/producer spans with relevant peer tags
61-
// may not be marked by the datadog connector as top-level spans.
62-
// If enabling both causes the datadog connector to consume too many resources, try disabling `compute_stats_by_span_kind` first.
63-
// A high cardinality of peer tags or APM resources can also contribute to higher CPU and memory consumption.
64-
// You can check for the cardinality of these fields by making trace search queries in the Datadog UI.
65-
// The default list of peer tags can be found in https://github.com/DataDog/datadog-agent/blob/main/pkg/trace/stats/concentrator.go.
66-
PeerTagsAggregation bool `mapstructure:"peer_tags_aggregation"`
67-
68-
// [BETA] Optional list of supplementary peer tags that go beyond the defaults. The Datadog backend validates all tags
69-
// and will drop ones that are unapproved. The default set of peer tags can be found at
70-
// https://github.com/DataDog/datadog-agent/blob/505170c4ac8c3cbff1a61cf5f84b28d835c91058/pkg/trace/stats/concentrator.go#L55.
71-
PeerTags []string `mapstructure:"peer_tags"`
22+
type TracesConfig = datadogconfig.TracesConnectorConfig
7223

73-
// TraceBuffer specifies the number of Datadog Agent TracerPayloads to buffer before dropping.
74-
// The default value is 1000.
75-
TraceBuffer int `mapstructure:"trace_buffer"`
76-
77-
// ResourceAttributesAsContainerTags specifies the list of resource attributes to be used as container tags.
78-
ResourceAttributesAsContainerTags []string `mapstructure:"resource_attributes_as_container_tags"`
79-
80-
// BucketInterval specifies the time interval size of aggregation buckets that aggregate the Datadog trace metrics.
81-
// It is also the time interval that Datadog trace metrics payloads are flushed to the pipeline.
82-
// If you are concerned about the metric volume generated by the Datadog connector and the resulting networking egress, try increasing bucket_interval.
83-
// Default is 10s if unset.
84-
BucketInterval time.Duration `mapstructure:"bucket_interval"`
85-
}
86-
87-
// Validate the configuration for errors. This is required by component.Config.
24+
// Validate checks if the configuration is valid
8825
func (c *Config) Validate() error {
89-
if c.Traces.IgnoreResources != nil {
90-
for _, entry := range c.Traces.IgnoreResources {
91-
_, err := regexp.Compile(entry)
92-
if err != nil {
93-
return fmt.Errorf("%q is not valid resource filter regular expression", entry)
94-
}
95-
}
96-
}
97-
98-
if c.Traces.SpanNameRemappings != nil {
99-
for key, value := range c.Traces.SpanNameRemappings {
100-
if value == "" {
101-
return fmt.Errorf("%q is not valid value for span name remapping", value)
102-
}
103-
if key == "" {
104-
return fmt.Errorf("%q is not valid key for span name remapping", key)
105-
}
106-
}
107-
}
108-
109-
if c.Traces.TraceBuffer < 0 {
110-
return fmt.Errorf("Trace buffer must be non-negative")
111-
}
112-
113-
if c.Traces.BucketInterval < 0 {
114-
return fmt.Errorf("bucket interval must be non-negative")
115-
}
116-
117-
return nil
26+
return c.Traces.Validate()
11827
}

connector/datadogconnector/config_test.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import (
88
"time"
99

1010
"github.com/stretchr/testify/assert"
11+
12+
datadogconfig "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog/config"
1113
)
1214

1315
func TestValidate(t *testing.T) {
14-
1516
tests := []struct {
1617
name string
1718
cfg *Config
@@ -21,36 +22,46 @@ func TestValidate(t *testing.T) {
2122
name: "span name remapping valid",
2223
cfg: &Config{
2324
Traces: TracesConfig{
24-
SpanNameRemappings: map[string]string{"old.opentelemetryspan.name": "updated.name"},
25+
TracesConfig: datadogconfig.TracesConfig{
26+
SpanNameRemappings: map[string]string{"old.opentelemetryspan.name": "updated.name"},
27+
},
2528
},
2629
},
2730
},
2831
{
2932
name: "span name remapping empty val",
3033
cfg: &Config{Traces: TracesConfig{
31-
SpanNameRemappings: map[string]string{"oldname": ""},
34+
TracesConfig: datadogconfig.TracesConfig{
35+
SpanNameRemappings: map[string]string{"oldname": ""},
36+
},
3237
}},
33-
err: "\"\" is not valid value for span name remapping",
38+
err: "'' is not valid value for span name remapping",
3439
},
3540
{
3641
name: "span name remapping empty key",
3742
cfg: &Config{Traces: TracesConfig{
38-
SpanNameRemappings: map[string]string{"": "newname"},
43+
TracesConfig: datadogconfig.TracesConfig{
44+
SpanNameRemappings: map[string]string{"": "newname"},
45+
},
3946
}},
40-
err: "\"\" is not valid key for span name remapping",
47+
err: "'' is not valid key for span name remapping",
4148
},
4249
{
4350
name: "ignore resources valid",
4451
cfg: &Config{Traces: TracesConfig{
45-
IgnoreResources: []string{"[123]"},
52+
TracesConfig: datadogconfig.TracesConfig{
53+
IgnoreResources: []string{"[123]"},
54+
},
4655
}},
4756
},
4857
{
4958
name: "ignore resources missing bracket",
5059
cfg: &Config{Traces: TracesConfig{
51-
IgnoreResources: []string{"[123"},
60+
TracesConfig: datadogconfig.TracesConfig{
61+
IgnoreResources: []string{"[123"},
62+
},
5263
}},
53-
err: "\"[123\" is not valid resource filter regular expression",
64+
err: "'[123' is not valid resource filter regular expression",
5465
},
5566
{
5667
name: "With trace_buffer",
@@ -63,12 +74,16 @@ func TestValidate(t *testing.T) {
6374
cfg: &Config{Traces: TracesConfig{
6475
TraceBuffer: -10,
6576
}},
66-
err: "Trace buffer must be non-negative",
77+
err: "trace buffer must be non-negative",
6778
},
6879
{
6980
name: "With peer_tags",
7081
cfg: &Config{
71-
Traces: TracesConfig{PeerTags: []string{"tag1", "tag2"}},
82+
Traces: TracesConfig{
83+
TracesConfig: datadogconfig.TracesConfig{
84+
PeerTags: []string{"tag1", "tag2"},
85+
},
86+
},
7287
},
7388
},
7489
{

connector/datadogconnector/factory.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"go.uber.org/zap"
1919

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

2324
const nativeIngestFeatureGateName = "connector.datadogconnector.NativeIngest"
@@ -43,9 +44,12 @@ func NewFactory() connector.Factory {
4344
func createDefaultConfig() component.Config {
4445
return &Config{
4546
Traces: TracesConfig{
46-
IgnoreResources: []string{},
47-
TraceBuffer: 1000,
48-
BucketInterval: 10 * time.Second,
47+
TracesConfig: datadogconfig.TracesConfig{
48+
IgnoreResources: []string{},
49+
},
50+
51+
TraceBuffer: 1000,
52+
BucketInterval: 10 * time.Second,
4953
},
5054
}
5155
}

connector/datadogconnector/factory_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99

1010
"github.com/stretchr/testify/assert"
1111
"go.opentelemetry.io/collector/component/componenttest"
12+
13+
datadogconfig "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog/config"
1214
)
1315

1416
func TestCreateDefaultConfig(t *testing.T) {
@@ -18,9 +20,11 @@ func TestCreateDefaultConfig(t *testing.T) {
1820
assert.Equal(t,
1921
&Config{
2022
Traces: TracesConfig{
21-
IgnoreResources: []string{},
22-
TraceBuffer: 1000,
23-
BucketInterval: 10 * time.Second,
23+
TracesConfig: datadogconfig.TracesConfig{
24+
IgnoreResources: []string{},
25+
},
26+
TraceBuffer: 1000,
27+
BucketInterval: 10 * time.Second,
2428
},
2529
},
2630
cfg, "failed to create default config")

connector/datadogconnector/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.20.0
1313
github.com/google/go-cmp v0.6.0
1414
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter v0.109.0
15+
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog v0.0.0-00010101000000-000000000000
1516
github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.109.0
1617
github.com/patrickmn/go-cache v2.1.0+incompatible
1718
github.com/stretchr/testify v1.9.0
@@ -363,3 +364,5 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling =
363364
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil => ../../internal/pdatautil
364365

365366
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata => ../../pkg/experimentalmetricmetadata
367+
368+
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog => ../../pkg/datadog

0 commit comments

Comments
 (0)