feat(logback): add posthog-server-logback appender module - #672
Draft
cat-ph wants to merge 1 commit into
Draft
Conversation
5 tasks
New pure-JVM module publishing com.posthog:posthog-server-logback — a Logback appender that mirrors qualifying log events into PostHog error tracking. - PostHogAppender (AppenderBase<ILoggingEvent>): captures events at minimumCaptureLevel (default ERROR) that carry a real Throwable; maps log level to $exception_level; attaches logger name and the log message when it differs from the throwable message; never throws from append. - Client wiring via static PostHogAppender.setPostHog(...); events before registration are dropped by design. Runs on the logging thread, so PostHogRequestContext scopes resolve the distinct id automatically. - Recursion guard: com.posthog.* loggers are never captured. - Dedup: consults the core PostHogCapturedThrowables identity marker so the appender and the uncaught handler don't double-report the same Throwable. - logback-classic is compileOnly (1.3.x line, Java 8); animalsniffer and apiCheck pass. release.yml publish matrix / version-sync intentionally not updated (workflow edits out of scope) — human follow-up before release. # Conflicts: # gradle.properties
cat-ph
force-pushed
the
cat/java-et-uncaught
branch
from
August 3, 2026 23:03
29a1276 to
c9db1af
Compare
cat-ph
force-pushed
the
cat/java-et-logback
branch
from
August 3, 2026 23:03
b168168 to
1df4118
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚨 Before merge / release
posthog-server-logbackis not wired into the release workflow. The version-sync step and the publish matrix in.github/workflowsstill need an entry for the new module (and the module needs its Sonatype coordinates confirmed). That was deliberately left out of this PR — no workflow files are touched here — so the repo owner can wire it up. Merging as-is is safe: nothing publishes the module yet.💡 Motivation and Context
Fourth and last PR in the JVM error-tracking stack: a new
posthog-server-logbackmodule (com.posthog:posthog-server-logback,0.1.0) with a Logback appender that reports logged errors to PostHog Error Tracking through the server SDK.PostHogAppender(AppenderBase<ILoggingEvent>, packagecom.posthog.server.logback) captures events at or aboveminimumCaptureLevel(defaultERROR) that carry aThrowable, sending them through the server SDK'scaptureExceptionso request-context distinct-id resolution and in-app frame config apply automatically (the appender runs on the logging thread, inside any activePostHogRequestContextscope).PostHogAppender.setPostHog(client)once at startup (events logged before registration are dropped — documented), or let the appender self-configure fromlogback.xmlvia<apiKey>/<host>, in which case it owns and closes that client onstop(). An explicitly registered client always wins.com.posthog…loggers are always skipped (recursion guard), events without a throwable are skipped (no message-only synthesis in this first version), and captured events carry$exception_level,logger_name, andlog_messagewhen the log message differs from the throwable message.PostHogCapturedThrowablesguard from PR 3, so an exception already reported by the uncaught handler is not re-reported when a log mirror sees the same instance.settings.gradle.kts,pnpm-workspace.yaml,gradle.properties(serverLogbackVersion=0.1.0),Makefiledry/release targets, and aLOGBACKversion constant inbuildSrc. Logback iscompileOnly(consumers bringlogback-classic; the 1.3.x line is the last one targeting Java 8), andposthog-serveris anapidependency.The module is explicitly pre-1.0: the changeset says the public API may change between minor versions.
💚 How did you test it?
PostHogAppenderTest(8 tests): an error with a throwable becomes exactly one$exceptionevent with the expected properties, below-threshold events ignored,WARNcaptured withwarninglevel once the threshold is lowered,com.posthoglogger names skipped for recursion, a logger merely sharing that string prefix still captured, throwable-less events ignored, events logged before a client is registered dropped, and the same throwable instance logged twice captured once../gradlew :posthog-server-logback:test :posthog-server-logback:apiCheckpass;spotlessCheckclean. The module'sgradle.lockfilewas regenerated so it matches the repo's current kover/animalsniffer versions.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🔗 Stacked PR
Position 4 of 4 (top of the stack). Base:
cat/java-et-uncaught(PR #671).captureExceptionoptionsposthog-server-logbackappender module