Skip to content

Add _dd.svc_src to distinguish source#5778

Merged
TonyCTHsu merged 13 commits into
masterfrom
tonycthsu/source-attri
May 28, 2026
Merged

Add _dd.svc_src to distinguish source#5778
TonyCTHsu merged 13 commits into
masterfrom
tonycthsu/source-attri

Conversation

@TonyCTHsu
Copy link
Copy Markdown
Collaborator

@TonyCTHsu TonyCTHsu commented May 19, 2026

What does this PR do?

Adds a new _dd.svc_src tag on spans whose service name has been overridden from the global default service. The value identifies the source of the override: the integration component name (e.g. redis, pg, sidekiq) for Datadog-instrumented spans, or m for manually-instrumented spans.

The tag is set in each contrib alongside the existing span.service = override, and a fallback m value is applied in the span_before_finish hook for any service-overridden span that does not already carry the tag. The tag is removed when the span's service ends up matching the global default service.

This complements the existing _dd.base_service tag, which records the global default service when a span overrides it.

Motivation:

Backends and downstream consumers need to distinguish manually-set service overrides from those applied by Datadog integrations, so they can attribute service-naming behavior correctly.

Change log entry

None.

Additional Notes:

This PR is stacked on top of tonycthsu/before_finish_event — please review and merge that branch first. The fallback m tagging relies on the span_before_finish event introduced there.

How to test the change?

  • Trigger a span via an instrumented integration (e.g. Redis) with a custom service_name configured — span should carry _dd.svc_src = redis.
  • Manually create a span with Tracing.trace('op', service: 'custom') { ... } — span should carry _dd.svc_src = m.
  • Create a span whose service matches the global default service — span should not carry _dd.svc_src.

@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 19, 2026

Thank you for updating Change log entry section 👏

Visited at: 2026-05-19 12:52:01 UTC

@dd-octo-sts dd-octo-sts Bot added integrations Involves tracing integrations tracing labels May 19, 2026
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 19, 2026

Typing analysis

This PR does not change typing compared to the base branch.

@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented May 19, 2026

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 90.37%
Overall Coverage: 97.07% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 539a132 | Docs | Datadog PR Page | Give us feedback!

@TonyCTHsu TonyCTHsu changed the base branch from master to tonycthsu/before_finish_event May 19, 2026 12:13
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/source-attri branch from 426ca31 to cef8ea3 Compare May 19, 2026 12:21
@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented May 19, 2026

Benchmarks

Benchmark execution time: 2026-05-28 08:54:45

Comparing candidate commit 539a132 in PR branch tonycthsu/source-attri with baseline commit b1a5c02 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 45 metrics, 1 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/source-attri branch from cef8ea3 to a4bff46 Compare May 19, 2026 12:47
@TonyCTHsu TonyCTHsu marked this pull request as ready for review May 20, 2026 11:51
@TonyCTHsu TonyCTHsu requested review from a team as code owners May 20, 2026 11:51
@TonyCTHsu TonyCTHsu requested review from marcotc and vpellan and removed request for a team May 20, 2026 11:51
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 32b3f85653

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/datadog/tracing/tracer.rb Outdated
Comment thread spec/datadog/tracing/contrib/svc_src_examples.rb
Base automatically changed from tonycthsu/before_finish_event to master May 21, 2026 12:36
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/source-attri branch from 7638637 to e21c2eb Compare May 22, 2026 08:05
@TonyCTHsu TonyCTHsu requested a review from a team as a code owner May 22, 2026 08:05
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/source-attri branch from e21c2eb to e459e32 Compare May 22, 2026 09:57
TonyCTHsu added 6 commits May 27, 2026 13:28
`reset_subscription_state!` previously cleared the patcher's
`@patch_only_once` flag so the next `Datadog.configure` call would
re-run the patcher and rebuild subscriptions with fresh span options.

This caused ActionCable tests to fail on Ruby 3.4: re-running the
patcher re-includes `Instrumentation::ActionCableChannel` into
`ActionCable::Channel::Base`, which re-fires `included` and appends
duplicate `set_callback` entries every test, accumulating spans.

The helper now takes a block to wrap the caller's `Datadog.configure`,
then explicitly calls `events_module.subscribe!` to refresh subscriptions
without touching `@patch_only_once`. All affected specs are updated to
the new block form with matching `after` cleanup.
The 'service_name is overridden' context configures
`c.tracing.instrument :hanami, service_name: 'custom-hanami'` but
nothing resets it afterwards. Under randomized order, later tests that
expect `tracer.default_service` instead saw 'custom-hanami'.

Hanami tracers read `Datadog.configuration.tracing[:hanami]` at request
time (no ActiveSupport::Notifications subscription cache to refresh), so
a plain `reset_configuration!` in the shared context's `after` hook is
enough — no need for `reset_subscription_state!`.
`reset_subscription_state!` calls `Subscription#unsubscribe_all`, which
goes through `ActiveSupport::Notifications.unsubscribe(subscriber)`.
Fanout's `unsubscribe` does `subscriber.try(:pattern)`.

AS 7.0+ requires `active_support/core_ext/object/try` at the top of
`fanout.rb` itself. AS 6.x does not and relies on the host application
having loaded the core_ext elsewhere (Rails apps do; our test bundle
does not on Ruby 2.6 + AS 6.0.6.1, which surfaces as
`NoMethodError: undefined method 'try' for Fanout::Subscribers::Evented`).

Require `try` lazily inside the helper so AS-free contrib specs
(redis, mongo, net_http, ...) are unaffected.
@TonyCTHsu TonyCTHsu merged commit 66609b0 into master May 28, 2026
585 checks passed
@TonyCTHsu TonyCTHsu deleted the tonycthsu/source-attri branch May 28, 2026 09:54
@dd-octo-sts dd-octo-sts Bot added this to the 2.35.0 milestone May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrations Involves tracing integrations tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants