Skip to content

Update service discovery check #7122

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 4 commits into from
Jun 23, 2025
Merged

Conversation

andrewlock
Copy link
Member

Summary of changes

  • Refactor service discovery check to make it testable
  • Add some additional debug logs
  • Bail out when libdatadog is not available or PInvoking is not supported

Reason for change

We recently noticed that the service discovery supported introduced in #7014 was failing when running dd-trace ci run in CI Visbility scenarios.

This is because the dd-trace tool creates a Tracer instance, so that it can create a TestSession span, and propagate the context to the testhost. With the recent discovery service work, the dd-trace process therefore tries to load the libdatadog library, but the call fails, as we haven't rewritten the PInvokes (because this isn't an instrumented process, we're effectively doing "Manual" instrumentation).

Implementation details

As a workaround, make sure we check to see if we're in an auto-instrumented process by checking that the native tracer dll is loaded. This should give a reliable determination for this scenario. we can also cache the check for use anywhere else we need to use libdatadog.

I put the IsLibDatadogAvailable property on the Libdatadog.NativeInterop type, to try to highlight that it needs checking any time you're assuming libdatadog is there, but I'm open to moving it.

Otherwise, mostly refactored to make the code easier to test.

Test coverage

Added a couple of tests to make sure we skip the instrumentation (instead of erroring, as we would have done before the final fix commit).

The positive case (i.e. that the feature works) is already tested in system tests.

Other details

We don't have tests for the dd-trace ci run commands yet - we should look to add them, but that's out of the scope for this PR. We should do a manual test instead

@andrewlock andrewlock added the area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) label Jun 19, 2025
@andrewlock andrewlock requested review from a team as code owners June 19, 2025 16:38
Copy link
Member Author

Choose a reason for hiding this comment

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

This file moved to ServiceDiscoveryHelpers - when the namespaces are removed Utils was too generic for my liking 😄

@@ -691,22 +691,8 @@ private static void OneTimeSetup(TracerSettings tracerSettings)
// start the heartbeat loop
_heartbeatTimer = new Timer(HeartbeatCallback, state: null, dueTime: TimeSpan.Zero, period: TimeSpan.FromMinutes(1));

if (FrameworkDescription.Instance.OSPlatform == OSPlatformName.Linux && Environment.Is64BitProcess && !Util.EnvironmentHelpers.IsServerlessEnvironment())
Copy link
Member Author

Choose a reason for hiding this comment

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

This code was moved as-is into ServiceDiscoveryHelpers and then refactored to make it easier to test

@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jun 19, 2025

Datadog Report

All test runs cfb7cbe 🔗

2 Total Test Services: 0 Failed, 2 Passed
❄️ 1 with New Flaky

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Test Service View
dd-trace-dotnet 0 0 1 251993 2519 18h 24m 39.24s Link
exploration_tests 0 0 0 22085 3 2m 14.97s Link

@pr-commenter
Copy link

pr-commenter bot commented Jun 20, 2025

Benchmarks

Benchmarks Report for benchmark platform 🐌

Benchmarks for #7122 compared to master:

  • 3 benchmarks are slower, with geometric mean 1.172
  • 42 benchmarks have fewer allocations
  • 5 benchmarks have more allocations

The following thresholds were used for comparing the benchmark speeds:

  • Mann–Whitney U test with statistical test for significance of 5%
  • Only results indicating a difference greater than 10% and 0.3 ns are considered.

Allocation changes below 0.5% are ignored.

Benchmark details

Benchmarks.Trace.ActivityBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.ActivityBenchmark.StartStopWithChild‑netcoreapp3.1 5.75 KB 5.71 KB -41 B -0.71%
Benchmarks.Trace.ActivityBenchmark.StartStopWithChild‑net472 6.09 KB 6.02 KB -64 B -1.05%
Benchmarks.Trace.ActivityBenchmark.StartStopWithChild‑net6.0 5.58 KB 5.5 KB -77 B -1.38%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartStopWithChild net6.0 11.2μs 59.7ns 322ns 0 0 0 5.58 KB
master StartStopWithChild netcoreapp3.1 14.1μs 67.5ns 286ns 0 0 0 5.75 KB
master StartStopWithChild net472 22.1μs 119ns 651ns 1.03 0.411 0.103 6.09 KB
#7122 StartStopWithChild net6.0 10.9μs 57.1ns 274ns 0 0 0 5.5 KB
#7122 StartStopWithChild netcoreapp3.1 14.2μs 74.9ns 367ns 0 0 0 5.71 KB
#7122 StartStopWithChild net472 21.6μs 123ns 842ns 0.919 0.23 0 6.02 KB
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces‑net472 3.33 KB 3.31 KB -23 B -0.69%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 927μs 26.6ns 103ns 0 0 0 2.71 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 1.04ms 404ns 1.56μs 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 1.25ms 357ns 1.38μs 0 0 0 3.33 KB
#7122 WriteAndFlushEnrichedTraces net6.0 924μs 110ns 395ns 0 0 0 2.71 KB
#7122 WriteAndFlushEnrichedTraces netcoreapp3.1 1.03ms 178ns 691ns 0 0 0 2.7 KB
#7122 WriteAndFlushEnrichedTraces net472 1.21ms 212ns 822ns 0 0 0 3.31 KB
Benchmarks.Trace.Asm.AppSecBodyBenchmark - Same speed ✔️ More allocations ⚠️

More allocations ⚠️ in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody‑net472 236.35 KB 239.64 KB 3.28 KB 1.39%
Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody‑net472 239.87 KB 243.15 KB 3.28 KB 1.37%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master AllCycleSimpleBody net6.0 331μs 1.76μs 8.42μs 0 0 0 197.06 KB
master AllCycleSimpleBody netcoreapp3.1 510μs 1.45μs 5.61μs 0 0 0 204.77 KB
master AllCycleSimpleBody net472 436μs 119ns 460ns 36.6 2.16 0 236.35 KB
master AllCycleMoreComplexBody net6.0 338μs 1.76μs 8.8μs 0 0 0 200.56 KB
master AllCycleMoreComplexBody netcoreapp3.1 495μs 987ns 3.56μs 0 0 0 208.18 KB
master AllCycleMoreComplexBody net472 446μs 106ns 412ns 36.6 2.16 0 239.87 KB
master ObjectExtractorSimpleBody net6.0 311ns 1.77ns 12.3ns 0 0 0 280 B
master ObjectExtractorSimpleBody netcoreapp3.1 409ns 1.93ns 8.2ns 0 0 0 272 B
master ObjectExtractorSimpleBody net472 303ns 0.175ns 0.676ns 0.0442 0 0 281 B
master ObjectExtractorMoreComplexBody net6.0 6.52μs 29.5ns 110ns 0 0 0 3.78 KB
master ObjectExtractorMoreComplexBody netcoreapp3.1 7.76μs 36.2ns 140ns 0 0 0 3.69 KB
master ObjectExtractorMoreComplexBody net472 6.66μs 0.89ns 3.33ns 0.599 0 0 3.8 KB
#7122 AllCycleSimpleBody net6.0 332μs 1.12μs 4.21μs 0 0 0 197.59 KB
#7122 AllCycleSimpleBody netcoreapp3.1 494μs 1.76μs 6.8μs 0 0 0 205.35 KB
#7122 AllCycleSimpleBody net472 442μs 134ns 500ns 36.6 2.16 0 239.64 KB
#7122 AllCycleMoreComplexBody net6.0 341μs 275ns 1.07μs 0 0 0 201.1 KB
#7122 AllCycleMoreComplexBody netcoreapp3.1 514μs 1.81μs 6.77μs 0 0 0 208.77 KB
#7122 AllCycleMoreComplexBody net472 455μs 82.9ns 321ns 37.9 2.23 0 243.15 KB
#7122 ObjectExtractorSimpleBody net6.0 319ns 0.219ns 0.818ns 0 0 0 280 B
#7122 ObjectExtractorSimpleBody netcoreapp3.1 395ns 2.06ns 9.66ns 0 0 0 272 B
#7122 ObjectExtractorSimpleBody net472 326ns 0.808ns 3.13ns 0.0446 0 0 281 B
#7122 ObjectExtractorMoreComplexBody net6.0 6.3μs 1.93ns 7.49ns 0 0 0 3.78 KB
#7122 ObjectExtractorMoreComplexBody netcoreapp3.1 7.66μs 36.6ns 146ns 0 0 0 3.69 KB
#7122 ObjectExtractorMoreComplexBody net472 6.85μs 1.14ns 4.41ns 0.582 0 0 3.8 KB
Benchmarks.Trace.Asm.AppSecEncoderBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs‑net6.0 2.16 KB 2.15 KB -11 B -0.51%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EncodeArgs net6.0 73.3μs 263ns 984ns 0 0 0 32.41 KB
master EncodeArgs netcoreapp3.1 95.7μs 36.2ns 130ns 0 0 0 32.4 KB
master EncodeArgs net472 107μs 17.6ns 65.8ns 4.82 0 0 32.51 KB
master EncodeLegacyArgs net6.0 143μs 122ns 472ns 0 0 0 2.16 KB
master EncodeLegacyArgs netcoreapp3.1 197μs 42.5ns 147ns 0 0 0 2.14 KB
master EncodeLegacyArgs net472 261μs 66.8ns 250ns 0 0 0 2.16 KB
#7122 EncodeArgs net6.0 73.3μs 27ns 105ns 0 0 0 32.4 KB
#7122 EncodeArgs netcoreapp3.1 94.3μs 186ns 721ns 0 0 0 32.4 KB
#7122 EncodeArgs net472 105μs 15.5ns 60.2ns 4.75 0 0 32.51 KB
#7122 EncodeLegacyArgs net6.0 147μs 155ns 602ns 0 0 0 2.15 KB
#7122 EncodeLegacyArgs netcoreapp3.1 201μs 262ns 1.02μs 0 0 0 2.14 KB
#7122 EncodeLegacyArgs net472 261μs 28.6ns 111ns 0 0 0 2.16 KB
Benchmarks.Trace.Asm.AppSecWafBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunWafRealisticBenchmark net6.0 271μs 133ns 499ns 0 0 0 4.55 KB
master RunWafRealisticBenchmark netcoreapp3.1 294μs 264ns 989ns 0 0 0 4.48 KB
master RunWafRealisticBenchmark net472 307μs 38.1ns 147ns 0 0 0 4.66 KB
master RunWafRealisticBenchmarkWithAttack net6.0 181μs 80.1ns 300ns 0 0 0 2.24 KB
master RunWafRealisticBenchmarkWithAttack netcoreapp3.1 198μs 104ns 404ns 0 0 0 2.22 KB
master RunWafRealisticBenchmarkWithAttack net472 207μs 45.3ns 169ns 0 0 0 2.28 KB
#7122 RunWafRealisticBenchmark net6.0 272μs 102ns 382ns 0 0 0 4.55 KB
#7122 RunWafRealisticBenchmark netcoreapp3.1 299μs 67.6ns 244ns 0 0 0 4.48 KB
#7122 RunWafRealisticBenchmark net472 307μs 43ns 149ns 0 0 0 4.66 KB
#7122 RunWafRealisticBenchmarkWithAttack net6.0 183μs 15ns 56.1ns 0 0 0 2.24 KB
#7122 RunWafRealisticBenchmarkWithAttack netcoreapp3.1 198μs 474ns 1.84μs 0 0 0 2.22 KB
#7122 RunWafRealisticBenchmarkWithAttack net472 206μs 42.5ns 165ns 0 0 0 2.28 KB
Benchmarks.Trace.AspNetCoreBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendRequest net6.0 61.1μs 29ns 104ns 0 0 0 14.53 KB
master SendRequest netcoreapp3.1 69.9μs 118ns 440ns 0 0 0 17.42 KB
master SendRequest net472 0.0171ns 0.00147ns 0.00551ns 0 0 0 0 b
#7122 SendRequest net6.0 62μs 38.3ns 143ns 0 0 0 14.52 KB
#7122 SendRequest netcoreapp3.1 70.1μs 98.8ns 356ns 0 0 0 17.42 KB
#7122 SendRequest net472 0.00166ns 0.000886ns 0.00331ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Slower ⚠️ More allocations ⚠️

Slower ⚠️ in #7122

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces‑net472 1.154 924,947.10 1,067,584.79
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces‑netcoreapp3.1 1.139 631,437.50 719,360.04 bimodal

More allocations ⚠️ in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces‑net472 55.75 KB 56.77 KB 1.01 KB 1.82%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 645μs 512ns 1.98μs 0 0 0 41.73 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 631μs 1.67μs 6.67μs 0 0 0 41.89 KB
master WriteAndFlushEnrichedTraces net472 923μs 1.93μs 7.2μs 4.46 0 0 55.75 KB
#7122 WriteAndFlushEnrichedTraces net6.0 684μs 821ns 3.18μs 0 0 0 41.78 KB
#7122 WriteAndFlushEnrichedTraces netcoreapp3.1 724μs 4.16μs 31.7μs 0 0 0 41.81 KB
#7122 WriteAndFlushEnrichedTraces net472 1.06ms 5.1μs 20.4μs 8.33 0 0 56.77 KB
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery‑net6.0 1.03 KB 1.02 KB -8 B -0.78%
Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery‑netcoreapp3.1 1.02 KB 1.02 KB -8 B -0.78%
Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery‑net472 995 B 987 B -8 B -0.80%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.99μs 10.2ns 46.8ns 0 0 0 1.03 KB
master ExecuteNonQuery netcoreapp3.1 2.53μs 3.43ns 13.3ns 0 0 0 1.02 KB
master ExecuteNonQuery net472 2.7μs 2.41ns 9.34ns 0.147 0.0134 0 995 B
#7122 ExecuteNonQuery net6.0 1.93μs 9.23ns 38ns 0 0 0 1.02 KB
#7122 ExecuteNonQuery netcoreapp3.1 2.62μs 12.1ns 50ns 0 0 0 1.02 KB
#7122 ExecuteNonQuery net472 2.88μs 4.53ns 17.5ns 0.144 0.0144 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync‑net6.0 1.02 KB 1.01 KB -7 B -0.69%
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync‑net472 1.11 KB 1.1 KB -8 B -0.72%
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync‑netcoreapp3.1 1.09 KB 1.08 KB -8 B -0.74%
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch‑net472 1.05 KB 1.04 KB -8 B -0.76%
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch‑net6.0 1.04 KB 1.03 KB -8 B -0.77%
Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch‑netcoreapp3.1 1.04 KB 1.03 KB -8 B -0.77%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.83μs 5.85ns 22.7ns 0 0 0 1.04 KB
master CallElasticsearch netcoreapp3.1 2.3μs 11.8ns 56.6ns 0 0 0 1.04 KB
master CallElasticsearch net472 3.55μs 3.05ns 11.8ns 0.159 0 0 1.05 KB
master CallElasticsearchAsync net6.0 1.81μs 3.89ns 14.5ns 0 0 0 1.02 KB
master CallElasticsearchAsync netcoreapp3.1 2.35μs 7.26ns 28.1ns 0 0 0 1.09 KB
master CallElasticsearchAsync net472 3.84μs 3.19ns 12.4ns 0.169 0 0 1.11 KB
#7122 CallElasticsearch net6.0 1.81μs 7.32ns 28.4ns 0 0 0 1.03 KB
#7122 CallElasticsearch netcoreapp3.1 2.3μs 8.42ns 29.2ns 0 0 0 1.03 KB
#7122 CallElasticsearch net472 3.59μs 2.85ns 11ns 0.162 0 0 1.04 KB
#7122 CallElasticsearchAsync net6.0 1.84μs 9.36ns 42.9ns 0 0 0 1.01 KB
#7122 CallElasticsearchAsync netcoreapp3.1 2.45μs 7.36ns 28.5ns 0 0 0 1.08 KB
#7122 CallElasticsearchAsync net472 3.69μs 3.36ns 11.6ns 0.167 0 0 1.1 KB
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync‑net6.0 960 B 952 B -8 B -0.83%
Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync‑netcoreapp3.1 960 B 952 B -8 B -0.83%
Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync‑net472 923 B 915 B -8 B -0.87%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net6.0 1.78μs 9.27ns 43.5ns 0 0 0 960 B
master ExecuteAsync netcoreapp3.1 2.29μs 7.45ns 25.8ns 0 0 0 960 B
master ExecuteAsync net472 2.58μs 1.78ns 6.88ns 0.143 0 0 923 B
#7122 ExecuteAsync net6.0 1.86μs 6.75ns 26.1ns 0 0 0 952 B
#7122 ExecuteAsync netcoreapp3.1 2.41μs 6.45ns 25ns 0 0 0 952 B
#7122 ExecuteAsync net472 2.57μs 3.43ns 13.3ns 0.141 0 0 915 B
Benchmarks.Trace.HttpClientBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendAsync net6.0 7.1μs 10.4ns 39ns 0 0 0 2.37 KB
master SendAsync netcoreapp3.1 8.69μs 14.1ns 54.6ns 0 0 0 2.9 KB
master SendAsync net472 12.5μs 10.3ns 38.5ns 0.498 0 0 3.19 KB
#7122 SendAsync net6.0 7.01μs 11.7ns 45.4ns 0 0 0 2.36 KB
#7122 SendAsync netcoreapp3.1 8.63μs 18.9ns 70.8ns 0 0 0 2.9 KB
#7122 SendAsync net472 12.3μs 12ns 46.6ns 0.493 0 0 3.18 KB
Benchmarks.Trace.Iast.StringAspectsBenchmark - Slower ⚠️ More allocations ⚠️

Slower ⚠️ in #7122

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑netcoreapp3.1 1.223 413,700.00 506,100.00

More allocations ⚠️ in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark‑net472 57.34 KB 65.54 KB 8.19 KB 14.29%
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑net6.0 259.96 KB 277.81 KB 17.85 KB 6.87%

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark‑netcoreapp3.1 274.93 KB 258.42 KB -16.5 KB -6.00%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StringConcatBenchmark net6.0 44.6μs 212ns 1.6μs 0 0 0 43.83 KB
master StringConcatBenchmark netcoreapp3.1 47.2μs 224ns 838ns 0 0 0 42.64 KB
master StringConcatBenchmark net472 56.8μs 259ns 968ns 0 0 0 57.34 KB
master StringConcatAspectBenchmark net6.0 458μs 1.08μs 3.89μs 0 0 0 259.96 KB
master StringConcatAspectBenchmark netcoreapp3.1 447μs 6.44μs 63.7μs 0 0 0 274.93 KB
master StringConcatAspectBenchmark net472 410μs 2.07μs 9.27μs 0 0 0 286.72 KB
#7122 StringConcatBenchmark net6.0 44.5μs 238ns 1.22μs 0 0 0 43.93 KB
#7122 StringConcatBenchmark netcoreapp3.1 49.4μs 329ns 3.02μs 0 0 0 42.85 KB
#7122 StringConcatBenchmark net472 56.5μs 196ns 735ns 0 0 0 65.54 KB
#7122 StringConcatAspectBenchmark net6.0 502μs 1.4μs 6.58μs 0 0 0 277.81 KB
#7122 StringConcatAspectBenchmark netcoreapp3.1 507μs 1.06μs 3.98μs 0 0 0 258.42 KB
#7122 StringConcatAspectBenchmark net472 406μs 2.01μs 8.27μs 0 0 0 286.72 KB
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.ILoggerBenchmark.EnrichedLog‑net6.0 1.76 KB 1.7 KB -56 B -3.18%
Benchmarks.Trace.ILoggerBenchmark.EnrichedLog‑netcoreapp3.1 1.76 KB 1.7 KB -56 B -3.18%
Benchmarks.Trace.ILoggerBenchmark.EnrichedLog‑net472 1.69 KB 1.64 KB -56 B -3.31%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.63μs 2.6ns 10.1ns 0 0 0 1.76 KB
master EnrichedLog netcoreapp3.1 3.44μs 4.38ns 17ns 0 0 0 1.76 KB
master EnrichedLog net472 4.05μs 4.83ns 18.7ns 0.265 0 0 1.69 KB
#7122 EnrichedLog net6.0 2.66μs 2.8ns 10.5ns 0 0 0 1.7 KB
#7122 EnrichedLog netcoreapp3.1 3.39μs 16.8ns 77.1ns 0 0 0 1.7 KB
#7122 EnrichedLog net472 3.83μs 2.25ns 8.72ns 0.249 0 0 1.64 KB
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.Log4netBenchmark.EnrichedLog‑net472 4.57 KB 4.52 KB -56 B -1.22%
Benchmarks.Trace.Log4netBenchmark.EnrichedLog‑net6.0 4.37 KB 4.31 KB -56 B -1.28%
Benchmarks.Trace.Log4netBenchmark.EnrichedLog‑netcoreapp3.1 4.37 KB 4.31 KB -58 B -1.33%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 123μs 145ns 563ns 0 0 0 4.37 KB
master EnrichedLog netcoreapp3.1 126μs 330ns 1.24μs 0 0 0 4.37 KB
master EnrichedLog net472 167μs 161ns 603ns 0 0 0 4.57 KB
#7122 EnrichedLog net6.0 123μs 159ns 596ns 0 0 0 4.31 KB
#7122 EnrichedLog netcoreapp3.1 129μs 175ns 631ns 0 0 0 4.31 KB
#7122 EnrichedLog net472 169μs 45.8ns 177ns 0 0 0 4.52 KB
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.NLogBenchmark.EnrichedLog‑net6.0 2.32 KB 2.26 KB -56 B -2.41%
Benchmarks.Trace.NLogBenchmark.EnrichedLog‑netcoreapp3.1 2.32 KB 2.26 KB -56 B -2.41%
Benchmarks.Trace.NLogBenchmark.EnrichedLog‑net472 2.14 KB 2.08 KB -56 B -2.62%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 4.94μs 19.3ns 74.6ns 0 0 0 2.32 KB
master EnrichedLog netcoreapp3.1 6.77μs 22.2ns 79.9ns 0 0 0 2.32 KB
master EnrichedLog net472 7.45μs 8.04ns 31.1ns 0.335 0 0 2.14 KB
#7122 EnrichedLog net6.0 5.12μs 7.49ns 29ns 0 0 0 2.26 KB
#7122 EnrichedLog netcoreapp3.1 6.86μs 14.6ns 56.6ns 0 0 0 2.26 KB
#7122 EnrichedLog net472 7.55μs 5.73ns 22.2ns 0.302 0 0 2.08 KB
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.RedisBenchmark.SendReceive‑net472 1.21 KB 1.2 KB -8 B -0.66%
Benchmarks.Trace.RedisBenchmark.SendReceive‑net6.0 1.21 KB 1.2 KB -8 B -0.66%
Benchmarks.Trace.RedisBenchmark.SendReceive‑netcoreapp3.1 1.21 KB 1.2 KB -8 B -0.66%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendReceive net6.0 2.04μs 10.5ns 49.4ns 0 0 0 1.21 KB
master SendReceive netcoreapp3.1 2.53μs 11.8ns 47.4ns 0 0 0 1.21 KB
master SendReceive net472 3.28μs 2.71ns 10.5ns 0.178 0 0 1.21 KB
#7122 SendReceive net6.0 2.02μs 9.56ns 38.2ns 0 0 0 1.2 KB
#7122 SendReceive netcoreapp3.1 2.61μs 9.45ns 34.1ns 0 0 0 1.2 KB
#7122 SendReceive net472 3.28μs 3.16ns 12.2ns 0.181 0 0 1.2 KB
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.SerilogBenchmark.EnrichedLog‑net472 2.08 KB 2.03 KB -56 B -2.69%
Benchmarks.Trace.SerilogBenchmark.EnrichedLog‑netcoreapp3.1 1.69 KB 1.63 KB -56 B -3.32%
Benchmarks.Trace.SerilogBenchmark.EnrichedLog‑net6.0 1.64 KB 1.58 KB -56 B -3.41%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 4.18μs 0.92ns 3.44ns 0 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 5.64μs 23ns 89.3ns 0 0 0 1.69 KB
master EnrichedLog net472 6.67μs 7.28ns 27.3ns 0.298 0 0 2.08 KB
#7122 EnrichedLog net6.0 4.25μs 7.77ns 30.1ns 0 0 0 1.58 KB
#7122 EnrichedLog netcoreapp3.1 5.48μs 15.5ns 60ns 0 0 0 1.63 KB
#7122 EnrichedLog net472 6.59μs 8.3ns 32.2ns 0.296 0 0 2.03 KB
Benchmarks.Trace.SpanBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑net6.0 704 B 696 B -8 B -1.14%
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑netcoreapp3.1 704 B 696 B -8 B -1.14%
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑net472 666 B 658 B -8 B -1.20%
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net472 586 B 578 B -8 B -1.37%
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net6.0 584 B 576 B -8 B -1.37%
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑netcoreapp3.1 584 B 576 B -8 B -1.37%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 751ns 3.97ns 22.4ns 0 0 0 584 B
master StartFinishSpan netcoreapp3.1 953ns 4.42ns 17.7ns 0 0 0 584 B
master StartFinishSpan net472 914ns 0.809ns 3.13ns 0.0912 0 0 586 B
master StartFinishScope net6.0 918ns 0.479ns 1.73ns 0 0 0 704 B
master StartFinishScope netcoreapp3.1 1.15μs 6.24ns 34.2ns 0 0 0 704 B
master StartFinishScope net472 1.09μs 0.174ns 0.652ns 0.104 0 0 666 B
#7122 StartFinishSpan net6.0 757ns 3.71ns 15.3ns 0 0 0 576 B
#7122 StartFinishSpan netcoreapp3.1 943ns 4.28ns 21.8ns 0 0 0 576 B
#7122 StartFinishSpan net472 895ns 0.652ns 2.44ns 0.0898 0 0 578 B
#7122 StartFinishScope net6.0 908ns 4.33ns 18.9ns 0 0 0 696 B
#7122 StartFinishScope netcoreapp3.1 1.18μs 6ns 28.1ns 0 0 0 696 B
#7122 StartFinishScope net472 1.11μs 1.17ns 4.54ns 0.0995 0 0 658 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Same speed ✔️ Fewer allocations 🎉

Fewer allocations 🎉 in #7122

Benchmark Base Allocated Diff Allocated Change Change %
Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin‑net6.0 704 B 696 B -8 B -1.14%
Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin‑netcoreapp3.1 704 B 696 B -8 B -1.14%
Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin‑net472 666 B 658 B -8 B -1.20%

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net6.0 1.02μs 5.36ns 26.8ns 0 0 0 704 B
master RunOnMethodBegin netcoreapp3.1 1.38μs 2.28ns 8.82ns 0 0 0 704 B
master RunOnMethodBegin net472 1.36μs 0.141ns 0.544ns 0.102 0 0 666 B
#7122 RunOnMethodBegin net6.0 1.02μs 4.74ns 18.4ns 0 0 0 696 B
#7122 RunOnMethodBegin netcoreapp3.1 1.36μs 6.9ns 30.1ns 0 0 0 696 B
#7122 RunOnMethodBegin net472 1.36μs 0.628ns 2.43ns 0.101 0 0 658 B

Copy link
Member Author

Choose a reason for hiding this comment

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

Most of this code is just refactoring, moved from elsewhere to make it easier to test

internal static StoreMetadataResult StoreTracerMetadata(TracerSettings tracerSettings)
{
var platformIsSupported = FrameworkDescription.Instance.OSPlatform == OSPlatformName.Linux && Environment.Is64BitProcess;
var deploymentIsSupported = LibDatadog.NativeInterop.IsLibDatadogAvailable;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the real fix, checking LibDatadog.NativeInterop.IsLibDatadogAvailable instead of purely for serverless env vars

Copy link
Member

@tonyredondo tonyredondo left a comment

Choose a reason for hiding this comment

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

LGTM, just a nit not for this PR, CharSlice can be optimized, currently is allocating in both managed heap and unmanaged heap just for interop, we can use stackalloc when is supported or an array buffer in old frameworks.

@andrewlock andrewlock merged commit 04f852a into master Jun 23, 2025
130 of 131 checks passed
@andrewlock andrewlock deleted the andrew/fix-service-discovery branch June 23, 2025 10:16
@github-actions github-actions bot added this to the vNext-v3 milestone Jun 23, 2025
andrewlock added a commit that referenced this pull request Jun 26, 2025
## Summary of changes

Disabled data pipeline if libdatadog is not available

## Reason for change

Libdatadog is not available in all scenarios e.g. serverless scenarios,
`dd-trace ci run` ([as in this recent
issue](#7122)). We should
not enable data pipeline in these scenarios

## Implementation details

Do not allow enabling data pipeline if libdatadog isn't available

## Test coverage

We have a unit test for IsLibDatadogAvailable, I don't think we need
tests for the value here

## Other details
Fixes some other log messages to remove structured logging variables as
not really necessary.
lucaspimentel pushed a commit that referenced this pull request Jul 1, 2025
## Summary of changes

Disabled data pipeline if libdatadog is not available

## Reason for change

Libdatadog is not available in all scenarios e.g. serverless scenarios,
`dd-trace ci run` ([as in this recent
issue](#7122)). We should
not enable data pipeline in these scenarios

## Implementation details

Do not allow enabling data pipeline if libdatadog isn't available

## Test coverage

We have a unit test for IsLibDatadogAvailable, I don't think we need
tests for the value here

## Other details
Fixes some other log messages to remove structured logging variables as
not really necessary.
chojomok pushed a commit that referenced this pull request Jul 15, 2025
## Summary of changes

- Refactor service discovery check to make it testable
- Add some additional debug logs
- Bail out when libdatadog is not available or PInvoking is not
supported

## Reason for change

We recently
[noticed](https://app.datadoghq.com/error-tracking/unified?query=source%3Adotnet+issue.age%3A%3C%3D3600000+-System.OutOfMemoryException+service%3Ainstrumentation-telemetry-data+version%3A%3E%3D3.0.0.0&issueId=c610d57a-4ab5-11f0-84cd-da7ad0900002&from_ts=1749995650000&to_ts=1750082050000&live=false&monitor_id=156515650&monitor_sub_type=.new%28%29&link_source=monitor_notif)
that the service discovery supported introduced in #7014 was failing
when running `dd-trace ci run` in CI Visbility scenarios.

This is because the `dd-trace` tool creates a `Tracer` instance, so that
it can create a `TestSession` span, and propagate the context to the
testhost. With the recent discovery service work, the `dd-trace` process
therefore tries to load the libdatadog library, but the call fails, as
we haven't rewritten the PInvokes (because this isn't an _instrumented_
process, we're effectively doing "Manual" instrumentation).

## Implementation details

As a workaround, make sure we check to see if we're in an
auto-instrumented process by checking that the native tracer dll is
loaded. This should give a reliable determination for this scenario. we
can also cache the check for use anywhere else we need to use
libdatadog.

I put the `IsLibDatadogAvailable` property on the
`Libdatadog.NativeInterop` type, to try to highlight that it needs
checking any time you're assuming libdatadog is there, but I'm open to
moving it.

Otherwise, mostly refactored to make the code easier to test.

## Test coverage

Added a couple of tests to make sure we _skip_ the instrumentation
(instead of erroring, as we would have done before the final fix
commit).

The positive case (i.e. that the feature works) is already tested in
system tests.

## Other details

We don't have tests for the `dd-trace ci run` commands yet - we should
look to add them, but that's out of the scope for this PR. We should do
a manual test instead
chojomok pushed a commit that referenced this pull request Jul 15, 2025
## Summary of changes

Disabled data pipeline if libdatadog is not available

## Reason for change

Libdatadog is not available in all scenarios e.g. serverless scenarios,
`dd-trace ci run` ([as in this recent
issue](#7122)). We should
not enable data pipeline in these scenarios

## Implementation details

Do not allow enabling data pipeline if libdatadog isn't available

## Test coverage

We have a unit test for IsLibDatadogAvailable, I don't think we need
tests for the value here

## Other details
Fixes some other log messages to remove structured logging variables as
not really necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:ci-visibility area:tools area:tracer The core tracer library (Datadog.Trace, does not include OpenTracing, native code, or integrations) identified-by:telemetry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants