Skip to content

chore: Defer container ID truncation in logging#1701

Merged
HofmeisterAn merged 1 commit into
developfrom
feature/defer-container-id-truncation
Jun 12, 2026
Merged

chore: Defer container ID truncation in logging#1701
HofmeisterAn merged 1 commit into
developfrom
feature/defer-container-id-truncation

Conversation

@HofmeisterAn

@HofmeisterAn HofmeisterAn commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

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

  • Chores
    • Updated project target framework to .NET 10.0, establishing new runtime requirements
    • Updated build tool dependencies to latest versions
    • Improved internal logging infrastructure

@HofmeisterAn HofmeisterAn added the chore A change that doesn't impact the existing functionality, e.g. internal refactorings or cleanups label Jun 12, 2026
@netlify

netlify Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit a1f2126
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/6a2c4f240a3cf400080f7cb5
😎 Deploy Preview https://deploy-preview-1701--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This 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.

Changes

Build infrastructure updates

Layer / File(s) Summary
Build framework and tools upgrade
build/Build.csproj, build/Program.cs
.NET target framework is updated to net10.0, and dotnet-sonarscanner is upgraded to version 11.2.1.

Logging ID truncation refactoring

Layer / File(s) Summary
TruncatedId struct and logger message target updates
src/Testcontainers/Logging.cs
Introduces TruncatedId as an internal readonly struct that truncates IDs to 12 characters in ToString(). Multiple LoggerMessage-annotated *Core methods for container and network lifecycle operations are updated to accept TruncatedId instead of string for identifier parameters.
Extension method wiring and cleanup
src/Testcontainers/Logging.cs
Public ILogger extension methods are updated to construct new TruncatedId(id) when calling the updated *Core logger targets, including network connect and execute command operations. The old TruncId(string id) helper method is removed.

Possibly related PRs

  • testcontainers/testcontainers-dotnet#1697: Both PRs modify src/Testcontainers/Logging.cs's logger wiring (this PR refactoring ID truncation types passed into logger message targets, related PR migrating logging implementation to [LoggerMessage]-generated methods).

Poem

🐰 The truncated IDs now shine bright,
From string to struct, a refactor done right,
Net10 awaits with sonarscanner's new cheer,
Logging flows cleaner—the future is here! ✨


🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: introducing deferred container ID truncation in logging through a TruncatedId wrapper struct.
Description check ✅ Passed The description includes both mandatory sections (What and Why) with clear explanations. The 'What' explains the TruncatedId wrapper implementation, and the 'Why' explains the performance rationale for deferring truncation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/defer-container-id-truncation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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-sonarscanner 11.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.token consistent 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

📥 Commits

Reviewing files that changed from the base of the PR and between a4c0b58 and a1f2126.

📒 Files selected for processing (3)
  • build/Build.csproj
  • build/Program.cs
  • src/Testcontainers/Logging.cs

Comment thread src/Testcontainers/Logging.cs
@HofmeisterAn
HofmeisterAn merged commit 42bddd0 into develop Jun 12, 2026
154 checks passed
@HofmeisterAn
HofmeisterAn deleted the feature/defer-container-id-truncation branch June 12, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore A change that doesn't impact the existing functionality, e.g. internal refactorings or cleanups

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant