Skip to content

Add "manual" service source#8302

Merged
NachoEchevarria merged 39 commits intomasterfrom
nacho/TrackServiceSourceManual
Mar 19, 2026
Merged

Add "manual" service source#8302
NachoEchevarria merged 39 commits intomasterfrom
nacho/TrackServiceSourceManual

Conversation

@NachoEchevarria
Copy link
Copy Markdown
Collaborator

@NachoEchevarria NachoEchevarria commented Mar 13, 2026

Summary of changes

Add _dd.svc_src: m tracking for manually set service names — via the manual API, OpenTracing, and post-creation Span.ServiceName assignments. OTel service.name from resource attributes and Activity tags is treated as configuration (analogous to DD_SERVICE), not manual instrumentation.

Reason for change

Per the service name source RFC, when a service name is explicitly set by manual instrumentation (API or interceptors), _dd.svc_src must be set to "m". This complements the existing auto-instrumentation sources (e.g., "redis", "http-client") and configuration-driven sources ("opt.service_mapping").

Implementation details

  • Span.cs: Setting ServiceName after span creation now marks source as "m" (or clears it when set to null). The setter is the duck-typed entry point that Datadog.Trace.Manual.dll users call (span.ServiceName = "myService"), making it the natural and correct boundary to tag manual sources. This covers OpenTracing and all manual API paths.
  • StartActiveImplementationIntegration.cs: Manual API bridge passes serviceNameSource: "m" when a service name is provided at span creation.
  • NormalizerTraceProcessor.cs: Bypasses the setter via span.Context.ServiceName to avoid overwriting the source during normalization.
  • OtlpHelpers.cs: Bypasses the setter for both the peer.service/OTLPResourceNoServiceName fallback and service.name tag processing. These are not manual instrumentation.
  • ResourceAttributeProcessorHelper.cs: Bypasses the setter for service.name resource attributes — OTEL_SERVICE_NAME is configuration (analogous to DD_SERVICE), not per-span manual instrumentation.
  • V1 schema: Added .IsOptional("_dd.svc_src") to all V1 SpanMetadataRules. While V1 integrations don't override service names (so integration-driven sources don't appear), the tag can still be present from manual instrumentation.

Test coverage

  • Snapshot updates for OpenTracing and ASM tests.

Other details

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 13, 2026

Snapshots difference summary

The following differences have been observed in committed snapshots. It is meant to help the reviewer.
The diff is simplistic, so please check some files anyway while we improve it.

3 occurrences of :

+      _dd.svc_src: m

1 occurrences of :

+      _dd.svc_src: m,

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 13, 2026

Benchmarks

Benchmark execution time: 2026-03-18 15:20:41

Comparing candidate commit 5b1d13b in PR branch nacho/TrackServiceSourceManual with baseline commit 2a80e17 in branch master.

Found 9 performance improvements and 5 performance regressions! Performance is the same for 160 metrics, 18 unstable metrics.

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody netcoreapp3.1

  • 🟥 execution_time [+10.833ms; +16.155ms] or [+5.455%; +8.135%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody netcoreapp3.1

  • 🟩 execution_time [-22.270ms; -16.586ms] or [-10.211%; -7.605%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1

  • 🟥 execution_time [+21.561ms; +22.424ms] or [+11.932%; +12.410%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • 🟥 execution_time [+29.849ms; +35.059ms] or [+19.023%; +22.344%]
  • 🟥 throughput [-218.678op/s; -172.043op/s] or [-13.397%; -10.540%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 throughput [-154.323op/s; -116.075op/s] or [-9.264%; -6.968%]
  • 🟩 execution_time [-57.878ms; -53.010ms] or [-28.682%; -26.270%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0

  • 🟩 execution_time [-218.929µs; -207.697µs] or [-13.881%; -13.169%]
  • 🟩 throughput [+96.562op/s; +101.788op/s] or [+15.229%; +16.053%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1

  • 🟩 execution_time [-13.658ms; -8.932ms] or [-7.968%; -5.211%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog netcoreapp3.1

  • 🟩 throughput [+8631.826op/s; +10754.116op/s] or [+5.161%; +6.429%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1

  • 🟩 throughput [+15617937.001op/s; +16928840.122op/s] or [+6.935%; +7.518%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net6.0

  • 🟩 execution_time [-15.505ms; -14.713ms] or [-7.178%; -6.811%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net6.0

  • 🟩 execution_time [-16.283ms; -12.060ms] or [-7.616%; -5.641%]

@dd-trace-dotnet-ci-bot
Copy link
Copy Markdown

dd-trace-dotnet-ci-bot bot commented Mar 13, 2026

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8302) and master.

✅ No regressions detected - check the details below

Full Metrics Comparison

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration71.33 ± (71.37 - 71.59) ms70.66 ± (70.66 - 70.93) ms-0.9%
.NET Framework 4.8 - Bailout
duration75.64 ± (75.53 - 75.77) ms74.63 ± (74.43 - 74.74) ms-1.3%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1058.55 ± (1058.16 - 1063.44) ms1055.24 ± (1056.27 - 1064.22) ms-0.3%
.NET Core 3.1 - Baseline
process.internal_duration_ms22.31 ± (22.27 - 22.35) ms22.18 ± (22.15 - 22.20) ms-0.6%
process.time_to_main_ms82.43 ± (82.29 - 82.57) ms80.80 ± (80.66 - 80.95) ms-2.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.90 ± (10.89 - 10.90) MB10.90 ± (10.89 - 10.90) MB-0.0%
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms22.26 ± (22.23 - 22.30) ms22.17 ± (22.14 - 22.21) ms-0.4%
process.time_to_main_ms84.15 ± (84.02 - 84.29) ms83.48 ± (83.31 - 83.66) ms-0.8%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.93 ± (10.93 - 10.94) MB10.94 ± (10.94 - 10.95) MB+0.1%✅⬆️
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms223.99 ± (222.77 - 225.21) ms220.98 ± (219.85 - 222.12) ms-1.3%
process.time_to_main_ms481.26 ± (480.48 - 482.04) ms477.69 ± (477.09 - 478.30) ms-0.7%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed47.15 ± (47.12 - 47.18) MB47.23 ± (47.20 - 47.27) MB+0.2%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.2%
.NET 6 - Baseline
process.internal_duration_ms21.02 ± (20.99 - 21.06) ms20.88 ± (20.85 - 20.90) ms-0.7%
process.time_to_main_ms72.00 ± (71.84 - 72.17) ms70.59 ± (70.45 - 70.72) ms-2.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.62 - 10.62) MB10.65 ± (10.64 - 10.65) MB+0.3%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.93 ± (20.89 - 20.97) ms20.81 ± (20.77 - 20.84) ms-0.6%
process.time_to_main_ms72.61 ± (72.48 - 72.74) ms72.07 ± (71.94 - 72.20) ms-0.7%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.73 ± (10.72 - 10.73) MB10.76 ± (10.75 - 10.76) MB+0.3%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms207.09 ± (205.55 - 208.63) ms207.05 ± (205.13 - 208.97) ms-0.0%
process.time_to_main_ms482.32 ± (481.68 - 482.96) ms478.51 ± (477.83 - 479.19) ms-0.8%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.09 ± (49.04 - 49.14) MB49.06 ± (49.00 - 49.12) MB-0.1%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.0%
.NET 8 - Baseline
process.internal_duration_ms19.26 ± (19.23 - 19.30) ms19.18 ± (19.14 - 19.21) ms-0.5%
process.time_to_main_ms71.03 ± (70.90 - 71.15) ms70.22 ± (70.10 - 70.34) ms-1.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.67 ± (7.66 - 7.67) MB7.68 ± (7.68 - 7.69) MB+0.2%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.28 ± (19.24 - 19.31) ms19.08 ± (19.06 - 19.11) ms-1.0%
process.time_to_main_ms72.66 ± (72.52 - 72.79) ms71.02 ± (70.95 - 71.10) ms-2.3%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.72 ± (7.71 - 7.73) MB7.76 ± (7.75 - 7.78) MB+0.6%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms161.71 ± (160.76 - 162.66) ms161.29 ± (160.25 - 162.34) ms-0.3%
process.time_to_main_ms459.59 ± (459.01 - 460.18) ms454.85 ± (454.35 - 455.36) ms-1.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.44 ± (36.43 - 36.46) MB36.58 ± (36.56 - 36.60) MB+0.4%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.1%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration193.87 ± (193.82 - 194.73) ms198.12 ± (198.18 - 199.08) ms+2.2%✅⬆️
.NET Framework 4.8 - Bailout
duration196.84 ± (196.71 - 197.49) ms199.70 ± (199.59 - 200.43) ms+1.5%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1153.98 ± (1157.03 - 1166.64) ms1166.49 ± (1164.92 - 1172.33) ms+1.1%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms187.96 ± (187.65 - 188.27) ms190.57 ± (190.16 - 190.97) ms+1.4%✅⬆️
process.time_to_main_ms80.85 ± (80.61 - 81.10) ms82.38 ± (82.16 - 82.61) ms+1.9%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.18 ± (16.15 - 16.21) MB16.04 ± (16.02 - 16.06) MB-0.9%
runtime.dotnet.threads.count20 ± (19 - 20)20 ± (20 - 20)+0.4%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms188.29 ± (187.93 - 188.64) ms189.84 ± (189.42 - 190.25) ms+0.8%✅⬆️
process.time_to_main_ms82.32 ± (82.18 - 82.45) ms83.63 ± (83.45 - 83.81) ms+1.6%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.26 ± (16.23 - 16.28) MB16.09 ± (16.06 - 16.12) MB-1.0%
runtime.dotnet.threads.count21 ± (20 - 21)21 ± (21 - 21)+0.4%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms396.19 ± (394.49 - 397.88) ms397.14 ± (395.31 - 398.98) ms+0.2%✅⬆️
process.time_to_main_ms474.53 ± (473.93 - 475.14) ms479.99 ± (479.21 - 480.76) ms+1.1%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed57.86 ± (57.70 - 58.01) MB57.99 ± (57.84 - 58.14) MB+0.2%✅⬆️
runtime.dotnet.threads.count30 ± (29 - 30)30 ± (30 - 30)+0.1%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms192.80 ± (192.38 - 193.22) ms194.55 ± (194.11 - 195.00) ms+0.9%✅⬆️
process.time_to_main_ms70.31 ± (70.15 - 70.47) ms71.33 ± (71.16 - 71.51) ms+1.5%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.18 ± (16.06 - 16.30) MB16.41 ± (16.38 - 16.44) MB+1.4%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)19 ± (19 - 19)+4.1%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms191.71 ± (191.43 - 191.99) ms193.98 ± (193.57 - 194.39) ms+1.2%✅⬆️
process.time_to_main_ms71.09 ± (71.01 - 71.17) ms72.09 ± (71.92 - 72.25) ms+1.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.17 ± (16.03 - 16.31) MB16.15 ± (16.02 - 16.29) MB-0.1%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.6%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms428.17 ± (426.41 - 429.94) ms433.10 ± (431.52 - 434.67) ms+1.2%✅⬆️
process.time_to_main_ms476.75 ± (475.94 - 477.56) ms484.44 ± (483.50 - 485.39) ms+1.6%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed60.31 ± (60.25 - 60.37) MB60.30 ± (60.23 - 60.36) MB-0.0%
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)+0.1%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms190.92 ± (190.53 - 191.32) ms193.51 ± (193.04 - 193.98) ms+1.4%✅⬆️
process.time_to_main_ms70.34 ± (70.13 - 70.55) ms71.00 ± (70.81 - 71.19) ms+0.9%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.71 ± (11.68 - 11.73) MB11.71 ± (11.70 - 11.73) MB+0.0%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.0%
.NET 8 - Bailout
process.internal_duration_ms190.05 ± (189.61 - 190.49) ms194.13 ± (193.55 - 194.72) ms+2.2%✅⬆️
process.time_to_main_ms71.08 ± (70.91 - 71.25) ms72.76 ± (72.53 - 73.00) ms+2.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.80 ± (11.77 - 11.83) MB11.74 ± (11.72 - 11.75) MB-0.5%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)+0.7%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms353.81 ± (352.52 - 355.11) ms362.86 ± (361.33 - 364.40) ms+2.6%✅⬆️
process.time_to_main_ms453.97 ± (453.38 - 454.57) ms462.84 ± (461.83 - 463.85) ms+2.0%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.35 ± (48.32 - 48.38) MB48.39 ± (48.36 - 48.42) MB+0.1%✅⬆️
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)+0.4%✅⬆️
Comparison explanation

Execution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

Duration charts
FakeDbCommand (.NET Framework 4.8)
gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8302) - mean (71ms)  : 69, 73
    master - mean (71ms)  : 70, 73

    section Bailout
    This PR (8302) - mean (75ms)  : 73, 76
    master - mean (76ms)  : 75, 77

    section CallTarget+Inlining+NGEN
    This PR (8302) - mean (1,060ms)  : 1003, 1117
    master - mean (1,061ms)  : 1023, 1099

Loading
FakeDbCommand (.NET Core 3.1)
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8302) - mean (109ms)  : 106, 112
    master - mean (111ms)  : 109, 114

    section Bailout
    This PR (8302) - mean (112ms)  : 110, 114
    master - mean (113ms)  : 111, 114

    section CallTarget+Inlining+NGEN
    This PR (8302) - mean (735ms)  : 718, 751
    master - mean (744ms)  : 724, 764

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8302) - mean (97ms)  : 94, 100
    master - mean (99ms)  : 96, 102

    section Bailout
    This PR (8302) - mean (99ms)  : 97, 101
    master - mean (99ms)  : 97, 101

    section CallTarget+Inlining+NGEN
    This PR (8302) - mean (719ms)  : 675, 763
    master - mean (723ms)  : 676, 769

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8302) - mean (97ms)  : 94, 99
    master - mean (98ms)  : 95, 100

    section Bailout
    This PR (8302) - mean (97ms)  : 96, 98
    master - mean (99ms)  : 98, 101

    section CallTarget+Inlining+NGEN
    This PR (8302) - mean (656ms)  : 633, 678
    master - mean (657ms)  : 634, 681

Loading
HttpMessageHandler (.NET Framework 4.8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8302) - mean (199ms)  : 193, 205
    master - mean (194ms)  : 189, 200

    section Bailout
    This PR (8302) - mean (200ms)  : 196, 204
    master - mean (197ms)  : 193, 201

    section CallTarget+Inlining+NGEN
    This PR (8302) - mean (1,169ms)  : 1116, 1221
    master - mean (1,162ms)  : 1090, 1233

Loading
HttpMessageHandler (.NET Core 3.1)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8302) - mean (282ms)  : 273, 290
    master - mean (277ms)  : 273, 282

    section Bailout
    This PR (8302) - mean (282ms)  : 276, 288
    master - mean (279ms)  : 273, 285

    section CallTarget+Inlining+NGEN
    This PR (8302) - mean (912ms)  : 885, 940
    master - mean (904ms)  : 873, 936

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8302) - mean (274ms)  : 267, 282
    master - mean (271ms)  : 265, 277

    section Bailout
    This PR (8302) - mean (274ms)  : 267, 282
    master - mean (271ms)  : 268, 274

    section CallTarget+Inlining+NGEN
    This PR (8302) - mean (949ms)  : 915, 984
    master - mean (938ms)  : 903, 973

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8302) - mean (275ms)  : 265, 284
    master - mean (271ms)  : 264, 278

    section Bailout
    This PR (8302) - mean (277ms)  : 265, 288
    master - mean (271ms)  : 265, 276

    section CallTarget+Inlining+NGEN
    This PR (8302) - mean (859ms)  : 822, 896
    master - mean (840ms)  : 810, 870

Loading

@NachoEchevarria NachoEchevarria added the area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) label Mar 16, 2026
@NachoEchevarria NachoEchevarria marked this pull request as ready for review March 17, 2026 11:29
@NachoEchevarria NachoEchevarria requested review from a team as code owners March 17, 2026 11:29
if (span.ServiceName is null)
{
span.ServiceName = span.GetTag("peer.service") switch
span.Context.ServiceName = span.GetTag("peer.service") switch
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we going to need to do something to avoid "accidentally" calling these in general, as this is going to be a source of bugs otherwise 🤔

I think we should avoid calling Span.Service entirely 🤔 and do something like the following:

  • Add a new method to Span that requires you provide a source at the same time SetService(string serviceName, string? source)
  • Mark it as [Obsolete("This should not be called directly, instead call SetService() and provide a source"]`
  • Update all our usages to explicitly set the source
  • Keep the Span.Service implementation you have, so that manual instrumentation still works correctly
  • Potentially "fix" SpanContext.ServiceName in the same way, so that you can't "accidentally" not set the source?

WDYT?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that would help avoiding errors in the future, thanks!
I have changed the code. Left SpanContext.ServiceName for now, but I can add it here or in a sugsequent PR. WDYT?

Comment thread tracer/test/Datadog.Trace.TestHelpers/SpanMetadataV1Rules.cs
Comment thread tracer/src/Datadog.Trace/Span.ISpan.cs Outdated
{
get => ServiceName;
set => ServiceName = value;
set => SetService(value, Configuration.Schema.ServiceNameMetadata.Manual);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this code path should probably be the same as the on in Span.cs, though I'm not sure which one is correct 😄

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch!

Comment thread tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/ScopeFactoryTests.cs Outdated
@@ -262,7 +262,7 @@ public void StartActive_NoServiceName_DefaultServiceName()
public void StartActive_SetServiceName_ServiceNameIsSet()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we extend these tests to test the source behaviour too?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure! Done!

@lucaspimentel
Copy link
Copy Markdown
Member

@codex review

Comment thread tracer/src/Datadog.Trace/Span.cs Outdated
Comment thread tracer/src/Datadog.Trace/Span.cs Outdated
[Obsolete("Use SetService(serviceName, source) instead to explicitly provide a source.")]
set
{
Context.ServiceName = value;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Note related to this PR, but why is the service name on SpanContext?! 😓)

@lucaspimentel lucaspimentel changed the title Service source manual Add "manual" service source Mar 18, 2026
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@NachoEchevarria
Copy link
Copy Markdown
Collaborator Author

Thank you for your feedback and reviews!

@NachoEchevarria NachoEchevarria merged commit 2b15f71 into master Mar 19, 2026
140 checks passed
@NachoEchevarria NachoEchevarria deleted the nacho/TrackServiceSourceManual branch March 19, 2026 10:54
@github-actions github-actions bot added this to the vNext-v3 milestone Mar 19, 2026
NachoEchevarria added a commit that referenced this pull request Apr 8, 2026
## Summary of changes

Add `srv_src` field to the client stats payload, propagating the service
name source alongside trace stats.

## Reason for change

Per the [service name source
RFC](https://docs.google.com/document/d/11OnbVYMDK-c5D-_V4QfOvL0Pc0z5oFQFGY3xSI-W7xk/edit?tab=t.0#heading=h.uoivahvmuvbg),
the source must be propagated in both trace and stats payloads. The
trace payload (`_dd.svc_src` span meta) was added in PR #8302. This
completes the implementation by adding `srv_src` at the stats bucket
level.

## Implementation details

- **`StatsAggregationKey.cs`**: Added `ServiceSource` field. It
participates in equality and hash code, so stats with different sources
aggregate into distinct buckets.
- **`StatsAggregator.cs`**: `BuildKey()` now reads
`span.Context.ServiceNameSource` and passes it to the aggregation key.
- **`StatsBuffer.cs`**: `SerializeBucket()` conditionally serializes
`srv_src` when `ServiceSource` is non-null (dynamic map size: 13 with
source, 12 without).

## Test coverage

- `KeyEquality_WithServiceSource`: Verifies that keys with different
sources are not equal.
- `Serialization_WithServiceSource`: Verifies `srv_src` is serialized
when present and absent when null.
- Existing `StatsBufferTests` and `StatsAggregatorTests` updated and
passing.

## Other details

[APMLP-1015](https://datadoghq.atlassian.net/browse/APMLP-1015)

Related agent PR: DataDog/datadog-agent#45982
Reference Java implementation:
DataDog/dd-trace-java#10653

[APMLP-1015]:
https://datadoghq.atlassian.net/browse/APMLP-1015?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants