-
Notifications
You must be signed in to change notification settings - Fork 30
feat(rails): forward Rails.logger to PostHog Logs via OpenTelemetry #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
johnnagro
wants to merge
31
commits into
PostHog:main
Choose a base branch
from
noreastergroup:feat/posthog-rails-otel-logs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
883b496
feat(rails): forward Rails.logger to PostHog Logs via OpenTelemetry
johnnagro ef893c9
fix(rails): drop incorrect service.version OTel resource attribute
johnnagro 33ba5e7
test(rails): cover all severity mappings in appender spec
johnnagro 921777c
refactor(rails): capture init options for logs instead of exposing cl…
johnnagro c29ffe5
docs(rails): document Appender's lock-free thread-safety design
johnnagro fd95ed4
fix(rails): match self-log prefix with start_with? to avoid over-supp…
johnnagro ca3c155
feat(rails): cap PostHog Logs forwarding at a configurable records-pe…
johnnagro 0b07c9b
feat(rails): add logs_before_send callback to scrub or drop PostHog L…
johnnagro 532165a
Update posthog-rails/lib/posthog/rails/logs/appender.rb
johnnagro 8b45826
fix: fallback to 'unknown_service' rather than 'rails'
johnnagro e382f3c
fix(rails): emit progname as logger.name to match OTel logger-name co…
johnnagro b5836cd
docs(rails): note automatic trace_id/span_id correlation for apps usi…
johnnagro 318e7d3
refactor(rails): expose a single :severity enum in the logs_before_se…
johnnagro 8329bf4
fix(rails): run logs_before_send before the rate cap so dropped recor…
johnnagro c29da56
fix(rails): use OTel semconv names (url.full, http.request.method, ur…
johnnagro 0c8a179
test(rails): cover body UTF-8 normalization and before_send string sa…
johnnagro bf8d01e
fix(rails): warn when logs_before_send returns a non-Hash value inste…
johnnagro 6f338b7
fix(rails): coerce numeric strings for logs rate cap instead of silen…
johnnagro be99a7c
docs(rails): recommend require: false for the optional OpenTelemetry …
johnnagro 059d712
fix(rails): warn when logs are enabled but PostHog.init never ran
johnnagro 100bdf5
fix(rails): bound the at_exit logs flush with a 2s timeout so it can'…
johnnagro a148692
refactor(rails): rename forward_rails_logger to logs_forward_rails_lo…
johnnagro 84bfd61
Remove logs_resource_attributes config; resource attrs are now fixed …
johnnagro 9bcd5ad
Remove unused Setup.force_flush; shutdown! already flushes buffered r…
johnnagro e7f1f83
Warn once on invalid logs_level instead of silently falling back to t…
johnnagro b5267ac
Keep forwarding threshold out of Logger#level so BroadcastLogger pred…
johnnagro 4687427
Guard Appender#add against re-entrant logging and warn once when emit…
johnnagro 9f527a3
Add fork-safety spec pinning BatchLogRecordProcessor's post-fork rest…
johnnagro 87b49fc
feat(rails): add changeset and fork-safety spec for PostHog Logs forw…
johnnagro ce9ca0e
Remove unused Severity.for; name_for and for_name cover the split emi…
johnnagro 1dfe9a8
Merge remote-tracking branch 'origin/main' into feat/posthog-rails-ot…
johnnagro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "posthog-ruby": minor | ||
| --- | ||
|
|
||
| Add opt-in PostHog Logs support to posthog-rails: set `config.logs_enabled = true` to forward `Rails.logger` output to PostHog Logs over OpenTelemetry (OTLP), automatically correlated with the request's PostHog distinct ID and session ID (and active trace/span when OpenTelemetry tracing is present). Includes a configurable severity filter (`logs_level`), a rate cap (`logs_max_records_per_minute`, default 6,000/min), and a `logs_before_send` callback for scrubbing or dropping records. Relies on the optional OpenTelemetry gems; when they are absent the feature warns once and no-ops. |
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried running this as is, and got the following error
My lockfile resolved to:
and it looks like the exporter expects
log_record_data.event_nameto exist, butopentelemetry-logs-sdkv0.4.0 definesLogRecordDatawithout anevent_namefield.a fresh bundle with the following fixed it:
maybe we use something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth a test using real exports from these libs