Capture exceptions from Microsoft.Extensions.Logging entries

Open
#384 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp

Research direction

Read the exception event metadata spec linked in the issue and review the existing handling in PostHogOptions.CaptureUnhandledExceptions, the request middleware, and runtime hooks. Decide the provider package, public API, category filtering, and request context behavior before implementation. Done means qualifying logged exceptions are captured with the specified metadata, SDK logs cannot recurse, and duplicate reports are suppressed across integrations.

Written by the indexing model from the issue text.

Description

enhancement feature/error-tracking

Problem

PostHogOptions.CaptureUnhandledExceptions (#356) reports exceptions that reach AppDomain.UnhandledException or TaskScheduler.UnobservedTaskException. Exceptions that application or framework code catches and logs never reach either hook, because they are already handled or observed. This includes many hosted BackgroundService failures, which the host logs before it stops.

Proposal

Add an optional Microsoft.Extensions.Logging provider that captures the exception attached to a qualifying log entry.

  • Opt-in, with a configurable minimum level (suggested default: Error).
  • Only entries that carry an Exception produce an event.
  • Event metadata follows the exception event metadata spec: mechanism.type logger, handled: true, $exception_level normalized from the log level, and a $exception_source for the integration (for example dotnet.microsoft_extensions_logging).
  • Entries logged by the SDK itself are filtered out, so a failed capture cannot recurse.
  • Deduplicate against the request middleware and the runtime hooks, so an exception that is logged and then escapes is reported once.

Open questions

  • Which package hosts the provider: PostHog (which already depends on the logging abstractions) or PostHog.AspNetCore.
  • The public API shape: an ILoggingBuilder extension, its options type, and whether category filters are needed in the first version.
  • Whether the request context (distinct_id, session) is applied when the entry is logged inside a request.

Context

Raised as a non-blocking follow-up in the review of #356.

Dominant language
C#
Stars
47
Forks
23
Avg merge
2d 12h
Merged PRs (30d)
30

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PostHog/posthog-dotnet

All issues in PostHog/posthog-dotnet

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.