-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Datadog Connector Component #25065
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
Merged
Merged
Datadog Connector Component #25065
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
82275b5
parent 0454100f244052c42b968ad4c15313474a49e184
gord02 4fd7e86
resolving conflicts
gord02 f11b7ed
resolving issues to pass CI checks
gord02 93da989
adding changelog file
gord02 54e327a
updating verison.yaml
gord02 c4541e0
adding in doc.go and other changes necessary for adding new component
gord02 1c08283
Merge branch 'main' into datadogconnector
songy23 852ef82
fixing code based on feedback
gord02 806f7fb
Merge branch 'datadogconnector' of github.com:gord02/opentelemetry-co…
gord02 84f7252
re-running crosslink
gord02 160032a
make genotelcontribcol
gord02 9d64c12
Update .chloggen/datadogconnector.yaml
mx-psi dfd0fd7
Merge branch 'main' into datadogconnector
mx-psi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: new_component | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
| component: datadogconnector | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: This is a new component that computes Datadog APM Stats in the event that trace pipelines are sampled. | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| issues: [19740] | ||
|
|
||
| # (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: | ||
|
|
||
| # 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: [user] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include ../../Makefile.Common |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # Datadog Connector | ||
|
|
||
| ## Description | ||
|
|
||
| The Datadog Connector is a connector component that computes Datadog APM Stats pre-sampling in the event that your traces pipeline is sampled using components such as the tailsamplingprocessor or probabilisticsamplerprocessor. | ||
|
|
||
| The connector is most applicable when using the sampling components such as the [tailsamplingprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/tailsamplingprocessor#tail-sampling-processor), or the [probabilisticsamplerprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/probabilisticsamplerprocessor) in one of your pipelines. The sampled pipeline should be duplicated and the `datadog` connector should be added to the the pipeline that is not being sampled to ensure that Datadog APM Stats are accurate in the backend. | ||
|
|
||
| ## Usage | ||
|
|
||
| To use the Datadog Connector, add the connector to one set of the duplicated pipelines while sampling the other. The Datadog Connector will compute APM Stats on all spans that it sees. Here is an example on how to add it to a pipeline using the [probabilisticsampler]: | ||
|
|
||
| <table> | ||
| <tr> | ||
| <td> Before </td> <td> After </td> | ||
| </tr> | ||
| <tr> | ||
| <td valign="top"> | ||
|
|
||
| ```yaml | ||
| # ... | ||
| processors: | ||
| # ... | ||
| probabilistic_sampler: | ||
| sampling_percentage: 20 | ||
| # add the "datadog" processor definition | ||
| datadog: | ||
|
|
||
| exporters: | ||
| datadog: | ||
| api: | ||
| key: ${env:DD_API_KEY} | ||
|
|
||
| service: | ||
| pipelines: | ||
| traces: | ||
| receivers: [otlp] | ||
| # prepend it to the sampler in your pipeline: | ||
| processors: [batch, datadog, probabilistic_sampler] | ||
| exporters: [datadog] | ||
|
|
||
| metrics: | ||
| receivers: [otlp] | ||
| processors: [batch] | ||
| exporters: [datadog] | ||
| ``` | ||
|
|
||
| </td><td valign="top"> | ||
|
|
||
| ```yaml | ||
| # ... | ||
| processors: | ||
| probabilistic_sampler: | ||
| sampling_percentage: 20 | ||
|
|
||
| connectors: | ||
| # add the "datadog" connector definition and further configurations | ||
| datadog/connector: | ||
|
|
||
| exporters: | ||
| datadog: | ||
| api: | ||
| key: ${env:DD_API_KEY} | ||
|
|
||
| service: | ||
| pipelines: | ||
| traces: | ||
| receivers: [otlp] | ||
| processors: [batch] | ||
| exporters: [datadog/connector] | ||
|
|
||
| traces/2: # this pipeline uses sampling | ||
| receivers: [otlp] | ||
| processors: [batch, probabilistic_sampler] | ||
| exporters: [datadog] | ||
|
|
||
| metrics: | ||
| receivers: [datadog/connector] | ||
| processors: [batch] | ||
| exporters: [datadog] | ||
| ``` | ||
| </tr></table> | ||
|
|
||
| Here we have two traces pipelines that ingest the same data but one is being sampled. The one that is sampled has its data sent to the datadog backend for you to see the sampled subset of the total traces sent across. The other non-sampled pipeline of traces sends its data to the metrics pipeline to be used in the APM stats. This unsampled pipeline gives the full picture of how much data the application emits in traces. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package datadogconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector" | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace" | ||
| "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics" | ||
| "go.opentelemetry.io/collector/component" | ||
| "go.opentelemetry.io/collector/consumer" | ||
| "go.opentelemetry.io/collector/pdata/ptrace" | ||
| "go.uber.org/zap" | ||
|
|
||
| "github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog" | ||
| ) | ||
|
|
||
| // connectorImp is the schema for connector | ||
| type connectorImp struct { | ||
| metricsConsumer consumer.Metrics // the next component in the pipeline to ingest data after connector | ||
| logger *zap.Logger | ||
|
|
||
| // agent specifies the agent used to ingest traces and output APM Stats. | ||
| // It is implemented by the traceagent structure; replaced in tests. | ||
| agent datadog.Ingester | ||
|
|
||
| // translator specifies the translator used to transform APM Stats Payloads | ||
| // from the agent to OTLP Metrics. | ||
| translator *metrics.Translator | ||
|
|
||
| // in specifies the channel through which the agent will output Stats Payloads | ||
| // resulting from ingested traces. | ||
| in chan *pb.StatsPayload | ||
|
|
||
| // exit specifies the exit channel, which will be closed upon shutdown. | ||
| exit chan struct{} | ||
| } | ||
|
|
||
| var _ component.Component = (*connectorImp)(nil) // testing that the connectorImp properly implements the type Component interface | ||
|
|
||
| // function to create a new connector | ||
| func newConnector(logger *zap.Logger, _ component.Config, nextConsumer consumer.Metrics) (*connectorImp, error) { | ||
| logger.Info("Building datadog connector") | ||
|
|
||
| in := make(chan *pb.StatsPayload, 100) | ||
| trans, err := metrics.NewTranslator(logger) | ||
|
|
||
| ctx := context.Background() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &connectorImp{ | ||
| logger: logger, | ||
| agent: datadog.NewAgent(ctx, in), | ||
| translator: trans, | ||
| in: in, | ||
| metricsConsumer: nextConsumer, | ||
| exit: make(chan struct{}), | ||
| }, nil | ||
| } | ||
|
|
||
| // Start implements the component.Component interface. | ||
| func (c *connectorImp) Start(_ context.Context, _ component.Host) error { | ||
| c.logger.Info("Starting datadogconnector") | ||
| c.agent.Start() | ||
| go c.run() | ||
| return nil | ||
| } | ||
|
|
||
| // Shutdown implements the component.Component interface. | ||
| func (c *connectorImp) Shutdown(context.Context) error { | ||
| c.logger.Info("Shutting down datadog connector") | ||
| c.agent.Stop() | ||
| c.exit <- struct{}{} // signal exit | ||
| <-c.exit // wait for close | ||
| return nil | ||
| } | ||
|
|
||
| // Capabilities implements the consumer interface. | ||
| // tells use whether the component(connector) will mutate the data passed into it. if set to true the processor does modify the data | ||
| func (c *connectorImp) Capabilities() consumer.Capabilities { | ||
| return consumer.Capabilities{MutatesData: false} | ||
| } | ||
|
|
||
| func (c *connectorImp) ConsumeTraces(ctx context.Context, traces ptrace.Traces) error { | ||
| c.agent.Ingest(ctx, traces) | ||
| return nil | ||
| } | ||
|
|
||
| // run awaits incoming stats resulting from the agent's ingestion, converts them | ||
| // to metrics and flushes them using the configured metrics exporter. | ||
| func (c *connectorImp) run() { | ||
| defer close(c.exit) | ||
| for { | ||
| select { | ||
| case stats := <-c.in: | ||
| if len(stats.Stats) == 0 { | ||
| continue | ||
| } | ||
| // APM stats as metrics | ||
| mx := c.translator.StatsPayloadToMetrics(stats) | ||
| ctx := context.TODO() | ||
|
|
||
| // send metrics to the consumer or next component in pipeline | ||
| if err := c.metricsConsumer.ConsumeMetrics(ctx, mx); err != nil { | ||
| c.logger.Error("Failed ConsumeMetrics", zap.Error(err)) | ||
| return | ||
| } | ||
| case <-c.exit: | ||
| return | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package datadogconnector | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "go.opentelemetry.io/collector/component" | ||
| "go.opentelemetry.io/collector/connector/connectortest" | ||
| "go.opentelemetry.io/collector/consumer/consumertest" | ||
| ) | ||
|
|
||
| var _ component.Component = (*connectorImp)(nil) // testing that the connectorImp properly implements the type Component interface | ||
gord02 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // create test to create a connector, check that basic code compiles | ||
| func TestNewConnector(t *testing.T) { | ||
|
|
||
| factory := NewFactory() | ||
|
|
||
| creationParams := connectortest.NewNopCreateSettings() | ||
| cfg := factory.CreateDefaultConfig().(*Config) | ||
|
|
||
| traceConnector, err := factory.CreateTracesToMetrics(context.Background(), creationParams, cfg, consumertest.NewNop()) | ||
| assert.NoError(t, err) | ||
|
|
||
| _, ok := traceConnector.(*connectorImp) | ||
| assert.True(t, ok) // checks if the created connector implements the connectorImp struct | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //go:generate mdatagen metadata.yaml | ||
|
|
||
| package datadogconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.