Skip to content

Refactor Azure Functions instrumentation before #7628#8079

Merged
lucaspimentel merged 12 commits intomasterfrom
lpimentel/APMSVLS-58-azfunc-host-parenting-pre-cleanup
Jan 27, 2026
Merged

Refactor Azure Functions instrumentation before #7628#8079
lucaspimentel merged 12 commits intomasterfrom
lpimentel/APMSVLS-58-azfunc-host-parenting-pre-cleanup

Conversation

@lucaspimentel
Copy link
Member

@lucaspimentel lucaspimentel commented Jan 16, 2026

Summary of changes

Refactor Azure Functions instrumentation code as a precursor to #7628.

Reason for change

The changes in #7628 were building up, so I decided to split them into two PRs. This PR is mostly cleanup and refactoring. No functional changes.

Implementation details

Environment detection helpers (EnvironmentHelpers)

  • Added IsAzureFunctionsIsolated() - detects isolated worker runtime
  • Added GetAzureFunctionsWorkerRuntime() - retrieves worker runtime value
  • Added GetAzureFunctionsExtensionVersion() - retrieves extension version
  • Refactored IsRunningInAzureFunctionsHost() to use new helpers

Diagnostic observer initialization (Instrumentation)

  • Extracted GetAspNetCoreDiagnosticObserver()
  • Extracted SkipAspNetCoreDiagnosticObserver()

Azure Functions instrumentation cleanup (AzureFunctionsCommon)

  • Renamed parameter context to functionContext for clarity and consistency
  • Made CreateIsolatedFunctionScope() private
  • Formatting: improved comment alignment and whitespace
  • Changed if to switch for trigger type handling

ASP.NET Core tracking key rename

  • Renamed HttpContextItemsKey to HttpContextTrackingKey across all usages (will add another key in next PR, needed to distinguish them since they are both "item keys")

Test coverage

No new tests added - this is a refactoring/cleanup PR with no functional changes. Existing Azure Functions tests provide coverage.

Other details

Precursor to #7628 - Fix span parenting for isolated Azure Functions using ASP.NET Core integration

@lucaspimentel lucaspimentel force-pushed the lpimentel/APMSVLS-58-azfunc-host-parenting-pre-cleanup branch 2 times, most recently from bdae1c7 to 67e423e Compare January 20, 2026 20:15
@lucaspimentel lucaspimentel changed the title cleanup before apmsvls 58 azfunc host parenting code cleanup/refactoring before #7628 Jan 20, 2026
@lucaspimentel lucaspimentel changed the title code cleanup/refactoring before #7628 Refactor Azure Functions instrumentation for improved clarity Jan 20, 2026
@lucaspimentel lucaspimentel force-pushed the lpimentel/APMSVLS-58-azfunc-host-parenting-pre-cleanup branch 3 times, most recently from cb6304f to ddd2357 Compare January 20, 2026 21:40
@dd-trace-dotnet-ci-bot
Copy link

dd-trace-dotnet-ci-bot bot commented Jan 20, 2026

Execution-Time Benchmarks Report ⏱️

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

⚠️ Potential regressions detected

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration68.48 ± (68.49 - 68.75) ms77.75 ± (77.70 - 78.09) ms+13.5%❌⬆️
.NET Framework 4.8 - Bailout
duration72.33 ± (72.20 - 72.41) ms82.63 ± (82.45 - 82.87) ms+14.2%❌⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1005.41 ± (1014.39 - 1025.33) ms1087.91 ± (1088.85 - 1098.03) ms+8.2%❌⬆️
Full Metrics Comparison

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration68.48 ± (68.49 - 68.75) ms77.75 ± (77.70 - 78.09) ms+13.5%❌⬆️
.NET Framework 4.8 - Bailout
duration72.33 ± (72.20 - 72.41) ms82.63 ± (82.45 - 82.87) ms+14.2%❌⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1005.41 ± (1014.39 - 1025.33) ms1087.91 ± (1088.85 - 1098.03) ms+8.2%❌⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms21.86 ± (21.84 - 21.89) ms24.14 ± (24.09 - 24.20) ms+10.4%✅⬆️
process.time_to_main_ms79.07 ± (78.91 - 79.24) ms92.57 ± (92.35 - 92.79) ms+17.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.91 ± (10.91 - 10.92) MB10.91 ± (10.90 - 10.91) MB-0.1%
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms21.82 ± (21.80 - 21.84) ms23.88 ± (23.83 - 23.94) ms+9.5%✅⬆️
process.time_to_main_ms80.23 ± (80.12 - 80.34) ms93.16 ± (92.90 - 93.41) ms+16.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.95 ± (10.95 - 10.96) MB10.97 ± (10.96 - 10.97) MB+0.2%✅⬆️
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms242.15 ± (238.49 - 245.81) ms240.73 ± (237.06 - 244.39) ms-0.6%
process.time_to_main_ms468.08 ± (467.57 - 468.60) ms523.96 ± (523.16 - 524.76) ms+11.9%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.34 ± (48.31 - 48.37) MB48.26 ± (48.23 - 48.29) MB-0.2%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.2%
.NET 6 - Baseline
process.internal_duration_ms20.71 ± (20.68 - 20.74) ms22.84 ± (22.78 - 22.90) ms+10.3%✅⬆️
process.time_to_main_ms68.33 ± (68.24 - 68.43) ms81.18 ± (80.98 - 81.39) ms+18.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.61 - 10.62) MB10.64 ± (10.64 - 10.64) MB+0.2%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.62 ± (20.60 - 20.64) ms22.56 ± (22.50 - 22.62) ms+9.4%✅⬆️
process.time_to_main_ms69.59 ± (69.53 - 69.66) ms81.96 ± (81.75 - 82.18) ms+17.8%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.73 ± (10.72 - 10.74) MB10.75 ± (10.74 - 10.75) MB+0.2%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms248.52 ± (246.84 - 250.21) ms235.62 ± (231.31 - 239.93) ms-5.2%
process.time_to_main_ms446.84 ± (446.41 - 447.27) ms497.58 ± (496.82 - 498.35) ms+11.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.26 ± (49.24 - 49.29) MB49.02 ± (49.00 - 49.04) MB-0.5%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms18.84 ± (18.82 - 18.87) ms20.55 ± (20.50 - 20.60) ms+9.0%✅⬆️
process.time_to_main_ms67.56 ± (67.44 - 67.68) ms78.66 ± (78.45 - 78.87) ms+16.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.66 ± (7.65 - 7.66) MB7.67 ± (7.67 - 7.68) MB+0.2%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.87 ± (18.85 - 18.89) ms20.59 ± (20.53 - 20.65) ms+9.1%✅⬆️
process.time_to_main_ms68.62 ± (68.56 - 68.67) ms79.73 ± (79.53 - 79.93) ms+16.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.75 ± (7.73 - 7.76) MB7.72 ± (7.71 - 7.74) MB-0.3%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms178.45 ± (177.56 - 179.34) ms197.83 ± (197.00 - 198.66) ms+10.9%✅⬆️
process.time_to_main_ms429.97 ± (429.42 - 430.51) ms474.89 ± (473.88 - 475.91) ms+10.4%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.51 ± (36.48 - 36.54) MB36.97 ± (36.93 - 37.02) MB+1.3%✅⬆️
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)-0.2%

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration192.09 ± (192.01 - 192.81) ms194.14 ± (193.87 - 194.54) ms+1.1%✅⬆️
.NET Framework 4.8 - Bailout
duration195.01 ± (194.95 - 195.49) ms198.71 ± (198.41 - 198.97) ms+1.9%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1109.23 ± (1114.44 - 1123.54) ms1131.72 ± (1132.16 - 1139.61) ms+2.0%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms186.98 ± (186.62 - 187.34) ms189.88 ± (189.44 - 190.32) ms+1.5%✅⬆️
process.time_to_main_ms80.37 ± (80.14 - 80.60) ms81.83 ± (81.61 - 82.05) ms+1.8%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.12 ± (16.09 - 16.15) MB16.03 ± (16.01 - 16.06) MB-0.6%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (19 - 20)-0.1%
.NET Core 3.1 - Bailout
process.internal_duration_ms185.55 ± (185.30 - 185.81) ms190.20 ± (189.75 - 190.66) ms+2.5%✅⬆️
process.time_to_main_ms81.65 ± (81.50 - 81.81) ms83.48 ± (83.24 - 83.71) ms+2.2%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.14 ± (16.12 - 16.17) MB16.11 ± (16.09 - 16.13) MB-0.2%
runtime.dotnet.threads.count21 ± (20 - 21)21 ± (20 - 21)+0.2%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms432.33 ± (429.49 - 435.17) ms427.91 ± (424.68 - 431.14) ms-1.0%
process.time_to_main_ms471.32 ± (470.78 - 471.86) ms485.49 ± (484.31 - 486.67) ms+3.0%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.66 ± (58.54 - 58.77) MB58.83 ± (58.72 - 58.95) MB+0.3%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 30)+0.2%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms191.71 ± (191.30 - 192.12) ms195.40 ± (194.94 - 195.86) ms+1.9%✅⬆️
process.time_to_main_ms70.10 ± (69.93 - 70.27) ms71.82 ± (71.60 - 72.04) ms+2.5%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.10 ± (15.96 - 16.24) MB16.36 ± (16.33 - 16.39) MB+1.6%✅⬆️
runtime.dotnet.threads.count18 ± (18 - 18)19 ± (19 - 19)+5.3%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms190.06 ± (189.84 - 190.29) ms192.55 ± (192.21 - 192.89) ms+1.3%✅⬆️
process.time_to_main_ms70.63 ± (70.53 - 70.74) ms72.12 ± (71.97 - 72.27) ms+2.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed15.89 ± (15.73 - 16.04) MB16.08 ± (15.94 - 16.22) MB+1.2%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)20 ± (19 - 20)+3.4%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms443.82 ± (441.03 - 446.61) ms446.23 ± (442.75 - 449.71) ms+0.5%✅⬆️
process.time_to_main_ms447.88 ± (447.42 - 448.35) ms456.41 ± (455.86 - 456.96) ms+1.9%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed58.95 ± (58.84 - 59.07) MB58.72 ± (58.58 - 58.85) MB-0.4%
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.1%
.NET 8 - Baseline
process.internal_duration_ms190.04 ± (189.63 - 190.45) ms191.62 ± (191.30 - 191.95) ms+0.8%✅⬆️
process.time_to_main_ms69.78 ± (69.62 - 69.94) ms70.57 ± (70.37 - 70.77) ms+1.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.81 ± (11.78 - 11.84) MB11.71 ± (11.68 - 11.73) MB-0.9%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)-0.0%
.NET 8 - Bailout
process.internal_duration_ms188.67 ± (188.39 - 188.96) ms193.22 ± (192.74 - 193.70) ms+2.4%✅⬆️
process.time_to_main_ms70.75 ± (70.61 - 70.90) ms72.15 ± (71.98 - 72.32) ms+2.0%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.87 ± (11.83 - 11.92) MB11.75 ± (11.73 - 11.77) MB-1.0%
runtime.dotnet.threads.count19 ± (18 - 19)19 ± (19 - 19)+2.9%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms364.01 ± (362.25 - 365.77) ms368.08 ± (366.82 - 369.35) ms+1.1%✅⬆️
process.time_to_main_ms434.84 ± (434.24 - 435.44) ms438.13 ± (437.41 - 438.85) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.20 ± (48.16 - 48.24) MB48.22 ± (48.18 - 48.26) MB+0.0%✅⬆️
runtime.dotnet.threads.count29 ± (28 - 29)29 ± (29 - 29)+1.2%✅⬆️
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 (8079) - mean (78ms)  : 75, 81
    master - mean (69ms)  : 67, 70

    section Bailout
    This PR (8079) - mean (83ms)  : crit, 80, 85
    master - mean (72ms)  : 71, 73

    section CallTarget+Inlining+NGEN
    This PR (8079) - mean (1,093ms)  : crit, 1028, 1159
    master - mean (1,020ms)  : 939, 1101

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 (8079) - mean (124ms)  : 120, 128
    master - mean (106ms)  : 104, 109

    section Bailout
    This PR (8079) - mean (124ms)  : crit, 121, 128
    master - mean (107ms)  : 106, 109

    section CallTarget+Inlining+NGEN
    This PR (8079) - mean (806ms)  : crit, 748, 864
    master - mean (740ms)  : 687, 794

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8079) - mean (111ms)  : 107, 115
    master - mean (94ms)  : 92, 96

    section Bailout
    This PR (8079) - mean (111ms)  : crit, 108, 115
    master - mean (95ms)  : 94, 96

    section CallTarget+Inlining+NGEN
    This PR (8079) - mean (772ms)  : crit, 696, 847
    master - mean (722ms)  : 691, 753

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8079) - mean (107ms)  : 103, 111
    master - mean (93ms)  : 90, 95

    section Bailout
    This PR (8079) - mean (108ms)  : crit, 106, 111
    master - mean (93ms)  : 92, 95

    section CallTarget+Inlining+NGEN
    This PR (8079) - mean (712ms)  : crit, 690, 733
    master - mean (636ms)  : 621, 650

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 (8079) - mean (194ms)  : 191, 197
    master - mean (192ms)  : 188, 196

    section Bailout
    This PR (8079) - mean (199ms)  : 196, 201
    master - mean (195ms)  : 193, 198

    section CallTarget+Inlining+NGEN
    This PR (8079) - mean (1,136ms)  : 1083, 1189
    master - mean (1,119ms)  : 1052, 1186

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 (8079) - mean (280ms)  : 273, 287
    master - mean (276ms)  : 270, 282

    section Bailout
    This PR (8079) - mean (283ms)  : 275, 290
    master - mean (275ms)  : 272, 278

    section CallTarget+Inlining+NGEN
    This PR (8079) - mean (947ms)  : 895, 998
    master - mean (930ms)  : 880, 980

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8079) - mean (276ms)  : 269, 282
    master - mean (270ms)  : 265, 274

    section Bailout
    This PR (8079) - mean (273ms)  : 269, 276
    master - mean (269ms)  : 266, 272

    section CallTarget+Inlining+NGEN
    This PR (8079) - mean (930ms)  : 876, 984
    master - mean (916ms)  : 858, 974

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8079) - mean (272ms)  : 266, 278
    master - mean (269ms)  : 262, 276

    section Bailout
    This PR (8079) - mean (275ms)  : 266, 284
    master - mean (269ms)  : 264, 274

    section CallTarget+Inlining+NGEN
    This PR (8079) - mean (839ms)  : 823, 855
    master - mean (832ms)  : 809, 855

Loading

@lucaspimentel lucaspimentel changed the title Refactor Azure Functions instrumentation for improved clarity Refactor Azure Functions instrumentation before #7628 Jan 21, 2026
@lucaspimentel lucaspimentel force-pushed the lpimentel/APMSVLS-58-azfunc-host-parenting-pre-cleanup branch from ddd2357 to a9b5436 Compare January 21, 2026 23:36
@pr-commenter
Copy link

pr-commenter bot commented Jan 22, 2026

Benchmarks

Benchmark execution time: 2026-01-26 15:16:50

Comparing candidate commit 19c86a2 in PR branch lpimentel/APMSVLS-58-azfunc-host-parenting-pre-cleanup with baseline commit e62315b in branch master.

Found 12 performance improvements and 8 performance regressions! Performance is the same for 155 metrics, 17 unstable metrics.

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild netcoreapp3.1

  • 🟩 execution_time [-14.501ms; -11.526ms] or [-7.087%; -5.633%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0

  • 🟩 execution_time [-20.914ms; -14.927ms] or [-9.570%; -6.831%]

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

  • 🟩 execution_time [-24.640ms; -18.182ms] or [-11.450%; -8.449%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net6.0

  • 🟥 execution_time [+16.390ms; +20.965ms] or [+8.196%; +10.484%]
  • 🟩 throughput [+147219.592op/s; +218285.392op/s] or [+5.026%; +7.452%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0

  • 🟩 execution_time [-28.910ms; -28.634ms] or [-14.231%; -14.095%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 execution_time [+18.811ms; +24.000ms] or [+9.632%; +12.289%]

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

  • 🟥 throughput [-241.089op/s; -125.178op/s] or [-16.062%; -8.340%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net472

  • 🟥 execution_time [+142.258µs; +146.235µs] or [+7.412%; +7.619%]
  • 🟥 throughput [-36.921op/s; -35.921op/s] or [-7.086%; -6.894%]

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

  • 🟩 execution_time [-160.508µs; -154.012µs] or [-10.370%; -9.951%]
  • 🟩 throughput [+71.634op/s; +74.496op/s] or [+11.087%; +11.530%]

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

  • 🟩 execution_time [-85.701µs; -81.419µs] or [-7.553%; -7.176%]
  • 🟩 throughput [+68.241op/s; +71.910op/s] or [+7.743%; +8.159%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472

  • 🟩 throughput [+21108.945op/s; +24684.096op/s] or [+5.599%; +6.547%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark netcoreapp3.1

  • 🟥 throughput [-594.876op/s; -393.036op/s] or [-26.265%; -17.353%]

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

  • 🟥 throughput [-16147997.777op/s; -15008517.434op/s] or [-6.699%; -6.226%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope netcoreapp3.1

  • 🟩 execution_time [-16.072ms; -10.800ms] or [-7.633%; -5.129%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan netcoreapp3.1

  • 🟩 execution_time [-18.770ms; -13.492ms] or [-8.784%; -6.314%]

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

  • 🟥 execution_time [+16.432ms; +20.066ms] or [+8.113%; +9.907%]

Copy link
Contributor

@pablomartinezbernardo pablomartinezbernardo left a comment

Choose a reason for hiding this comment

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

LGTM!

var functionsWorkerRuntime = EnvironmentHelpers.GetEnvironmentVariable(PlatformKeys.AzureFunctions.FunctionsWorkerRuntime);

if (!string.IsNullOrEmpty(functionsExtensionVersion) && !string.IsNullOrEmpty(functionsWorkerRuntime))
if (!SkipAspNetCoreDiagnosticObserver())
Copy link
Contributor

@pablomartinezbernardo pablomartinezbernardo Jan 26, 2026

Choose a reason for hiding this comment

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

Previously this was looking at FUNCTIONS_EXTENSION_VERSION and FUNCTIONS_WORKER_RUNTIME, and now it is doing EnvironmentHelpers.IsAzureFunctions() which adds WEBSITE_SITE_NAME to the check. Seems totally intended, just mentioning it because the PR says there are no functional changes and I'm not sure if this has other consequences

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks! I'll take a closer look.

Copy link
Member Author

@lucaspimentel lucaspimentel Jan 26, 2026

Choose a reason for hiding this comment

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

Ahh, yes. In EnvironmentHelpers we also check WEBSITE_SITE_NAME which we didn't do here before. It shouldn't make any difference in practice (all 3 env vars should always be set). We only check for the additional env vars to be safe, I guess.

@lucaspimentel lucaspimentel force-pushed the lpimentel/APMSVLS-58-azfunc-host-parenting-pre-cleanup branch from a9b5436 to 19c86a2 Compare January 26, 2026 14:33
@lucaspimentel lucaspimentel removed the request for review from apiarian-datadog January 27, 2026 20:52
@lucaspimentel lucaspimentel merged commit 3db9044 into master Jan 27, 2026
148 of 150 checks passed
@lucaspimentel lucaspimentel deleted the lpimentel/APMSVLS-58-azfunc-host-parenting-pre-cleanup branch January 27, 2026 21:27
@github-actions github-actions bot added this to the vNext-v3 milestone Jan 27, 2026
igoragoli pushed a commit that referenced this pull request Jan 29, 2026
## Summary of changes

Refactor Azure Functions instrumentation code as a precursor to #7628.

## Reason for change

The changes in #7628 were building up, so I decided to split them into
two PRs. This PR is mostly cleanup and refactoring. No functional
changes.

## Implementation details

**Environment detection helpers** (`EnvironmentHelpers`)
- Added `IsAzureFunctionsIsolated()` - detects isolated worker runtime
- Added `GetAzureFunctionsWorkerRuntime()` - retrieves worker runtime
value
- Added `GetAzureFunctionsExtensionVersion()` - retrieves extension
version
- Refactored `IsRunningInAzureFunctionsHost()` to use new helpers

**Diagnostic observer initialization** (`Instrumentation`)
- Extracted `GetAspNetCoreDiagnosticObserver()`
- Extracted `SkipAspNetCoreDiagnosticObserver()`

**Azure Functions instrumentation cleanup** (`AzureFunctionsCommon`)
- Renamed parameter `context` to `functionContext` for clarity and
consistency
- Made `CreateIsolatedFunctionScope()` private
- Formatting: improved comment alignment and whitespace
- Changed `if` to `switch` for trigger type handling

**ASP.NET Core tracking key rename**
- Renamed `HttpContextItemsKey` to `HttpContextTrackingKey` across all
usages (will add another key in next PR, needed to distinguish them
since they are both "item keys")

## Test coverage

No new tests added - this is a refactoring/cleanup PR with no functional
changes. Existing Azure Functions tests provide coverage.

## Other details

Precursor to #7628 - Fix span parenting for isolated Azure Functions
using ASP.NET Core integration
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.

4 participants