Skip to content
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

Extract Upper64 bit trace ID from extension response #6041

Merged

Conversation

agocs
Copy link
Contributor

@agocs agocs commented Sep 16, 2024

Summary of changes

I've updated the Lambda extension so it is capable of returning a 128 bit trace ID when a tracer calls the /lambda/start-invocation endpoint in this PR

As per the RFC, the

lower 64 bits in x-datadog-trace-id (decimal) and the higher 64 bits in x-datadog-tags header under _dd.p.tid (hex) tag.

This change modifies the function that calls /lambda/start-invocation, allowing it to pick out the upper 64 bits of the trace ID and set the resulting 128-bit trace ID in the extracted context.

Reason for change

The Lambda Extension may now return a 128 bit trace ID when a Step Function invokes a Lambda Function.

Implementation details

I rewrote LambdaCommon's CreatePlaceholderScope so it uses SpanContextPropagator.Instance.Extract rather than extracting trace context elements one by one.

Test coverage

Added a unit test for 128 bit trace IDs. Fixed existing unit tests so they pass a dictionary of headers to CreatePlaceholderScope. Removed a unit test that only passes SamplingPriority, since a distributed trace with only a sampling priority is hardly a distributed trace at all.

Other details

Backported to 2.x in #6181

@andrewlock
Copy link
Member

andrewlock commented Sep 16, 2024

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing the following branches/commits:

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 shown 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).

gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6041) - mean (69ms)  : 68, 71
     .   : milestone, 69,
    master - mean (70ms)  : 67, 73
     .   : milestone, 70,

    section CallTarget+Inlining+NGEN
    This PR (6041) - mean (1,108ms)  : 1084, 1133
     .   : milestone, 1108,
    master - mean (1,109ms)  : 1084, 1133
     .   : milestone, 1109,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6041) - mean (109ms)  : 106, 112
     .   : milestone, 109,
    master - mean (109ms)  : 106, 111
     .   : milestone, 109,

    section CallTarget+Inlining+NGEN
    This PR (6041) - mean (770ms)  : 754, 786
     .   : milestone, 770,
    master - mean (769ms)  : 749, 790
     .   : milestone, 769,

Loading
gantt
    title Execution time (ms) FakeDbCommand (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6041) - mean (92ms)  : 89, 95
     .   : milestone, 92,
    master - mean (92ms)  : 89, 94
     .   : milestone, 92,

    section CallTarget+Inlining+NGEN
    This PR (6041) - mean (721ms)  : 706, 736
     .   : milestone, 721,
    master - mean (727ms)  : 707, 746
     .   : milestone, 727,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.6.2) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6041) - mean (191ms)  : 187, 195
     .   : milestone, 191,
    master - mean (192ms)  : 188, 196
     .   : milestone, 192,

    section CallTarget+Inlining+NGEN
    This PR (6041) - mean (1,205ms)  : 1178, 1231
     .   : milestone, 1205,
    master - mean (1,203ms)  : 1180, 1226
     .   : milestone, 1203,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6041) - mean (276ms)  : 272, 280
     .   : milestone, 276,
    master - mean (276ms)  : 272, 280
     .   : milestone, 276,

    section CallTarget+Inlining+NGEN
    This PR (6041) - mean (946ms)  : 929, 962
     .   : milestone, 946,
    master - mean (946ms)  : 925, 968
     .   : milestone, 946,

Loading
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6) 
    dateFormat  X
    axisFormat %s
    todayMarker off
    section Baseline
    This PR (6041) - mean (265ms)  : 260, 270
     .   : milestone, 265,
    master - mean (265ms)  : 261, 269
     .   : milestone, 265,

    section CallTarget+Inlining+NGEN
    This PR (6041) - mean (927ms)  : 908, 945
     .   : milestone, 927,
    master - mean (930ms)  : 912, 948
     .   : milestone, 930,

Loading

@datadog-ddstaging
Copy link

datadog-ddstaging bot commented Sep 16, 2024

Datadog Report

Branch report: chris.agocs/parse_128_bit_trace_id_from_lambda_extension
Commit report: 83201d8
Test service: dd-trace-dotnet

✅ 0 Failed, 363186 Passed, 2063 Skipped, 14h 59m 32.05s Total Time

@andrewlock
Copy link
Member

andrewlock commented Sep 16, 2024

Throughput/Crank Report ⚡

Throughput results for AspNetCoreSimpleController comparing the following branches/commits:

Cases where throughput results for the PR are worse than latest master (5% drop or greater), results are shown in red.

Note that these results are based on a single point-in-time result for each branch. For full results, see one of the many, many dashboards!

gantt
    title Throughput Linux x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6041) (11.244M)   : 0, 11244059
    master (11.101M)   : 0, 11100941
    benchmarks/2.9.0 (11.081M)   : 0, 11080577

    section Automatic
    This PR (6041) (7.434M)   : 0, 7434070
    master (7.389M)   : 0, 7389242
    benchmarks/2.9.0 (7.732M)   : 0, 7732233

    section Trace stats
    master (7.528M)   : 0, 7528321

    section Manual
    master (10.986M)   : 0, 10986040

    section Manual + Automatic
    This PR (6041) (6.862M)   : 0, 6862422
    master (6.820M)   : 0, 6819504

    section DD_TRACE_ENABLED=0
    master (10.304M)   : 0, 10304285

Loading
gantt
    title Throughput Linux arm64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6041) (9.777M)   : 0, 9777037
    master (9.728M)   : 0, 9727588
    benchmarks/2.9.0 (9.798M)   : 0, 9798067

    section Automatic
    This PR (6041) (6.768M)   : 0, 6768161
    master (6.463M)   : 0, 6463228

    section Trace stats
    master (6.591M)   : 0, 6591023

    section Manual
    master (9.627M)   : 0, 9627166

    section Manual + Automatic
    This PR (6041) (6.092M)   : 0, 6092230
    master (6.028M)   : 0, 6027833

    section DD_TRACE_ENABLED=0
    master (8.762M)   : 0, 8761785

Loading
gantt
    title Throughput Windows x64 (Total requests) 
    dateFormat  X
    axisFormat %s
    section Baseline
    This PR (6041) (10.002M)   : 0, 10001542
    master (9.966M)   : 0, 9965554
    benchmarks/2.9.0 (10.067M)   : 0, 10067315

    section Automatic
    This PR (6041) (6.758M)   : 0, 6757917
    master (6.494M)   : 0, 6493647
    benchmarks/2.9.0 (7.552M)   : 0, 7552193

    section Trace stats
    master (7.096M)   : 0, 7096492

    section Manual
    master (9.850M)   : 0, 9850046

    section Manual + Automatic
    This PR (6041) (6.245M)   : 0, 6244577
    master (5.952M)   : 0, 5952386

    section DD_TRACE_ENABLED=0
    master (9.119M)   : 0, 9118624

Loading

@andrewlock
Copy link
Member

andrewlock commented Sep 16, 2024

Benchmarks Report for tracer 🐌

Benchmarks for #6041 compared to master:

  • 1 benchmarks are faster, with geometric mean 1.135
  • 2 benchmarks are slower, with geometric mean 1.177
  • All benchmarks have the same 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 ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartStopWithChild net6.0 7.73μs 39.1ns 183ns 0.0112 0.00372 0 5.43 KB
master StartStopWithChild netcoreapp3.1 10μs 53.7ns 364ns 0.0206 0.0103 0 5.62 KB
master StartStopWithChild net472 16.6μs 67.7ns 262ns 1.01 0.295 0.0928 6.07 KB
#6041 StartStopWithChild net6.0 7.85μs 44ns 308ns 0.0169 0.00847 0 5.43 KB
#6041 StartStopWithChild netcoreapp3.1 9.56μs 52.4ns 323ns 0.0187 0.00933 0 5.62 KB
#6041 StartStopWithChild net472 16.4μs 52.3ns 202ns 1.02 0.316 0.0973 6.06 KB
Benchmarks.Trace.AgentWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 475μs 187ns 726ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 654μs 201ns 753ns 0 0 0 2.7 KB
master WriteAndFlushEnrichedTraces net472 836μs 409ns 1.58μs 0.417 0 0 3.3 KB
#6041 WriteAndFlushEnrichedTraces net6.0 482μs 189ns 732ns 0 0 0 2.7 KB
#6041 WriteAndFlushEnrichedTraces netcoreapp3.1 643μs 366ns 1.32μs 0 0 0 2.7 KB
#6041 WriteAndFlushEnrichedTraces net472 839μs 518ns 1.94μs 0.419 0 0 3.3 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 193μs 1.04μs 6.35μs 0.195 0 0 18.45 KB
master SendRequest netcoreapp3.1 233μs 1.27μs 7.6μs 0.227 0 0 20.61 KB
master SendRequest net472 0.0013ns 0.000284ns 0.000982ns 0 0 0 0 b
#6041 SendRequest net6.0 214μs 1.19μs 7.63μs 0.195 0 0 18.45 KB
#6041 SendRequest netcoreapp3.1 222μs 1.28μs 9.82μs 0.224 0 0 20.61 KB
#6041 SendRequest net472 0.000658ns 0.000309ns 0.00116ns 0 0 0 0 b
Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master WriteAndFlushEnrichedTraces net6.0 594μs 3.36μs 22.5μs 0.581 0 0 41.62 KB
master WriteAndFlushEnrichedTraces netcoreapp3.1 705μs 3.69μs 21.2μs 0.363 0 0 41.82 KB
master WriteAndFlushEnrichedTraces net472 861μs 3.37μs 12.6μs 8.13 2.57 0.428 53.31 KB
#6041 WriteAndFlushEnrichedTraces net6.0 580μs 3.2μs 19.2μs 0.587 0 0 41.63 KB
#6041 WriteAndFlushEnrichedTraces netcoreapp3.1 664μs 2.36μs 8.51μs 0.334 0 0 41.87 KB
#6041 WriteAndFlushEnrichedTraces net472 860μs 4.46μs 21.4μs 8.45 2.53 0.422 53.32 KB
Benchmarks.Trace.DbCommandBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteNonQuery net6.0 1.23μs 1.2ns 4.66ns 0.0142 0 0 1.02 KB
master ExecuteNonQuery netcoreapp3.1 1.73μs 1.66ns 6.44ns 0.0138 0 0 1.02 KB
master ExecuteNonQuery net472 2.11μs 1.25ns 4.69ns 0.157 0 0 987 B
#6041 ExecuteNonQuery net6.0 1.36μs 1.76ns 6.8ns 0.0142 0 0 1.02 KB
#6041 ExecuteNonQuery netcoreapp3.1 1.74μs 1.84ns 7.12ns 0.014 0 0 1.02 KB
#6041 ExecuteNonQuery net472 2.13μs 1.87ns 6.98ns 0.156 0 0 987 B
Benchmarks.Trace.ElasticsearchBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master CallElasticsearch net6.0 1.23μs 0.363ns 1.36ns 0.0138 0 0 976 B
master CallElasticsearch netcoreapp3.1 1.52μs 1.38ns 5.36ns 0.0129 0 0 976 B
master CallElasticsearch net472 2.55μs 2.36ns 8.51ns 0.158 0 0 995 B
master CallElasticsearchAsync net6.0 1.2μs 0.922ns 3.57ns 0.0132 0 0 952 B
master CallElasticsearchAsync netcoreapp3.1 1.68μs 1.46ns 5.66ns 0.0135 0 0 1.02 KB
master CallElasticsearchAsync net472 2.74μs 2.61ns 10.1ns 0.167 0 0 1.05 KB
#6041 CallElasticsearch net6.0 1.23μs 0.483ns 1.81ns 0.0135 0 0 976 B
#6041 CallElasticsearch netcoreapp3.1 1.63μs 0.6ns 2.32ns 0.0131 0 0 976 B
#6041 CallElasticsearch net472 2.49μs 1.66ns 6.43ns 0.158 0 0 995 B
#6041 CallElasticsearchAsync net6.0 1.25μs 0.541ns 2.02ns 0.013 0 0 952 B
#6041 CallElasticsearchAsync netcoreapp3.1 1.67μs 1.18ns 4.4ns 0.0135 0 0 1.02 KB
#6041 CallElasticsearchAsync net472 2.49μs 3.58ns 13.9ns 0.167 0 0 1.05 KB
Benchmarks.Trace.GraphQLBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master ExecuteAsync net6.0 1.15μs 0.615ns 2.3ns 0.0132 0 0 952 B
master ExecuteAsync netcoreapp3.1 1.58μs 1.75ns 6.79ns 0.0126 0 0 952 B
master ExecuteAsync net472 1.89μs 2.39ns 9.24ns 0.145 0 0 915 B
#6041 ExecuteAsync net6.0 1.25μs 1.54ns 5.77ns 0.0132 0 0 952 B
#6041 ExecuteAsync netcoreapp3.1 1.65μs 0.478ns 1.79ns 0.0125 0 0 952 B
#6041 ExecuteAsync net472 1.8μs 0.574ns 2.22ns 0.145 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 4.1μs 3.69ns 13.8ns 0.0307 0 0 2.22 KB
master SendAsync netcoreapp3.1 5.1μs 2.99ns 11.2ns 0.0383 0 0 2.76 KB
master SendAsync net472 7.77μs 4.9ns 19ns 0.497 0 0 3.15 KB
#6041 SendAsync net6.0 4.09μs 1.3ns 5.05ns 0.0309 0 0 2.22 KB
#6041 SendAsync netcoreapp3.1 5.07μs 3.32ns 12.9ns 0.0381 0 0 2.76 KB
#6041 SendAsync net472 7.87μs 0.829ns 3.1ns 0.497 0 0 3.15 KB
Benchmarks.Trace.ILoggerBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 1.46μs 1.48ns 5.75ns 0.0228 0 0 1.64 KB
master EnrichedLog netcoreapp3.1 2.11μs 1.17ns 4.39ns 0.0222 0 0 1.64 KB
master EnrichedLog net472 2.7μs 1.18ns 4.56ns 0.249 0 0 1.57 KB
#6041 EnrichedLog net6.0 1.45μs 0.749ns 2.8ns 0.0232 0 0 1.64 KB
#6041 EnrichedLog netcoreapp3.1 2.25μs 1.61ns 6.03ns 0.0224 0 0 1.64 KB
#6041 EnrichedLog net472 2.73μs 0.626ns 2.34ns 0.25 0 0 1.57 KB
Benchmarks.Trace.Log4netBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 118μs 206ns 797ns 0.0582 0 0 4.28 KB
master EnrichedLog netcoreapp3.1 121μs 190ns 712ns 0 0 0 4.28 KB
master EnrichedLog net472 152μs 170ns 660ns 0.677 0.226 0 4.46 KB
#6041 EnrichedLog net6.0 118μs 155ns 559ns 0.0598 0 0 4.28 KB
#6041 EnrichedLog netcoreapp3.1 123μs 129ns 498ns 0 0 0 4.28 KB
#6041 EnrichedLog net472 152μs 237ns 917ns 0.679 0.226 0 4.46 KB
Benchmarks.Trace.NLogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 3.04μs 2.33ns 9.02ns 0.0304 0 0 2.2 KB
master EnrichedLog netcoreapp3.1 4.32μs 2.58ns 9.98ns 0.0281 0 0 2.2 KB
master EnrichedLog net472 4.93μs 8.04ns 31.1ns 0.318 0 0 2.02 KB
#6041 EnrichedLog net6.0 3.08μs 0.761ns 2.95ns 0.0294 0 0 2.2 KB
#6041 EnrichedLog netcoreapp3.1 4.26μs 1.67ns 6.48ns 0.0297 0 0 2.2 KB
#6041 EnrichedLog net472 4.94μs 1.07ns 4.01ns 0.32 0 0 2.02 KB
Benchmarks.Trace.RedisBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master SendReceive net6.0 1.45μs 0.623ns 2.41ns 0.0159 0 0 1.14 KB
master SendReceive netcoreapp3.1 1.76μs 0.624ns 2.33ns 0.0151 0 0 1.14 KB
master SendReceive net472 2.09μs 1.39ns 5.37ns 0.183 0.00104 0 1.16 KB
#6041 SendReceive net6.0 1.39μs 0.525ns 1.96ns 0.016 0 0 1.14 KB
#6041 SendReceive netcoreapp3.1 1.73μs 0.554ns 2.07ns 0.0155 0 0 1.14 KB
#6041 SendReceive net472 2.14μs 1.84ns 6.89ns 0.183 0.00107 0 1.16 KB
Benchmarks.Trace.SerilogBenchmark - Same speed ✔️ Same allocations ✔️

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master EnrichedLog net6.0 2.8μs 1.09ns 4.22ns 0.0224 0 0 1.6 KB
master EnrichedLog netcoreapp3.1 3.86μs 1.62ns 6.29ns 0.0213 0 0 1.65 KB
master EnrichedLog net472 4.6μs 2.89ns 11.2ns 0.323 0 0 2.04 KB
#6041 EnrichedLog net6.0 3.04μs 1.26ns 4.56ns 0.0212 0 0 1.6 KB
#6041 EnrichedLog netcoreapp3.1 4.06μs 2.8ns 10.9ns 0.0223 0 0 1.65 KB
#6041 EnrichedLog net472 4.42μs 3.13ns 11.7ns 0.322 0 0 2.04 KB
Benchmarks.Trace.SpanBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6041

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishSpan‑net6.0 1.204 399.98 481.52

Faster 🎉 in #6041

Benchmark base/diff Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.SpanBenchmark.StartFinishScope‑net6.0 1.135 557.61 491.38

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master StartFinishSpan net6.0 400ns 0.175ns 0.655ns 0.00807 0 0 576 B
master StartFinishSpan netcoreapp3.1 595ns 0.31ns 1.16ns 0.00798 0 0 576 B
master StartFinishSpan net472 667ns 0.434ns 1.62ns 0.0916 0 0 578 B
master StartFinishScope net6.0 558ns 0.48ns 1.86ns 0.00976 0 0 696 B
master StartFinishScope netcoreapp3.1 737ns 0.788ns 3.05ns 0.0093 0 0 696 B
master StartFinishScope net472 851ns 0.757ns 2.83ns 0.104 0 0 658 B
#6041 StartFinishSpan net6.0 482ns 0.16ns 0.598ns 0.008 0 0 576 B
#6041 StartFinishSpan netcoreapp3.1 617ns 0.827ns 3.2ns 0.00792 0 0 576 B
#6041 StartFinishSpan net472 704ns 0.303ns 1.17ns 0.0916 0 0 578 B
#6041 StartFinishScope net6.0 492ns 0.216ns 0.838ns 0.00965 0 0 696 B
#6041 StartFinishScope netcoreapp3.1 732ns 1.37ns 5.31ns 0.00951 0 0 696 B
#6041 StartFinishScope net472 888ns 0.906ns 3.51ns 0.104 0 0 658 B
Benchmarks.Trace.TraceAnnotationsBenchmark - Slower ⚠️ Same allocations ✔️

Slower ⚠️ in #6041

Benchmark diff/base Base Median (ns) Diff Median (ns) Modality
Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin‑net6.0 1.150 593.66 682.98

Raw results

Branch Method Toolchain Mean StdError StdDev Gen 0 Gen 1 Gen 2 Allocated
master RunOnMethodBegin net6.0 594ns 0.286ns 1.11ns 0.00978 0 0 696 B
master RunOnMethodBegin netcoreapp3.1 949ns 1.54ns 5.78ns 0.00934 0 0 696 B
master RunOnMethodBegin net472 1.15μs 0.353ns 1.37ns 0.104 0 0 658 B
#6041 RunOnMethodBegin net6.0 682ns 0.751ns 2.91ns 0.00984 0 0 696 B
#6041 RunOnMethodBegin netcoreapp3.1 906ns 0.853ns 3.31ns 0.00939 0 0 696 B
#6041 RunOnMethodBegin net472 1.15μs 0.492ns 1.77ns 0.104 0 0 658 B

scope.Should().NotBeNull();
scope.Span.TraceId128.Should().Be((TraceId)1234);
((ISpan)scope.Span).TraceId.Should().Be(1234);
scope.Span.SpanId.Should().BeGreaterThan(0);
}

[Fact]
public async Task TestCreatePlaceholderScopeSuccessWithSamplingPriorityOnly()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wound up removing this test since dd-trace doesn't seem to allow a distributed trace with no trace ID.

Copy link
Member

Choose a reason for hiding this comment

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

That's right. A trace id is required when extracting trace context from headers, otherwise we ignore all the other data. But what changed here? Are we now trying to propagate trace context without a trace id?

Copy link
Member

Choose a reason for hiding this comment

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

But what changed here?

Oh, I see. The null in LambdaCommon.CreatePlaceholderScope(tracer, null, "-1") below was the trace id, and it was handled differently since the previous code was not using SpanContextPropagator.


scope.Should().NotBeNull();
scope.Span.TraceId128.Should().Be((TraceId)1234);
((ISpan)scope.Span).TraceId.Should().Be(1234);
scope.Span.TraceId128.ToString().Should().Be("1914fe7789eb32be4fb6f07e011a6faf");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This value agrees with dd-trace-java

Copy link
Member

Choose a reason for hiding this comment

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

Confirmed that 1914fe7789eb32be4fb6f07e011a6faf has

  • 1914fe7789eb32be in the upper 64 bits
  • 4fb6f07e011a6faf (5744042798732701615) in the lower 64 bits

@agocs agocs marked this pull request as ready for review September 30, 2024 13:51
@agocs agocs requested review from a team as code owners September 30, 2024 13:51
@bouwkast
Copy link
Contributor

Could you fill out the PR description?

@agocs
Copy link
Contributor Author

agocs commented Sep 30, 2024

@bouwkast Yep! My mistake

agocs added 2 commits October 1, 2024 10:10
…n' of github.com:DataDog/dd-trace-dotnet into chris.agocs/parse_128_bit_trace_id_from_lambda_extension
@agocs
Copy link
Contributor Author

agocs commented Oct 1, 2024

Figuring out the null references in the tests...

@agocs
Copy link
Contributor Author

agocs commented Oct 4, 2024

I cherry-picked from this branch back into this branch 🤦. I think no damage was done

agocs added 2 commits October 8, 2024 09:15
…n' of github.com:DataDog/dd-trace-dotnet into chris.agocs/parse_128_bit_trace_id_from_lambda_extension

This comment was marked as outdated.

@agocs agocs mentioned this pull request Oct 9, 2024
@lucaspimentel lucaspimentel requested review from lucaspimentel and removed request for lucaspimentel October 15, 2024 15:34
@lucaspimentel lucaspimentel dismissed their stale review October 15, 2024 15:36

Andrew found some issues I missed

@lucaspimentel lucaspimentel requested a review from a team October 15, 2024 15:37
@lucaspimentel lucaspimentel requested a review from a team October 22, 2024 16:59
Copy link
Contributor

@bouwkast bouwkast left a comment

Choose a reason for hiding this comment

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

Just a nitpick but looks good to me!

Log($"setting the placeholder sampling priority to = {samplingPriority}");
span.Context.TraceContext?.SetSamplingPriority(Convert.ToInt32(samplingPriority), notifyDistributedTracer: false);
}
var span = spanContext != null ? tracer.StartSpan(PlaceholderOperationName, tags: null, parent: spanContext, serviceName: PlaceholderServiceName, addToTraceContext: false) : tracer.StartSpan(PlaceholderOperationName, tags: null, serviceName: PlaceholderServiceName, addToTraceContext: false);
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick

Suggested change
var span = spanContext != null ? tracer.StartSpan(PlaceholderOperationName, tags: null, parent: spanContext, serviceName: PlaceholderServiceName, addToTraceContext: false) : tracer.StartSpan(PlaceholderOperationName, tags: null, serviceName: PlaceholderServiceName, addToTraceContext: false);
var span = tracer.StartSpan(PlaceholderOperationName, tags: null, parent: spanContext, serviceName: PlaceholderServiceName, addToTraceContext: false);

I don't think the spanContext != null is necessary as we'll always be calling the same StartSpan function and parent can be set to null - that is the default value.

@bouwkast bouwkast merged commit 0c611c8 into master Oct 22, 2024
76 checks passed
@bouwkast bouwkast deleted the chris.agocs/parse_128_bit_trace_id_from_lambda_extension branch October 22, 2024 20:12
@github-actions github-actions bot added this to the vNext-v3 milestone Oct 22, 2024
agocs added a commit that referenced this pull request Oct 22, 2024
## Summary of changes

I've updated the Lambda extension so it is capable of returning a 128
bit trace ID when a tracer calls the `/lambda/start-invocation` endpoint
[in this PR](DataDog/datadog-agent#27988)

As per [the
RFC](https://datadoghq.atlassian.net/wiki/spaces/RUMP/pages/3545630931/RFC+Support+128+bit+trace+IDs+in+RUM+SDKs#:~:text=For%20Datadog%20headers%2C%20the%20128%20bit%20trace%20id%20is%20sent%20in%20two%20parts%2C%20lower%2064%20bits%20in%20x%2Ddatadog%2Dtrace%2Did%20(decimal)%20and%20the%20higher%2064%20bits%20in%20x%2Ddatadog%2Dtags%20header%20under%20_dd.p.tid%20(hex)%20tag),
the

> lower 64 bits in `x-datadog-trace-id` (decimal) and the higher 64 bits
in `x-datadog-tags` header under `_dd.p.tid` (hex) tag.

This change modifies the function that calls `/lambda/start-invocation`,
allowing it to pick out the upper 64 bits of the trace ID and set the
resulting 128-bit trace ID in the extracted context.


## Reason for change

The Lambda Extension may now return a 128 bit trace ID when a Step
Function invokes a Lambda Function.

## Implementation details

I rewrote LambdaCommon's `CreatePlaceholderScope` so it uses
`SpanContextPropagator.Instance.Extract` rather than extracting trace
context elements one by one.

## Test coverage

Added a unit test for 128 bit trace IDs. Fixed existing unit tests so
they pass a dictionary of headers to CreatePlaceholderScope. Removed a
unit test that only passes SamplingPriority, since a distributed trace
with only a sampling priority is hardly a distributed trace at all.

## Other details
Backported to 2.x in (TODO)
<!-- Fixes #{issue} -->

<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->

---------

Co-authored-by: Lucas Pimentel <[email protected]>
Co-authored-by: Andrew Lock <[email protected]>
Co-authored-by: Daniel Romano <[email protected]>
Co-authored-by: Steven Bouwkamp <[email protected]>
Co-authored-by: Anna <[email protected]>
Co-authored-by: NachoEchevarria <[email protected]>
Co-authored-by: William Conti <[email protected]>
Co-authored-by: Kevin Gosse <[email protected]>
Co-authored-by: Tony Redondo <[email protected]>
Co-authored-by: Gregory LEOCADIE <[email protected]>
@lucaspimentel lucaspimentel added the type:enhancement Improvement to an existing feature label Oct 22, 2024
bouwkast added a commit that referenced this pull request Oct 22, 2024
…6181)

## Summary of changes

I've updated the Lambda extension so it is capable of returning a 128
bit trace ID when a tracer calls the `/lambda/start-invocation` endpoint
[in this PR](DataDog/datadog-agent#27988)

As per [the

RFC](https://datadoghq.atlassian.net/wiki/spaces/RUMP/pages/3545630931/RFC+Support+128+bit+trace+IDs+in+RUM+SDKs#:~:text=For%20Datadog%20headers%2C%20the%20128%20bit%20trace%20id%20is%20sent%20in%20two%20parts%2C%20lower%2064%20bits%20in%20x%2Ddatadog%2Dtrace%2Did%20(decimal)%20and%20the%20higher%2064%20bits%20in%20x%2Ddatadog%2Dtags%20header%20under%20_dd.p.tid%20(hex)%20tag),
the

> lower 64 bits in `x-datadog-trace-id` (decimal) and the higher 64 bits
in `x-datadog-tags` header under `_dd.p.tid` (hex) tag.

This change modifies the function that calls `/lambda/start-invocation`,
allowing it to pick out the upper 64 bits of the trace ID and set the
resulting 128-bit trace ID in the extracted context.


## Reason for change

The Lambda Extension may now return a 128 bit trace ID when a Step
Function invokes a Lambda Function.

## Implementation details

I rewrote LambdaCommon's `CreatePlaceholderScope` so it uses
`SpanContextPropagator.Instance.Extract` rather than extracting trace
context elements one by one.

## Test coverage

Added a unit test for 128 bit trace IDs. Fixed existing unit tests so
they pass a dictionary of headers to CreatePlaceholderScope. Removed a
unit test that only passes SamplingPriority, since a distributed trace
with only a sampling priority is hardly a distributed trace at all.

## Other details
Backport to 2.x of #6041
<!-- Fixes #{issue} -->

<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->

---------

Co-authored-by: Lucas Pimentel <[email protected]>
Co-authored-by: Andrew Lock <[email protected]>
Co-authored-by: Daniel Romano <[email protected]>
Co-authored-by: Steven Bouwkamp <[email protected]>
Co-authored-by: Anna <[email protected]>
Co-authored-by: NachoEchevarria <[email protected]>
Co-authored-by: William Conti <[email protected]>
Co-authored-by: Kevin Gosse <[email protected]>
Co-authored-by: Tony Redondo <[email protected]>
Co-authored-by: Gregory LEOCADIE <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.