Repository navigation
feat(heroku): Add Heroku log drain endpoint - #6575
Conversation
Follow-up to the original draft in getsentry#5417, rebased onto master. Parsing: - Replace the `rsyslog` dependency with a small Logplex parser. Frames are split by their octet count (RFC 6587) instead of by line, malformed frames stop parsing without panicking, and the priority is validated instead of wrapping. Logplex omits STRUCTURED-DATA, which the parser handles natively. - Generate a random trace id for every log, logs without a trace id are now rejected during processing. - Reject payloads with more than 10,000 frames, Logplex sends at most ~1024 messages per request. Attributes: - Add `heroku.source` and `heroku.dyno` instead of the syslog `resource.*` and `syslog.*` attributes, which are constant for Logplex. - Extract the documented Heroku router fields as `heroku.router.*` and Heroku error codes (H12, R14, L10, ...) from router and platform messages as `heroku.error.code` and `heroku.error.description`. Platform error messages are logged with level `error`. - Do not parse logfmt pairs of application output into attributes, which allowed unbounded attribute keys. Endpoint: - Extract the Logplex headers with a `FromRequestParts` extractor and carry them in a typed item header, as arbitrary item headers no longer exist. - Use the container size limit like the Vercel log drain. - Drop the unused `Value::as_i64`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`time_within_delta` is relative to when it is created, building the expected items on import made the test flaky in long parallel runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
From an independent review: - Honor backslash escapes in quoted logfmt values. The router logs the client controlled request path and `X-Forwarded-For` header in quotes, if quotes are not escaped they can inject fake fields. `at`, `code`, `desc` and `method` are now only accepted before the first `path`, the first `path` wins and the last value wins for all other fields, so the log level and error code cannot be spoofed. - Stop adding `heroku.logplex.frame_id` and `heroku.logplex.user_agent` to every log. They are identical for all messages of a request and only inflate the billed log bytes. This also removes the second `LogplexHeaders` type. - Strip a trailing `\r\n` from messages. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for picking this up again. We'll need a bit of time to do a proper/full review. In the meantime I am looking together with the logs team into what we still need on the product side to get it fully polished and out. |
|
Hello @trevorturk I appreciate taking the time to contribute. This PR was a topic of internal discussion, because as a rule I like to encourage external contributions. However, my concern with this PR is that Heroku itself announced that they're on a Sustaining engineering model earlier this year. From a priority point of view, I'm hesitant to pull a significant new feature into the codebase for a platform that itself indicates no feature work is happening. I'm curious, what logs are you wanting to get out of the heroku drain that you are unable to get using the Sentry SDK? |
|
We've discussed more internally, an engineer is championing landing this work and was able to convince others that we should do this. So, we're going to work on getting this landed 👏 @trevorturk apologies for the churn on this one. I would still be interested in understanding your user case for the connector (given without a trace ID, these logs won't be connected to errors, traces, etc.) |
|
Awesome! I'd love to have this feature, but FWIW I do understand the "Sustaining engineering model" concern as well... My use case is to remove Honeybadger from my stack (nothing personal, but I prefer Sentry) because Honeybadger currently the best way for me to track Heroku Platform Errors. See for details:
AFAICT there's no way for Sentry to see those errors, which are quite important, for example R14/15 memory exceeded errors can take your app down unexpectedly. |
|
Conventions PR, we need to release/merge first: getsentry/sentry-conventions#762 |
|
Result of the discussion in the conventions PR is, that we want to not introduce a |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Write the router fields that are already defined in sentry-conventions or OTel under their generic names instead of `heroku.router.*`, as agreed in getsentry/sentry-conventions#762. Only Heroku-specific fields keep the `heroku` namespace. `at` no longer gets an attribute, it only sets the log level. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Only accept the documented `protocol` values, older router logs have the
scheme in this field. Only accept IP addresses for `client.address`, which
also stops a client sending `{{auto}}` from having it replaced with the
address of the Logplex host during normalization.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Updated: router fields now use the generic names where they exist ( Of course I'm happy to hand this PR off to you. I'm just trying to be helpful, so please feel free to close it as well. |
|
Just waiting on a Sentry Conventions release now. |
# Conflicts: # relay-conventions/sentry-conventions
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0229034. Configure here.
| .get_value(HEROKU__ROUTER__REQUEST_ID) | ||
| .and_then(|value| value.as_str()) | ||
| .unwrap_or_default(), | ||
| ); |
There was a problem hiding this comment.
Injected request ID sets trace ID
Medium Severity
Router request_id now becomes the log trace_id, but fwd is client-controlled and can still overwrite request_id after the genuine value. A crafted X-Forwarded-For can therefore attach that request’s router log to an arbitrary trace.
Reviewed by Cursor Bugbot for commit 0229034. Configure here.


Adds an HTTPS log drain endpoint for Heroku Cedar apps, which can't use the OTLP telemetry drains that Fir apps have:
Heroku can't set custom headers on drain requests, so the key goes in the
sentry_keyquery parameter. Users add the drain withheroku drains:add "https://o<org>.ingest.sentry.io/api/<project>/integration/heroku/logs?sentry_key=<key>" -a <app>.This continues @AbhiPrasad's draft in #5417, which this branch rebases (his commit is kept as-is) and finishes. Earlier experiments: #5405, #5407. Refs getsentry/sentry#91727.
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
🤖 Generated with Claude Code