Skip to content

fix(sentry): Add sampler to fuction to block /health transactions - #232

Merged
dabeeeenster merged 4 commits into
mainfrom
fit/github-228/sentry-sampler
Aug 3, 2021
Merged

fix(sentry): Add sampler to fuction to block /health transactions#232
dabeeeenster merged 4 commits into
mainfrom
fit/github-228/sentry-sampler

Conversation

@gagantrivedi

Copy link
Copy Markdown
Member

No description provided.

Comment thread api/integrations/sentry/apps.py Outdated
@gagantrivedi gagantrivedi linked an issue Aug 2, 2021 that may be closed by this pull request
Comment thread api/integrations/sentry/samplers.py
@dabeeeenster

dabeeeenster commented Aug 2, 2021

Copy link
Copy Markdown
Contributor

Actually sorry @gagantrivedi but this needs to move out of the integrations/sentry area altogether. There are 2 ways Flagsmith uses sentry:

  1. As an APM for the API itself. This PR is related to that.
  2. For customers of the platform to send flag change events into their sentry installation. This is what integrations/sentry is for.

I think this code should live in app - what do you think @matthewelwell ?

Having said that - I've tested this and its working for me - stripping out health endpoint checks correctly. It just needs moving out of integrations.

@matthewelwell

Copy link
Copy Markdown
Contributor

I don't really see any reason why it needs to move out of the sentry package tbh? It's still code related to Sentry, it's just that there are multiple ways in which we use Sentry.

@dabeeeenster

Copy link
Copy Markdown
Contributor

OK lets leave it here - but add that test pls @gagantrivedi

@gagantrivedi

Copy link
Copy Markdown
Member Author

OK lets leave it here - but add that test pls @gagantrivedi

Sure, but is this working for you locally? i.e: can you see transaction generated locally on the sentry dashboard?

@dabeeeenster

Copy link
Copy Markdown
Contributor

Yes - transactions other than /health show up


def test_block_health_sampler_empty_context_returns_defaut_sample_rate():
# Given
settings.SENTRY_TRACE_SAMPLE_RATE = 10

@matthewelwell matthewelwell Aug 3, 2021

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.

It's better to use the @override_settings() decorator to do this so your tests become something like the following:

sample_rate = 10

@override_settings(SENTRY_TRACE_SAMPLE_RATE=sample_rate)
def test_block_health_sampler_empty_context_returns_defaut_sample_rate():
    assert block_health_sampler({}) == sample_rate

See documentation links here:

@matthewelwell matthewelwell 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.

Some minor changes so that we're reusing the variable we defined as much as possible.

sample_rate = block_health_sampler({})

# Then
assert sample_rate == 10

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.

Suggested change
assert sample_rate == 10
assert sample_rate == SAMPLE_RATE

sample_rate = block_health_sampler(ctx)

# Then
assert sample_rate == 10

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.

Suggested change
assert sample_rate == 10
assert sample_rate == SAMPLE_RATE

@dabeeeenster
dabeeeenster merged commit 5d2b409 into main Aug 3, 2021
@dabeeeenster
dabeeeenster deleted the fit/github-228/sentry-sampler branch August 3, 2021 09:25
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.

Don't send /health healthcheck transactions to Sentry

3 participants