Refactor log directory resolution into smaller methods, add tests#7255
Conversation
8d547a5 to
dccf49d
Compare
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (7255) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-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:
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 chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7255) - mean (74ms) : 71, 76
master - mean (75ms) : 73, 78
section Bailout
This PR (7255) - mean (78ms) : 76, 80
master - mean (80ms) : 77, 82
section CallTarget+Inlining+NGEN
This PR (7255) - mean (1,086ms) : 1042, 1129
master - mean (1,106ms) : 1061, 1150
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 (7255) - mean (116ms) : 112, 120
master - mean (119ms) : 115, 123
section Bailout
This PR (7255) - mean (117ms) : 115, 120
master - mean (120ms) : 117, 123
section CallTarget+Inlining+NGEN
This PR (7255) - mean (756ms) : 736, 777
master - mean (769ms) : 738, 800
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7255) - mean (102ms) : 99, 106
master - mean (105ms) : 102, 108
section Bailout
This PR (7255) - mean (104ms) : 102, 106
master - mean (106ms) : 103, 108
section CallTarget+Inlining+NGEN
This PR (7255) - mean (738ms) : 702, 773
master - mean (749ms) : 716, 782
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7255) - mean (102ms) : 99, 104
master - mean (104ms) : 101, 108
section Bailout
This PR (7255) - mean (103ms) : 100, 105
master - mean (106ms) : 102, 109
section CallTarget+Inlining+NGEN
This PR (7255) - mean (684ms) : 658, 709
master - mean (695ms) : 670, 719
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 (7255) - mean (193ms) : 190, 197
master - mean (194ms) : 191, 198
section Bailout
This PR (7255) - mean (196ms) : 193, 199
master - mean (198ms) : 194, 202
section CallTarget+Inlining+NGEN
This PR (7255) - mean (1,151ms) : 1103, 1199
master - mean (1,152ms) : 1106, 1199
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 (7255) - mean (277ms) : 273, 282
master - mean (279ms) : 275, 283
section Bailout
This PR (7255) - mean (278ms) : 272, 283
master - mean (278ms) : 274, 282
section CallTarget+Inlining+NGEN
This PR (7255) - mean (902ms) : 868, 936
master - mean (907ms) : 877, 937
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7255) - mean (271ms) : 264, 278
master - mean (272ms) : 265, 278
section Bailout
This PR (7255) - mean (270ms) : 265, 274
master - mean (271ms) : 267, 275
section CallTarget+Inlining+NGEN
This PR (7255) - mean (935ms) : 906, 965
master - mean (946ms) : 911, 980
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7255) - mean (270ms) : 265, 275
master - mean (269ms) : 264, 274
section Bailout
This PR (7255) - mean (269ms) : 266, 273
master - mean (269ms) : 264, 274
section CallTarget+Inlining+NGEN
This PR (7255) - mean (838ms) : 808, 868
master - mean (835ms) : 814, 857
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BenchmarksBenchmark execution time: 2026-03-16 23:06:31 Comparing candidate commit 3d255d6 in PR branch Found 10 performance improvements and 2 performance regressions! Performance is the same for 169 metrics, 11 unstable metrics. scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net6.0
scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
scenario:Benchmarks.Trace.GraphQLBenchmark.ExecuteAsync netcoreapp3.1
scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0
scenario:Benchmarks.Trace.Log4netBenchmark.EnrichedLog netcoreapp3.1
scenario:Benchmarks.Trace.NLogBenchmark.EnrichedLog net472
scenario:Benchmarks.Trace.SerilogBenchmark.EnrichedLog net472
scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1
scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net6.0
|
dccf49d to
3d77f7a
Compare
a69e50b to
f0bf2b3
Compare
This comment has been minimized.
This comment has been minimized.
65a9c16 to
956d0c9
Compare
956d0c9 to
a5f7c9b
Compare
GetDefaultLogDirectory()There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5f7c9bc77
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
a5f7c9b to
c2121d7
Compare
1af6a0f to
1a2cbf0
Compare
🤖 Co-Authored-By: Claude Code <[email protected]>
🤖 Co-Authored-By: Claude Code <[email protected]>
🤖 Co-Authored-By: Claude Code <[email protected]>
🤖 Co-Authored-By: Claude Code <[email protected]>
🤖 Co-Authored-By: Claude Code <[email protected]>
🤖 Co-Authored-By: Claude Code <[email protected]>
f3bcc1c to
e85a39f
Compare
🤖 Co-Authored-By: Claude Code <[email protected]>
Summary of changes
Refactor
DatadogLoggingFactorylog directory resolution logic into smaller, testable methods and add unit tests.Reason for change
The log directory resolution logic was a single large method mixing concerns:
Breaking it apart makes each piece independently testable and easier to understand.
Implementation details
GetDefaultLogDirectory()— determines the default log directory based on platform and Azure environmentGetProgramDataDirectory()— resolves theProgramDatapath on Windows (with Nano Server fallbacks)TryCreateLogDirectory()— attempts to create a log directory, returning success/failureinternalwith[TestingAndPrivateOnly]for testabilitySimplify
GetLogDirectory()to orchestrate the above methods with clear fallback chain:DD_TRACE_LOG_DIRECTORYenv varDD_TRACE_LOG_PATH(deprecated, directory extracted from file path)GetDefaultLogDirectory()(platform/Azure-aware default)Path.GetTempPath()(last resort)Test coverage
Flattened nested test classes (
FileLoggingConfiguration,RedactedLogConfiguration,SinkConfiguration) into top-level methods with consistentMethodUnderTest_Scenario_ExpectedBehaviornaming:FileLoggingConfiguration.UsesLogDirectoryWhenItExistsGetConfiguration_WithLogDirectory_UsesLogDirectoryFileLoggingConfiguration.UsesObsoleteLogDirectoryWhenAvailableGetConfiguration_WithObsoleteLogPath_UsesObsoleteLogDirectoryFileLoggingConfiguration.UsesEnvironmentFallBackWhenBothNullGetConfiguration_WithNoLogDirectorySettings_UsesEnvironmentFallbackFileLoggingConfiguration.CreatesLogDirectoryWhenItDoesntExistGetConfiguration_WithNonExistentLogDirectory_CreatesDirectoryRedactedLogConfiguration.WhenNoOrInvalidConfiguration_TelemetryLogsEnabledGetConfiguration_WithNoOrInvalidTelemetryLogsSetting_EnablesErrorLoggingRedactedLogConfiguration.WhenDisabled_TelemetryLogsDisabledGetConfiguration_WithTelemetryLogsDisabled_DisablesErrorLoggingSinkConfiguration.WhenNoSinksProvided_UsesFileSinkGetConfiguration_WithNoSinksSetting_UsesFileSinkSinkConfiguration.WhenFileSinkIsIncluded_UsesFileSinkGetConfiguration_WithFileSinkIncluded_UsesFileSinkSinkConfiguration.WhenFileSinkIsNotIncluded_DoesNotUseFileSinkGetConfiguration_WithFileSinkNotIncluded_DoesNotUseFileSinkSinkConfiguration.WhenConsoleSinkIsIncluded_UsesConsoleSinkGetConfiguration_WithConsoleSinkIncluded_UsesConsoleSinkSinkConfiguration.WhenConsoleSinkIsNotIncluded_DoesNotUseConsoleSinkGetConfiguration_WithConsoleSinkNotIncluded_DoesNotUseConsoleSinkAdditional tests for the newly extracted methods:
GetDefaultLogDirectory_*— verifies default paths on Windows/Linux, and Azure App Services detectionGetProgramDataDirectory_*— verifiesProgramDataresolution on WindowsTryCreateLogDirectory_*— verifies directory creation success, existing directory, invalid path, and nested path scenariosOther details