To turn this on for a python project, add a couple of lines to our typical sentry set up
# Configure Sentry for error logging
if os.getenv("SENTRY_DSN"):
sentry_sdk.init(
dsn=os.environ["SENTRY_DSN"],
...
+ enable_tracing=True,
+ traces_sample_rate=0.05,
)
enable_tracing turns on performing monitoring and traces_sample_rate set the rate at which sentry will sample events to profile. this shouldn't be too high, or it will use up all of the sentry performance units.
> heroku labs:enable runtime-dyno-metadata -a <app name>
then in your sentry setup:
if os.getenv("SENTRY_DSN"):
sentry_sdk.init(
dsn=os.environ["SENTRY_DSN"],
...
+ release=f"{os.environ['HEROKU_RELEASE_VERSION']}-{os.environ['HEROKU_APP_NAME']}",
)
That's all you have to do, but you can get a few more features if you also add a github action to associate commits with a release. Here is action for chi-councilmatic. You would need to adjust the app name:
I have been playing around with some sentry features that I've been finding interesting and maybe also useful.
1. performance monitoring
To turn this on for a python project, add a couple of lines to our typical sentry set up
enable_tracing
turns on performing monitoring andtraces_sample_rate
set the rate at which sentry will sample events to profile. this shouldn't be too high, or it will use up all of the sentry performance units.2. releases
Releases are way to tell sentry that errors coming from your app are associated with a particular deployment.
With heroku, this isn't too hard.
First, you have to turn on a setting in heroku to add some metadata about the dyno to the environmental variables of the dyno.
then in your sentry setup:
That's all you have to do, but you can get a few more features if you also add a github action to associate commits with a release. Here is action for chi-councilmatic. You would need to adjust the app name:
https://github.com/datamade/chi-councilmatic/blob/main/.github/workflows/associate_commits.yml