chore: Defer container ID truncation in logging#1701
Conversation
✅ Deploy Preview for testcontainers-dotnet ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
WalkthroughThis PR updates the build infrastructure to .NET 10.0 and sonarscanner 11.2.1, and refactors logging ID truncation from a string helper method to an internal TruncatedId value type, updating all logger message contracts and public extension methods to use the new struct consistently. ChangesBuild infrastructure updates
Logging ID truncation refactoring
Possibly related PRs
Poem
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
build/Program.cs (1)
8-8: Update: dotnet-sonarscanner 11.2.1 upgrade doesn’t introduce SonarBegin/SonarEnd breaking changes (but watch 10.4+ behavior)
dotnet-sonarscanner11.2.1 exists on NuGet; its release notes list only a Newtonsoft.Json/GAC analysis failure fix and log timestamp visibility improvements—no documented breaking changes and no SonarBegin/SonarEnd parameter contract changes.- For CI reliability after upgrading across the 10.4+ timeframe, SonarSource docs indicate the end step may rely on a scanner engine downloaded from SonarQube Server unless you set
/d:sonar.scanner.useSonarScannerCLI=true; if SonarEnd fails, set that on the begin step (and keep auth parameters like/d:sonar.tokenconsistent between begin and end).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@build/Program.cs` at line 8, The .InstallTool call adding "dotnet-sonarscanner" to the build is fine for version 11.2.1, but to avoid runtime SonarEnd failures across 10.4+ behavior changes, ensure the SonarBegin invocation includes the property /d:sonar.scanner.useSonarScannerCLI=true and that authentication/configuration flags (e.g., /d:sonar.token) are passed identically to both SonarBegin and SonarEnd; update the SonarBegin/SonarEnd invocation locations in your CI scripts (the places that call the scanner, referenced by the .InstallTool line) to include that property and consistent token parameters.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Testcontainers/Logging.cs`:
- Around line 10-23: The TruncatedId constructor accepts a nullable string but
does not guard against null, which causes ToString() to throw; fix by adding a
null guard in the TruncatedId constructor (or normalize id with id ??
string.Empty) so the private field _id is never null, ensuring
TruncatedId.ToString() (which calls _id.Substring(...)) cannot throw a
NullReferenceException.
---
Nitpick comments:
In `@build/Program.cs`:
- Line 8: The .InstallTool call adding "dotnet-sonarscanner" to the build is
fine for version 11.2.1, but to avoid runtime SonarEnd failures across 10.4+
behavior changes, ensure the SonarBegin invocation includes the property
/d:sonar.scanner.useSonarScannerCLI=true and that authentication/configuration
flags (e.g., /d:sonar.token) are passed identically to both SonarBegin and
SonarEnd; update the SonarBegin/SonarEnd invocation locations in your CI scripts
(the places that call the scanner, referenced by the .InstallTool line) to
include that property and consistent token parameters.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0783173b-550b-4f29-b40f-fa6c0cf90e8a
📒 Files selected for processing (3)
build/Build.csprojbuild/Program.cssrc/Testcontainers/Logging.cs
What does this PR do?
Use a lazy TruncatedId wrapper in source-generated logging to avoid eager container/network ID truncation when logging is disabled.
Why is it important?
This keeps the public logging helpers simple while deferring the actual Substring work until formatting occurs.
Related issues
-
Summary by CodeRabbit