Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Sentry to report exceptions #26

Merged
merged 1 commit into from
Jul 17, 2017

Conversation

mars-f
Copy link
Contributor

@mars-f mars-f commented Jul 14, 2017

Does what is says on the tin. Sentry is shut off for local development. To use it you have to give Sentry a real DSN.

I have tested this change using the lando-api Sentry project. It reports errors correctly when they occur in a local development container. I think we can ship this.

Copy link

@ckolos ckolos left a comment

Choose a reason for hiding this comment

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

r+

from landoapi.dockerflow import dockerflow
from landoapi.models.storage import alembic, db
from mozlogging import MozLogFormatter

logger = logging.getLogger(__name__)

sentry = Sentry()

Choose a reason for hiding this comment

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

n00blyfe™ but why not initialize this in initialize_sentry since it's the only place it's used?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is a global, like logger, that can be used in other files to manually handle exceptions 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, will do. I was copying the docs, but you are totally right. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, it is not a bad thing that it is global. That will let us use it whereever we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can always extract it again if we need it.

landoapi/app.py Outdated
version_info = json.load(open(version_path))
logger.info(version_info, 'app.version')

this_app_version = version_info['commit']
Copy link
Contributor

Choose a reason for hiding this comment

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

Considering that there is a field specifically named 'version' I think we should use that instead of 'commit' even if they are equal right now, they could differ in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, I'll change it.

landoapi/app.py Outdated
logger.info(version_info, 'app.version')

this_app_version = version_info['commit']
environment = version_info['build']
Copy link
Contributor

@purelogiq purelogiq Jul 14, 2017

Choose a reason for hiding this comment

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

The version.json 'build' doesn't refer to the environment, it refers to the specific cirlce ci build that created this image (see https://circleci.com/docs/1.0/environment-variables/). With that in mind it cannot be used as the environment.

We could create another environment variable ('ENVIRONMENT' or something) and have @ckolos set it properly in dev, staging, and prod. Or we can switch based on the HOST_URL that is already available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I understand it, the environment is one way to partition the set of exceptions thrown by Sentry. Hostname is presumably another? But if you have multiple hosts per environment, like in prod, then partitioning the pool of exceptions coming from all the different environments by hostname might be a pain.

I like the ENVIRONMENT suggestion. I'd also like to know if Ops already has a way they do this. @ckolos, are you aware of any standard-ish way to get the environment label a host lives under into the container data so Sentry can report on it?

Copy link

Choose a reason for hiding this comment

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

"environment label a host lives under"... ?

You mean like "this is running in dev/stage/prod"? If so, that's available from the env as the ENV var.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ckolos perfect, thanks!

landoapi/app.py Outdated
"environment" identifier. See the Sentry client configuration docs
for details.
"""
sentry_dsn = os.environ.get('SENTRY_DSN', None)
Copy link
Contributor

Choose a reason for hiding this comment

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

The environment variable 'SENTRY_DSN' should be present in our docker-compose file even if it is empty or just a comment because our docker-compose defines all the environment variables needed to run the application. It is not used in production of course, it is just a good way to remind us what will be in the environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, I'll add it.

Copy link
Contributor

@purelogiq purelogiq left a comment

Choose a reason for hiding this comment

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

LGTM

@purelogiq purelogiq merged commit 6129bd9 into mozilla-conduit:master Jul 17, 2017
@mars-f mars-f deleted the use-sentry branch July 17, 2017 17:50
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.

4 participants