Skip to content

Commit

Permalink
[connector/datadog] Add config option for compute_top_level_by_span_k…
Browse files Browse the repository at this point in the history
…ind (#32836)

**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.-->
Add config option for computing top level spans by span kind in the
Datadog connector and exporter.

**Link to tracking Issue:** <Issue number if applicable>

#32005

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>
  • Loading branch information
liustanley authored May 6, 2024
1 parent 8d4cebc commit d444f48
Show file tree
Hide file tree
Showing 9 changed files with 387 additions and 67 deletions.
29 changes: 29 additions & 0 deletions .chloggen/stanley.liu_top-level-change-connector.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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: The Datadog connector now has a config option to identify top-level spans by span kind. This new logic can be enabled by setting `traces::compute_top_level_by_span_kind` to true in the Datadog connector config. Default is false.

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

# (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: |
`traces::compute_top_level_by_span_kind` needs to be enabled in both the Datadog connector and Datadog exporter configs if both components are being used.
With this new logic, 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.
# 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: []
29 changes: 29 additions & 0 deletions .chloggen/stanley.liu_top-level-change.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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: The Datadog exporter now has a config option to identify top-level spans by span kind. This new logic can be enabled by setting `traces::compute_top_level_by_span_kind` to true in the Datadog exporter config. Default is false.

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

# (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: |
`traces::compute_top_level_by_span_kind` needs to be enabled in both the Datadog connector and Datadog exporter configs if both components are being used.
With this new logic, 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.
# 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: []
9 changes: 9 additions & 0 deletions connector/datadogconnector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ type TracesConfig struct {
// 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`.
Expand Down
8 changes: 6 additions & 2 deletions connector/datadogconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newTraceToMetricConnector(set component.TelemetrySettings, cfg component.Co
ctx := context.Background()
return &traceToMetricConnector{
logger: set.Logger,
agent: datadog.NewAgentWithConfig(ctx, getTraceAgentCfg(cfg.(*Config).Traces, attributesTranslator), in, metricsClient, timingReporter),
agent: datadog.NewAgentWithConfig(ctx, getTraceAgentCfg(set.Logger, cfg.(*Config).Traces, attributesTranslator), in, metricsClient, timingReporter),
translator: trans,
in: in,
metricsConsumer: metricsConsumer,
Expand All @@ -98,7 +98,7 @@ func newTraceToMetricConnector(set component.TelemetrySettings, cfg component.Co
}, nil
}

func getTraceAgentCfg(cfg TracesConfig, attributesTranslator *attributes.Translator) *traceconfig.AgentConfig {
func getTraceAgentCfg(logger *zap.Logger, cfg TracesConfig, attributesTranslator *attributes.Translator) *traceconfig.AgentConfig {
acfg := traceconfig.New()
acfg.OTLPReceiver.AttributesTranslator = attributesTranslator
acfg.OTLPReceiver.SpanNameRemappings = cfg.SpanNameRemappings
Expand All @@ -114,6 +114,10 @@ func getTraceAgentCfg(cfg TracesConfig, attributesTranslator *attributes.Transla
if v := cfg.TraceBuffer; v > 0 {
acfg.TraceBuffer = v
}
if cfg.ComputeTopLevelBySpanKind {
logger.Info("traces::compute_top_level_by_span_kind needs to be enabled in both the Datadog connector and Datadog exporter configs if both components are being used")
acfg.Features["enable_otlp_compute_top_level_by_span_kind"] = struct{}{}
}
return acfg
}

Expand Down
9 changes: 9 additions & 0 deletions connector/datadogconnector/examples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ connectors:
## 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`.
#
compute_stats_by_span_kind: true
## @param compute_top_level_by_span_kind - enables top-level span identification based on `span.kind` - optional
## 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.
#
compute_top_level_by_span_kind: false
## @param peer_tags_aggregation - enables aggregation of peer related tags in Datadog exporter - optional
## If set to true, enables aggregation of peer related tags (e.g., `peer.service`, `db.instance`, etc.) in Datadog exporter.
## If disabled, aggregated trace stats will not include these tags as dimensions on trace metrics.
Expand Down
9 changes: 9 additions & 0 deletions exporter/datadogexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,17 @@ type TracesConfig struct {
// 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 `peer.service` aggregation in the exporter. If disabled, aggregated trace stats will not include `peer.service` as a dimension.
// For the best experience with `peer.service`, it is recommended to also enable `compute_stats_by_span_kind`.
// If enabling both causes the datadog exporter to consume too many resources, try disabling `compute_stats_by_span_kind` first.
Expand Down
10 changes: 10 additions & 0 deletions exporter/datadogexporter/examples/collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,18 @@ exporters:
## 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`.
#
# compute_stats_by_span_kind: true

## @param compute_top_level_by_span_kind - enables top-level span identification based on `span.kind` - optional
## 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.
#
# compute_top_level_by_span_kind: false

## @param peer_service_aggregation - enables `peer.service` aggregation on trace stats in Datadog exporter - optional
## If set to true, enables `peer.service` aggregation in the exporter. If disabled, aggregated trace stats will not include `peer.service` as a dimension.
## For the best experience with `peer.service`, it is recommended to also enable `compute_stats_by_span_kind`.
Expand Down
Loading

0 comments on commit d444f48

Please sign in to comment.