Skip to content

Add opt-in startup diagnostics logging with automatic size optimization#7660

Merged
danielmarbach merged 2 commits into
masterfrom
diagnostics
Mar 20, 2026
Merged

Add opt-in startup diagnostics logging with automatic size optimization#7660
danielmarbach merged 2 commits into
masterfrom
diagnostics

Conversation

@danielmarbach
Copy link
Copy Markdown
Contributor

@danielmarbach danielmarbach commented Mar 17, 2026

WriteDiagnosticsToLog() allows opting in to diagnostics logging instead of file output. When enabled, diagnostics are automatically compacted to prevent Application Insights telemetry limits from being exceeded.

Changes

  1. Opt-in API: WriteDiagnosticsToLog() replaces DisableWritingDiagnosticsToLog()
  2. Writer Suppression: When logging is enabled, the file writer (default or custom) is not called
  3. Automatic Compaction: AssemblyScanning section is automatically compacted to prevent exceeding Application Insights telemetry limits (~30KB threshold)

Diagnostic Size

Our test diagnostic analysis revealed critical size issues:

Large endpoints (e.g., NServiceBus.Core.Tests):

Typical endpoints (acceptance tests):

  • Size: 12-16 KB (safe for Application Insights)

This analysis showed that AssemblyScanning alone can exceed telemetry limits on complex endpoints, making automatic compaction essential for reliable diagnostics logging.

Large endpoints: Diagnostics can exceed 64KB (Application Insights limit), with AssemblyScanning alone consuming ~55KB

Solution: When logging to Application Insights, AssemblyScanning is automatically compacted:

  • Before: Full assembly list (~55KB)
  • After: AssemblyCount, SkippedFileCount, ErrorsThrownDuringScanning, Settings (~100 bytes)

Implementation: AssemblyScanningDiagnostics.CreateCompactedVersion() centralizes the compaction logic

Why

  1. Predictable: Always compact when logging - no threshold guessing
  2. Safe: Prevents Application Insights telemetry limits from being exceeded
  3. Type-safe: Strongly-typed DTO prevents runtime type errors
  4. Encapsulated: Compaction logic lives with the data it compacts
  5. Backward compatible: Existing file-only behavior is unchanged (opt-in feature)

@danielmarbach danielmarbach added this to the 10.2.0 milestone Mar 17, 2026
@danielmarbach danielmarbach marked this pull request as ready for review March 17, 2026 14:28
@bording bording marked this pull request as draft March 17, 2026 20:31
@bording

This comment was marked as resolved.

@danielmarbach danielmarbach changed the title By default write the startup diagnostics to the log and provide an ability to disable it Opt-in diagnostic logging with automatic size truncation Mar 19, 2026
@danielmarbach danielmarbach changed the title Opt-in diagnostic logging with automatic size truncation Add opt-in startup diagnostics logging with automatic size optimization Mar 19, 2026
@danielmarbach danielmarbach marked this pull request as ready for review March 19, 2026 19:01
@danielmarbach danielmarbach requested a review from bording March 19, 2026 19:02
@danielmarbach danielmarbach merged commit 81290cb into master Mar 20, 2026
4 checks passed
@danielmarbach danielmarbach deleted the diagnostics branch March 20, 2026 06:59
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