Skip to content

feat(heroku): Add Heroku log drain endpoint - #6575

Merged
Dav1dde merged 19 commits into
getsentry:masterfrom
trevorturk:heroku-log-drain
Nov 6, 2026
Merged

Dav1dde merged 19 commits into
getsentry:masterfrom
trevorturk:heroku-log-drain

Conversation

@trevorturk

@trevorturk trevorturk commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Adds an HTTPS log drain endpoint for Heroku Cedar apps, which can't use the OTLP telemetry drains that Fir apps have:

POST /api/{project_id}/integration/heroku/logs?sentry_key=<public key>
Content-Type: application/logplex-1

Heroku can't set custom headers on drain requests, so the key goes in the sentry_key query parameter. Users add the drain with heroku 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

AbhiPrasad and others added 4 commits October 27, 2026 12:02
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]>
@trevorturk
trevorturk requested a review from a team as a code owner October 27, 2026 18:13
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Dav1dde

Dav1dde commented Oct 28, 2026

Copy link
Copy Markdown
Member

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.

@bcoe

bcoe commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

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?

@bcoe

bcoe commented Oct 28, 2026

Copy link
Copy Markdown
Member

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.)

@trevorturk

Copy link
Copy Markdown
Contributor Author

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.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as resolved.

@Dav1dde Dav1dde self-assigned this Nov 3, 2026
@Dav1dde

Dav1dde commented Nov 3, 2026

Copy link
Copy Markdown
Member

Conventions PR, we need to release/merge first: getsentry/sentry-conventions#762

@Dav1dde

Dav1dde commented Nov 3, 2026

Copy link
Copy Markdown
Member

Result of the discussion in the conventions PR is, that we want to not introduce a heroku namespace for attributes which are already defined in conventions/otlp and use the generic names instead. The PR will have to be updated for this.

trevorturk and others added 4 commits November 3, 2026 09:05
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]>
@trevorturk

Copy link
Copy Markdown
Contributor Author

Updated: router fields now use the generic names where they exist (http.request.method, url.path/url.query, server.address, client.address, http.response.status_code, http.response.size, network.protocol.version, url.scheme, plus OTel's tls.protocol.version, which isn't in conventions yet). heroku.router.{request_id,dyno,connect,service}, heroku.error.* and the per-log heroku.* attributes keep the namespace. I also merged master.

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.

@Dav1dde

Dav1dde commented Nov 5, 2026

Copy link
Copy Markdown
Member

Just waiting on a Sentry Conventions release now.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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(),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0229034. Configure here.

@Dav1dde
Dav1dde enabled auto-merge November 6, 2026 11:42
@Dav1dde
Dav1dde disabled auto-merge November 6, 2026 11:43
@Dav1dde
Dav1dde enabled auto-merge November 6, 2026 11:43
@Dav1dde
Dav1dde added this pull request to the merge queue Nov 6, 2026
Merged via the queue into getsentry:master with commit 00e7ff4 Nov 6, 2026
32 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.

5 participants