Skip to content

Feat: Sentry rate limiting - #2366

Open
nhoening wants to merge 4 commits into
mainfrom
feat/sentry-rate-limiting
Open

Feat: Sentry rate limiting#2366
nhoening wants to merge 4 commits into
mainfrom
feat/sentry-rate-limiting

Conversation

@nhoening

@nhoening nhoening commented Jul 28, 2026

Copy link
Copy Markdown
Member

Description

On Sentry, we might be on a certain plan, e.g. 5k errors per month.
This PR adds a config setting to rate limit Sentry errors we send to the platform, capped at some amount each day. That way, hosts can spread out errors over the month, instead of spending it all early, then seeing no activity for the remainder.

That setting FLEXMEASURES_SENTRY_DAILY_RATE_LIMIT defaults to None, which leads to no rate limit, or should be a positive integer otherwise.

  • add and use FLEXMEASURES_SENTRY_DAILY_RATE_LIMIT
  • do not log errors when alembic revision is not on head, just warn
  • Added changelog item in documentation/changelog.rst

nhoening added 2 commits July 28, 2026 18:24
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
… warn

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening
nhoening requested a review from BelhsanHmida July 28, 2026 16:38
@nhoening nhoening self-assigned this Jul 28, 2026
@nhoening nhoening added this to the 1.0.0 milestone Jul 28, 2026
@read-the-docs-community

read-the-docs-community Bot commented Jul 28, 2026

Copy link
Copy Markdown

Flix6x and others added 2 commits July 29, 2026 21:07
Signed-off-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>

@BelhsanHmida BelhsanHmida left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. I left a couple of comments on some things i wanted to point out before approving.

)
else:
app.logger.error(
app.logger.warning(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just confirming the intention here: since production logging defaults to ERROR, changing this to WARNING means the schema mismatch won't appear in production logs or Sentry.

hour=0, minute=0, second=0, microsecond=0
) + timedelta(days=1)
pipeline = redis_connection.pipeline()
pipeline.incr(counter_key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

small edge case: if a host configures error sampling, sampled-out events will still use this allowance because sampling happens after before_send.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Does "error sampling" refer to a Sentry setting, where only randomized events are sent (I see the traces_sample_rate param).
That might not be a small edge case - those two approaches might not work well, at least we will actually see much less events actually in Sentry if both are active.

Full disclosure: I am not educated in Sentry error sampling right now.

pipeline = redis_connection.pipeline()
pipeline.incr(counter_key)
pipeline.expireat(counter_key, int(expires_at.timestamp()))
event_count, _ = pipeline.execute()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this runs inside Sentry's before_send and the Redis client doesn't have a timeout. If Redis accepts the connection but stops responding, the request/job could hang here instead of failing open. Should we use a separate Redis client with a short timeout for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants