Skip to content

Log4Net guard AppenderAttachedImpl integration against NullReferenceException. - #8489

Closed
NachoEchevarria wants to merge 3 commits into
masterfrom
nacho/FixNUllReferenceExceptionLog4Net
Closed

Log4Net guard AppenderAttachedImpl integration against NullReferenceException.#8489
NachoEchevarria wants to merge 3 commits into
masterfrom
nacho/FixNUllReferenceExceptionLog4Net

Conversation

@NachoEchevarria

@NachoEchevarria NachoEchevarria commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Summary of changes

Guards the log4net AppenderAttachedImpl.AppendLoopOnAppenders CallTarget integration against a NullReferenceException.

Reason for change

We have observed the following error in customer installations:

Error : Exception occurred when calling the CallTarget integration continuation.
System.NullReferenceException
   at Datadog.Trace.ClrProfiler.CallTarget.Handlers.BeginMethodHandler`3.Invoke(TTarget instance, TArg1& arg1)
   at Datadog.Trace.ClrProfiler.CallTarget.CallTargetInvoker.BeginMethod[TIntegration,TTarget,TArg1](TTarget instance, TArg1& arg1)
   at log4net.Util.AppenderAttachedImpl.AppendLoopOnAppenders(LoggingEvent loggingEvent)

How it can be thrown

Hypothesis - Startup race: the field backing Tracer.Instance.CurrentTraceSettings is only assigned partway through the TracerManager constructor (line 116), so there's a window — roughly lines 84–115 of the ctor — where Tracer.Instance.CurrentTraceSettings returns null, and the subsequent .Settings access NREs.

Implementation details

  • Null-check tracer.CurrentTraceSettings?.Settings; short-circuit with CallTargetState.GetDefault() if null or if LogsInjectionEnabled is false.
  • Log.Debug during startup if CurrentTraceSettings is null, so the condition stays diagnosable. Bounded naturally by the brief startup window; no flag / atomic needed.
  • #nullable enable on the file, with matching annotations on the OnMethodBegin / OnMethodEnd signatures.
  • Replaced new CallTargetState(scope: null, state: null) with CallTargetState.GetDefault() for consistency across the three return paths (same value, clearer intent).

Test coverage

Other details

@dd-trace-dotnet-ci-bot

dd-trace-dotnet-ci-bot Bot commented Apr 21, 2026

Copy link
Copy Markdown

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8489) 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
duration72.89 ± (73.03 - 73.52) ms72.88 ± (72.90 - 73.28) ms-0.0%
.NET Framework 4.8 - Bailout
duration77.14 ± (76.96 - 77.38) ms80.31 ± (80.09 - 80.67) ms+4.1%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1084.85 ± (1081.72 - 1088.59) ms1085.99 ± (1082.01 - 1089.48) ms+0.1%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms22.41 ± (22.36 - 22.46) ms22.69 ± (22.63 - 22.74) ms+1.2%✅⬆️
process.time_to_main_ms85.04 ± (84.81 - 85.27) ms86.76 ± (86.45 - 87.08) ms+2.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.91 ± (10.91 - 10.91) MB10.91 ± (10.91 - 10.92) MB+0.0%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms22.27 ± (22.24 - 22.31) ms22.53 ± (22.48 - 22.59) ms+1.2%✅⬆️
process.time_to_main_ms85.51 ± (85.32 - 85.71) ms88.02 ± (87.71 - 88.33) ms+2.9%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.88 ± (10.87 - 10.88) MB10.95 ± (10.95 - 10.95) MB+0.7%✅⬆️
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms230.09 ± (229.01 - 231.17) ms213.29 ± (212.48 - 214.09) ms-7.3%
process.time_to_main_ms526.25 ± (524.88 - 527.61) ms527.75 ± (526.19 - 529.31) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.46 ± (48.43 - 48.49) MB47.89 ± (47.86 - 47.92) MB-1.2%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%
.NET 6 - Baseline
process.internal_duration_ms21.62 ± (21.56 - 21.68) ms21.60 ± (21.53 - 21.67) ms-0.1%
process.time_to_main_ms76.76 ± (76.47 - 77.05) ms76.20 ± (75.87 - 76.54) ms-0.7%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.62 ± (10.62 - 10.63) 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_ms21.24 ± (21.20 - 21.28) ms21.08 ± (21.03 - 21.13) ms-0.7%
process.time_to_main_ms75.57 ± (75.39 - 75.76) ms74.74 ± (74.58 - 74.90) ms-1.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.73 ± (10.73 - 10.73) MB10.75 ± (10.75 - 10.76) MB+0.2%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms385.01 ± (383.02 - 387.00) ms381.47 ± (379.07 - 383.88) ms-0.9%
process.time_to_main_ms530.76 ± (529.48 - 532.04) ms531.25 ± (529.85 - 532.66) ms+0.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed49.91 ± (49.88 - 49.93) MB49.34 ± (49.32 - 49.37) MB-1.1%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.7%
.NET 8 - Baseline
process.internal_duration_ms19.66 ± (19.61 - 19.71) ms19.63 ± (19.58 - 19.67) ms-0.2%
process.time_to_main_ms73.44 ± (73.25 - 73.64) ms73.62 ± (73.41 - 73.83) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.67 ± (7.66 - 7.68) MB7.66 ± (7.66 - 7.67) MB-0.1%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms19.98 ± (19.92 - 20.04) ms20.08 ± (20.02 - 20.13) ms+0.5%✅⬆️
process.time_to_main_ms77.23 ± (76.96 - 77.50) ms77.80 ± (77.52 - 78.08) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.71 ± (7.71 - 7.72) MB7.71 ± (7.71 - 7.72) MB-0.0%
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms304.22 ± (301.78 - 306.66) ms300.91 ± (298.56 - 303.25) ms-1.1%
process.time_to_main_ms490.21 ± (489.16 - 491.27) ms489.96 ± (488.71 - 491.21) ms-0.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed37.25 ± (37.20 - 37.30) MB36.56 ± (36.52 - 36.61) MB-1.8%
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)+0.0%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration202.68 ± (202.57 - 203.73) ms209.21 ± (208.92 - 210.26) ms+3.2%✅⬆️
.NET Framework 4.8 - Bailout
duration206.28 ± (206.19 - 207.34) ms210.78 ± (210.96 - 212.13) ms+2.2%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1199.33 ± (1199.33 - 1205.55) ms1212.41 ± (1212.39 - 1220.13) ms+1.1%✅⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms197.93 ± (197.30 - 198.56) ms199.77 ± (199.15 - 200.39) ms+0.9%✅⬆️
process.time_to_main_ms85.71 ± (85.40 - 86.03) ms86.89 ± (86.56 - 87.23) ms+1.4%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.07 ± (16.06 - 16.09) MB15.95 ± (15.94 - 15.97) MB-0.7%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-1.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms198.09 ± (197.49 - 198.69) ms200.58 ± (200.01 - 201.15) ms+1.3%✅⬆️
process.time_to_main_ms87.22 ± (86.90 - 87.54) ms89.06 ± (88.73 - 89.39) ms+2.1%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.11 ± (16.09 - 16.13) MB15.99 ± (15.97 - 16.01) MB-0.7%
runtime.dotnet.threads.count21 ± (20 - 21)21 ± (21 - 21)+1.2%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms411.44 ± (410.00 - 412.87) ms392.19 ± (390.94 - 393.44) ms-4.7%
process.time_to_main_ms537.27 ± (535.81 - 538.72) ms539.48 ± (538.24 - 540.73) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed59.32 ± (59.28 - 59.36) MB57.78 ± (57.63 - 57.94) MB-2.6%
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)+0.5%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms202.50 ± (202.00 - 203.01) ms205.52 ± (204.93 - 206.11) ms+1.5%✅⬆️
process.time_to_main_ms74.66 ± (74.40 - 74.92) ms75.77 ± (75.49 - 76.05) ms+1.5%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.27 ± (16.25 - 16.29) MB16.25 ± (16.23 - 16.27) MB-0.1%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.7%
.NET 6 - Bailout
process.internal_duration_ms201.89 ± (201.34 - 202.44) ms206.51 ± (205.94 - 207.07) ms+2.3%✅⬆️
process.time_to_main_ms75.60 ± (75.35 - 75.85) ms77.63 ± (77.34 - 77.93) ms+2.7%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.30 ± (16.28 - 16.32) MB16.33 ± (16.31 - 16.35) MB+0.2%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-0.5%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms601.52 ± (598.46 - 604.59) ms593.81 ± (590.79 - 596.82) ms-1.3%
process.time_to_main_ms537.30 ± (536.20 - 538.39) ms539.48 ± (538.20 - 540.76) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed61.53 ± (61.43 - 61.62) MB60.95 ± (60.86 - 61.05) MB-0.9%
runtime.dotnet.threads.count30 ± (30 - 31)31 ± (31 - 31)+1.0%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms203.15 ± (202.58 - 203.71) ms205.08 ± (204.34 - 205.82) ms+0.9%✅⬆️
process.time_to_main_ms74.43 ± (74.19 - 74.67) ms75.16 ± (74.87 - 75.46) ms+1.0%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.55 ± (11.54 - 11.57) MB11.57 ± (11.56 - 11.59) MB+0.2%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.2%
.NET 8 - Bailout
process.internal_duration_ms202.68 ± (202.05 - 203.30) ms204.50 ± (203.74 - 205.25) ms+0.9%✅⬆️
process.time_to_main_ms76.08 ± (75.81 - 76.34) ms76.75 ± (76.42 - 77.07) ms+0.9%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.59 ± (11.58 - 11.61) MB11.66 ± (11.65 - 11.68) MB+0.6%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-0.2%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms536.01 ± (528.63 - 543.40) ms549.15 ± (541.95 - 556.35) ms+2.5%✅⬆️
process.time_to_main_ms500.98 ± (499.58 - 502.38) ms505.00 ± (503.92 - 506.09) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed50.81 ± (50.72 - 50.90) MB50.51 ± (50.43 - 50.59) MB-0.6%
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)+0.1%✅⬆️
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 (8489) - mean (73ms)  : 70, 76
    master - mean (73ms)  : 70, 77

    section Bailout
    This PR (8489) - mean (80ms)  : 76, 85
    master - mean (77ms)  : 74, 80

    section CallTarget+Inlining+NGEN
    This PR (8489) - mean (1,086ms)  : 1032, 1140
    master - mean (1,085ms)  : 1036, 1134

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 (8489) - mean (117ms)  : 111, 122
    master - mean (114ms)  : 110, 119

    section Bailout
    This PR (8489) - mean (118ms)  : 111, 124
    master - mean (115ms)  : 111, 118

    section CallTarget+Inlining+NGEN
    This PR (8489) - mean (779ms)  : 747, 811
    master - mean (794ms)  : 765, 824

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8489) - mean (104ms)  : 97, 112
    master - mean (105ms)  : 101, 110

    section Bailout
    This PR (8489) - mean (102ms)  : 100, 104
    master - mean (103ms)  : 99, 108

    section CallTarget+Inlining+NGEN
    This PR (8489) - mean (941ms)  : 905, 978
    master - mean (947ms)  : 900, 993

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8489) - mean (101ms)  : 97, 105
    master - mean (101ms)  : 96, 106

    section Bailout
    This PR (8489) - mean (106ms)  : 101, 111
    master - mean (105ms)  : 101, 110

    section CallTarget+Inlining+NGEN
    This PR (8489) - mean (823ms)  : 785, 861
    master - mean (826ms)  : 784, 869

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 (8489) - mean (210ms)  : 200, 219
    master - mean (203ms)  : 195, 212

    section Bailout
    This PR (8489) - mean (212ms)  : 203, 220
    master - mean (207ms)  : 198, 215

    section CallTarget+Inlining+NGEN
    This PR (8489) - mean (1,216ms)  : 1158, 1274
    master - mean (1,202ms)  : 1158, 1247

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 (8489) - mean (297ms)  : 284, 309
    master - mean (294ms)  : 280, 307

    section Bailout
    This PR (8489) - mean (299ms)  : 287, 311
    master - mean (295ms)  : 280, 311

    section CallTarget+Inlining+NGEN
    This PR (8489) - mean (970ms)  : 935, 1005
    master - mean (981ms)  : 952, 1011

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8489) - mean (291ms)  : 277, 305
    master - mean (286ms)  : 276, 297

    section Bailout
    This PR (8489) - mean (293ms)  : 281, 306
    master - mean (286ms)  : 276, 297

    section CallTarget+Inlining+NGEN
    This PR (8489) - mean (1,166ms)  : 1119, 1213
    master - mean (1,169ms)  : 1122, 1216

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8489) - mean (292ms)  : 275, 309
    master - mean (289ms)  : 276, 301

    section Bailout
    This PR (8489) - mean (292ms)  : 276, 308
    master - mean (290ms)  : 275, 306

    section CallTarget+Inlining+NGEN
    This PR (8489) - mean (1,090ms)  : 986, 1195
    master - mean (1,070ms)  : 983, 1158

Loading

@pr-commenter

pr-commenter Bot commented Apr 21, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-04-22 16:25:01

Comparing candidate commit b1b28de in PR branch nacho/FixNUllReferenceExceptionLog4Net with baseline commit 34902b0 in branch master.

Found 0 performance improvements and 1 performance regressions! Performance is the same for 26 metrics, 0 unstable metrics, 60 known flaky benchmarks, 27 flaky benchmarks without significant changes.

Explanation

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

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

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

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

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

More details about the CI and significant changes

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

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

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

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

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

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

scenario:Benchmarks.Trace.HttpClientBenchmark.SendAsync net472

  • 🟥 throughput [-4718.837op/s; -4433.398op/s] or [-5.387%; -5.061%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net6.0

  • 🟩 throughput [+8461.647op/s; +10644.565op/s] or [+7.112%; +8.947%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 execution_time [+303.810ms; +308.144ms] or [+150.761%; +152.912%]

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

  • 🟥 execution_time [+381.039ms; +383.855ms] or [+301.044%; +303.269%]

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

  • 🟥 execution_time [+396.826ms; +400.193ms] or [+351.176%; +354.155%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody net472

  • 🟥 allocated_mem [+1.308KB; +1.308KB] or [+27.529%; +27.541%]

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

  • 🟥 allocated_mem [+471 bytes; +472 bytes] or [+9.977%; +9.987%]
  • 🟩 execution_time [-15.864ms; -11.695ms] or [-7.409%; -5.462%]

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

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+27.502%; +27.510%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net472

  • 🟥 allocated_mem [+1.307KB; +1.307KB] or [+105.746%; +105.759%]
  • 🟥 throughput [-259349.116op/s; -249785.277op/s] or [-26.481%; -25.504%]

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

  • 🟥 allocated_mem [+471 bytes; +472 bytes] or [+38.558%; +38.566%]
  • 🟩 execution_time [-26.158ms; -21.286ms] or [-11.665%; -9.493%]
  • 🟥 throughput [-71261.557op/s; -47365.344op/s] or [-7.613%; -5.060%]

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

  • 🟥 allocated_mem [+1.272KB; +1.272KB] or [+105.292%; +105.304%]
  • 🟥 throughput [-141786.480op/s; -125894.570op/s] or [-20.372%; -18.089%]

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

  • 🟩 throughput [+10314.828op/s; +13278.124op/s] or [+6.563%; +8.449%]

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

  • 🟩 throughput [+7632.773op/s; +10291.578op/s] or [+6.080%; +8.199%]

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

  • 🟩 throughput [+457246.610op/s; +473926.993op/s] or [+15.247%; +15.803%]

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

  • 🟩 execution_time [-19.546ms; -15.187ms] or [-9.010%; -7.001%]
  • 🟩 throughput [+196271.117op/s; +253339.613op/s] or [+7.791%; +10.056%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeArgs net472

  • 🟥 execution_time [+300.006ms; +300.601ms] or [+149.903%; +150.200%]

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

  • 🟥 execution_time [+300.109ms; +303.247ms] or [+151.346%; +152.928%]

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

  • 🟥 execution_time [+299.731ms; +302.117ms] or [+150.981%; +152.183%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net472

  • 🟥 execution_time [+297.435ms; +298.111ms] or [+146.088%; +146.421%]

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

  • 🟥 execution_time [+293.088ms; +297.009ms] or [+143.280%; +145.197%]

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

  • 🟥 execution_time [+301.796ms; +303.479ms] or [+150.837%; +151.678%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net6.0

  • 🟥 execution_time [+42.733µs; +71.081µs] or [+9.801%; +16.302%]
  • 🟥 throughput [-329.104op/s; -203.671op/s] or [-14.308%; -8.855%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net6.0

  • 🟥 execution_time [+26.835µs; +50.503µs] or [+8.567%; +16.123%]
  • 🟥 throughput [-464.701op/s; -265.633op/s] or [-14.486%; -8.281%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net472

  • 🟥 execution_time [+299.733ms; +300.366ms] or [+149.597%; +149.914%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net6.0

  • 🟥 execution_time [+415.955ms; +421.537ms] or [+451.952%; +458.017%]
  • 🟩 throughput [+1038.702op/s; +1179.055op/s] or [+8.535%; +9.688%]

scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest netcoreapp3.1

  • unstable execution_time [+304.179ms; +342.865ms] or [+230.960%; +260.335%]
  • 🟩 throughput [+715.729op/s; +914.356op/s] or [+6.929%; +8.852%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • unstable execution_time [+394.364ms; +466.886ms] or [+181.325%; +214.670%]
  • 🟥 throughput [-586.181op/s; -524.618op/s] or [-53.114%; -47.536%]

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

  • unstable execution_time [+205.664ms; +338.932ms] or [+87.646%; +144.439%]
  • 🟥 throughput [-748.574op/s; -664.942op/s] or [-49.930%; -44.352%]

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

  • 🟥 execution_time [+339.742ms; +351.282ms] or [+203.205%; +210.107%]
  • 🟥 throughput [-416.343op/s; -380.972op/s] or [-28.989%; -26.527%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool netcoreapp3.1

  • unstable throughput [-9.750op/s; +58.321op/s] or [-1.820%; +10.886%]

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

  • 🟩 throughput [+27.940op/s; +37.806op/s] or [+5.516%; +7.463%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net472

  • 🟥 execution_time [+301.955ms; +303.444ms] or [+152.059%; +152.809%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch net6.0

  • 🟥 execution_time [+301.023ms; +302.665ms] or [+150.843%; +151.666%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearch netcoreapp3.1

  • 🟥 execution_time [+300.498ms; +303.808ms] or [+150.957%; +152.620%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net472

  • 🟥 execution_time [+302.588ms; +304.010ms] or [+151.950%; +152.664%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync net6.0

  • 🟥 execution_time [+298.203ms; +299.923ms] or [+147.448%; +148.298%]

scenario:Benchmarks.Trace.ElasticsearchBenchmark.CallElasticsearchAsync netcoreapp3.1

  • 🟥 execution_time [+302.768ms; +306.317ms] or [+153.456%; +155.255%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net472

  • 🟥 execution_time [+301.183ms; +302.312ms] or [+151.167%; +151.733%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync net6.0

  • 🟥 execution_time [+299.357ms; +302.167ms] or [+149.202%; +150.602%]
  • 🟩 throughput [+55028.440op/s; +59866.784op/s] or [+10.927%; +11.888%]

scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1

  • 🟥 execution_time [+299.463ms; +302.336ms] or [+148.980%; +150.410%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net6.0

  • 🟩 execution_time [-16.354ms; -12.701ms] or [-7.605%; -5.906%]
  • 🟩 throughput [+27625.621op/s; +34315.136op/s] or [+7.578%; +9.414%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net6.0

  • 🟩 allocated_mem [-18.706KB; -18.686KB] or [-6.824%; -6.816%]
  • unstable execution_time [-34.034µs; +18.372µs] or [-6.727%; +3.631%]

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

  • 🟩 allocated_mem [-15.936KB; -15.920KB] or [-5.809%; -5.803%]

scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0

  • 🟥 execution_time [+7.351µs; +11.400µs] or [+17.375%; +26.946%]
  • 🟥 throughput [-5099.695op/s; -3332.121op/s] or [-21.468%; -14.027%]

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

  • unstable execution_time [-13.731µs; -6.421µs] or [-21.303%; -9.962%]
  • 🟩 throughput [+1669.807op/s; +3221.264op/s] or [+10.245%; +19.764%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net472

  • 🟥 execution_time [+303.247ms; +305.134ms] or [+153.278%; +154.231%]

scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog net6.0

  • 🟥 execution_time [+303.127ms; +305.532ms] or [+154.291%; +155.515%]

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

  • 🟥 execution_time [+299.325ms; +301.227ms] or [+149.849%; +150.801%]

scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net6.0

  • 🟩 throughput [+42701.082op/s; +46754.892op/s] or [+8.082%; +8.850%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net472

  • 🟥 execution_time [+300.822ms; +302.763ms] or [+149.932%; +150.900%]

scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net6.0

  • 🟥 execution_time [+302.406ms; +303.733ms] or [+151.854%; +152.520%]

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

  • 🟥 execution_time [+303.698ms; +306.537ms] or [+154.016%; +155.456%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net472

  • 🟥 execution_time [+299.903ms; +300.489ms] or [+149.593%; +149.886%]
  • 🟩 throughput [+66021531.767op/s; +66272896.484op/s] or [+48.081%; +48.264%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0

  • unstable execution_time [+376.147ms; +407.502ms] or [+467.806%; +506.801%]
  • 🟩 throughput [+1040.959op/s; +1213.396op/s] or [+8.047%; +9.380%]

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

  • 🟥 execution_time [+299.569ms; +300.490ms] or [+149.418%; +149.877%]
  • 🟩 throughput [+16126492.560op/s; +18144471.634op/s] or [+7.143%; +8.037%]

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

  • 🟩 throughput [+81337.656op/s; +94020.209op/s] or [+7.594%; +8.778%]

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

  • 🟩 throughput [+46608.958op/s; +66061.850op/s] or [+5.395%; +7.647%]

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

  • 🟩 throughput [+90443.588op/s; +129089.707op/s] or [+7.000%; +9.992%]

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

  • 🟩 throughput [+78210.036op/s; +86310.827op/s] or [+7.768%; +8.572%]

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

  • 🟩 throughput [+29627.383op/s; +42576.836op/s] or [+5.380%; +7.731%]

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

  • 🟩 throughput [+47188.557op/s; +65351.337op/s] or [+5.272%; +7.301%]

Known flaky benchmarks without significant changes:

  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net472
  • scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorMoreComplexBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmark netcoreapp3.1
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net472
  • scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice net472
  • scenario:Benchmarks.Trace.CharSliceBenchmark.OriginalCharSlice netcoreapp3.1
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net472
  • scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog netcoreapp3.1
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatAspectBenchmark net472
  • scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net472
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive net472
  • scenario:Benchmarks.Trace.RedisBenchmark.SendReceive netcoreapp3.1
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes net472
  • scenario:Benchmarks.Trace.SpanBenchmark.StartFinishTwoScopes netcoreapp3.1
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472
  • scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin netcoreapp3.1

@NachoEchevarria NachoEchevarria changed the title Fix exception fix(log4net): guard AppenderAttachedImpl integration against NullReferenceException. Apr 21, 2026
@NachoEchevarria NachoEchevarria changed the title fix(log4net): guard AppenderAttachedImpl integration against NullReferenceException. Log4Net guard AppenderAttachedImpl integration against NullReferenceException. Apr 21, 2026
@NachoEchevarria
NachoEchevarria marked this pull request as ready for review April 21, 2026 14:54
@NachoEchevarria
NachoEchevarria requested review from a team as code owners April 21, 2026 14:54
if (!_loggedNullSettings)
{
_loggedNullSettings = true;
Log.Debug("log4net logs-injection skipped: CurrentTraceSettings was null.");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unsure how valuable this is, if the theory here is correct there will only be an occasional missed injection

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(at least as I understand it)

/// <param name="loggingEvent">The logging event</param>
/// <returns>Calltarget state value</returns>
internal static CallTargetState OnMethodBegin<TTarget, TLoggingEvent>(TTarget instance, TLoggingEvent loggingEvent)
internal static CallTargetState OnMethodBegin<TTarget, TLoggingEvent>(TTarget instance, TLoggingEvent? loggingEvent)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think TLoggingEvent can be null?

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.

Right! I have modified the code. Thanks!

var tracer = Tracer.Instance;

var mutableSettings = tracer.CurrentTraceSettings.Settings;
var mutableSettings = tracer.CurrentTraceSettings?.Settings;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if this is the case if we'd need to guard this elsewhere for other instrumentations, if so something that we can do later

@andrewlock andrewlock left a comment

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.

Startup race: TracerManager._perTraceSettings is only populated partway through the constructor.

Wait, what? If this is true, then everything everywhere is doomed 😅

@NachoEchevarria

Copy link
Copy Markdown
Collaborator Author

Startup race: TracerManager._perTraceSettings is only populated partway through the constructor.

Wait, what? If this is true, then everything everywhere is doomed 😅

LoggingEvent should never be null and anyway, we were already protected against that before this change. We are calling tracer.CurrentTraceSettings.Settings after calling Tracer.Instance, so it should be safe too... The more I think about it, the most weird this error seems. But it's there.

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.

3 participants