Skip to content

Fix Event Hub telemetry logging without an EventContext - #823

Merged
moprashant merged 1 commit into
microsoft:mainfrom
moprashant:fix/eventhub-telemetry-null-context
Oct 13, 2026
Merged

moprashant merged 1 commit into
microsoft:mainfrom
moprashant:fix/eventhub-telemetry-null-context

Conversation

@moprashant

Copy link
Copy Markdown
Contributor

Summary

Fix EventHubTelemetryLogger for enabled log calls whose state is not an EventContext, including null state.

CreateEvent casts the state to EventContext, but CreateEventObject immediately accesses its properties. Ordinary ILogger.LogInformation("Processed {Count} items", 42) calls therefore produce EventHubTelemetryLogger.LoggingError rather than the intended event. Null state also throws when calling ToString().

Changes

  • Use state?.ToString() for the state-only message path.
  • After the existing message selection, use EventContext.Persisted() only when no structured context was supplied.
  • Add capture-based regression tests for ordinary formatted/plain/null states, named events, exception paths, persisted correlation/properties, existing structured context and timestamp overrides, oversized context handling, and disabled log levels.

The production fix changes only two statements. Existing event-name precedence, formatter/exception message selection, structured contexts, channel behavior, and oversized-event handling remain unchanged.

Validation

  • Before the fix: 8 context-free logging cases fail with EventHubTelemetryLogger.LoggingError; 7 existing/preservation cases pass.
  • After the fix: all 15 EventHubTelemetryLoggerTests cases pass.
  • Full Debug solution build: succeeds with 0 warnings and 0 errors.
  • Repository unit/functional suite (build-test.cmd): still running; result will be added when available.

Risk

This is a narrow null-context fix in shared logging code. Previously failing ordinary logs will now be serialized and offered to the channel, using ambient correlation and persistent properties. This adds context allocation and can change delivered telemetry volume. Regression tests cover the affected path and preservation of structured events; performance overhead and live Event Hub delivery have not been measured. No benchmark/workload execution logic is changed.

Use persisted context for ordinary logging states and handle null state safely. Add regression coverage for context-free logs and existing structured event behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: d7afa8f5-e846-41bf-bf84-842b11a52ef4
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@moprashant
moprashant merged commit 0fd9d60 into microsoft:main Oct 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants