Skip to content

Commit 6e2ad14

Browse files
songy23mx-psi
authored andcommitted
[connector/datadog] Allow export to traces pipelines (open-telemetry#27846)
**Description:** <Describe what has changed.> Allow datadogconnector export to traces pipelines **Link to tracking Issue:** <Issue number if applicable> **Testing:** <Describe what testing was performed and which tests were added.> **Documentation:** <Describe the documentation added.> --------- Co-authored-by: Pablo Baeyens <[email protected]>
1 parent ad7f601 commit 6e2ad14

File tree

7 files changed

+61
-10
lines changed

7 files changed

+61
-10
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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: datadogconnector
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Allow datadogconnector to be used as a traces-to-traces connector
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [27846]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

connector/datadogconnector/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| [Exporter Pipeline Type] | [Receiver Pipeline Type] | [Stability Level] |
1616
| ------------------------ | ------------------------ | ----------------- |
1717
| traces | metrics | [beta] |
18+
| traces | traces | [beta] |
1819

1920
[Exporter Pipeline Type]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/README.md#exporter-pipeline-type
2021
[Receiver Pipeline Type]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/README.md#receiver-pipeline-type
@@ -91,7 +92,7 @@ service:
9192
exporters: [datadog/connector]
9293

9394
traces/2: # this pipeline uses sampling
94-
receivers: [otlp]
95+
receivers: [datadog/connector]
9596
processors: [batch, probabilistic_sampler]
9697
exporters: [datadog]
9798

connector/datadogconnector/connector.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import (
1818

1919
// connectorImp is the schema for connector
2020
type connectorImp struct {
21-
metricsConsumer consumer.Metrics // the next component in the pipeline to ingest data after connector
21+
metricsConsumer consumer.Metrics // the next component in the pipeline to ingest metrics after connector
22+
tracesConsumer consumer.Traces // the next component in the pipeline to ingest traces after connector
2223
logger *zap.Logger
2324

2425
// agent specifies the agent used to ingest traces and output APM Stats.
@@ -40,7 +41,7 @@ type connectorImp struct {
4041
var _ component.Component = (*connectorImp)(nil) // testing that the connectorImp properly implements the type Component interface
4142

4243
// function to create a new connector
43-
func newConnector(logger *zap.Logger, _ component.Config, nextConsumer consumer.Metrics) (*connectorImp, error) {
44+
func newConnector(logger *zap.Logger, _ component.Config, metricsConsumer consumer.Metrics, tracesConsumer consumer.Traces) (*connectorImp, error) {
4445
logger.Info("Building datadog connector")
4546

4647
in := make(chan *pb.StatsPayload, 100)
@@ -55,7 +56,8 @@ func newConnector(logger *zap.Logger, _ component.Config, nextConsumer consumer.
5556
agent: datadog.NewAgent(ctx, in),
5657
translator: trans,
5758
in: in,
58-
metricsConsumer: nextConsumer,
59+
metricsConsumer: metricsConsumer,
60+
tracesConsumer: tracesConsumer,
5961
exit: make(chan struct{}),
6062
}, nil
6163
}
@@ -64,7 +66,9 @@ func newConnector(logger *zap.Logger, _ component.Config, nextConsumer consumer.
6466
func (c *connectorImp) Start(_ context.Context, _ component.Host) error {
6567
c.logger.Info("Starting datadogconnector")
6668
c.agent.Start()
67-
go c.run()
69+
if c.metricsConsumer != nil {
70+
go c.run()
71+
}
6872
return nil
6973
}
7074

@@ -85,6 +89,9 @@ func (c *connectorImp) Capabilities() consumer.Capabilities {
8589

8690
func (c *connectorImp) ConsumeTraces(ctx context.Context, traces ptrace.Traces) error {
8791
c.agent.Ingest(ctx, traces)
92+
if c.tracesConsumer != nil {
93+
return c.tracesConsumer.ConsumeTraces(ctx, traces)
94+
}
8895
return nil
8996
}
9097

connector/datadogconnector/connector_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ func TestNewConnector(t *testing.T) {
2323
creationParams := connectortest.NewNopCreateSettings()
2424
cfg := factory.CreateDefaultConfig().(*Config)
2525

26-
traceConnector, err := factory.CreateTracesToMetrics(context.Background(), creationParams, cfg, consumertest.NewNop())
26+
traceToMetricsConnector, err := factory.CreateTracesToMetrics(context.Background(), creationParams, cfg, consumertest.NewNop())
2727
assert.NoError(t, err)
2828

29-
_, ok := traceConnector.(*connectorImp)
29+
_, ok := traceToMetricsConnector.(*connectorImp)
30+
assert.True(t, ok) // checks if the created connector implements the connectorImp struct
31+
32+
traceToTracesConnector, err := factory.CreateTracesToTraces(context.Background(), creationParams, cfg, consumertest.NewNop())
33+
assert.NoError(t, err)
34+
35+
_, ok = traceToTracesConnector.(*connectorImp)
3036
assert.True(t, ok) // checks if the created connector implements the connectorImp struct
3137
}

connector/datadogconnector/factory.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func NewFactory() connector.Factory {
2121
return connector.NewFactory(
2222
metadata.Type,
2323
createDefaultConfig,
24-
connector.WithTracesToMetrics(createTracesToMetricsConnector, metadata.TracesToMetricsStability))
24+
connector.WithTracesToMetrics(createTracesToMetricsConnector, metadata.TracesToMetricsStability),
25+
connector.WithTracesToTraces(createTracesToTracesConnector, metadata.TracesToTracesStability))
2526
}
2627

2728
var _ component.Config = (*Config)(nil)
@@ -35,7 +36,15 @@ func createDefaultConfig() component.Config {
3536
// defines the consumer type of the connector
3637
// we want to consume traces and export metrics therefore define nextConsumer as metrics, consumer is the next component in the pipeline
3738
func createTracesToMetricsConnector(_ context.Context, params connector.CreateSettings, cfg component.Config, nextConsumer consumer.Metrics) (connector.Traces, error) {
38-
c, err := newConnector(params.Logger, cfg, nextConsumer)
39+
c, err := newConnector(params.Logger, cfg, nextConsumer, nil)
40+
if err != nil {
41+
return nil, err
42+
}
43+
return c, nil
44+
}
45+
46+
func createTracesToTracesConnector(_ context.Context, params connector.CreateSettings, cfg component.Config, nextConsumer consumer.Traces) (connector.Traces, error) {
47+
c, err := newConnector(params.Logger, cfg, nil, nextConsumer)
3948
if err != nil {
4049
return nil, err
4150
}

connector/datadogconnector/internal/metadata/generated_status.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

connector/datadogconnector/metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type: datadog
33
status:
44
class: connector
55
stability:
6-
beta: [traces_to_metrics]
6+
beta: [traces_to_metrics, traces_to_traces]
77
distributions: [contrib]
88
codeowners:
99
active: [mx-psi, gbbr, dineshg13]

0 commit comments

Comments
 (0)