Django + Sentry On-Prem + SNI SSL= Not Working?

June 20, 2018
Contact Us
Weekly Shorts are topics we discuss in our weekly remote meeting related to recent work we have done with our customers
Django + Sentry On-Prem + SNI SSL= Not Working?
Sentry logo

Last week we installed Sentry On-Premise to one of our customers.

One of the developers there complained that he couldn’t capture errors to the new Sentry via Django using Raven.
Checking the configuration, the DSN was set correctly.

When we ran Raven test to check the connection, everything seemed to be OK with output message of :

Sending a test message… 

#gist:<link rel="stylesheet" href="https://assets-cdn.github.com/assets/gist-embed-87673c31a5b37b5e6556b63e1081ebbc.css"><div id=\"gist90273132\" class=\"gist\">\n    <div class=\"gist-file\">\n      <div class=\"gist-data\">\n        <div class=\"js-gist-file-update-container js-task-list-container file-box\">\n  <div id=\"file-djangows01\" class=\"file\">\n    \n\n  <div itemprop=\"text\" class=\"blob-wrapper data type-text\">\n      <table class=\"highlight tab-size js-file-line-container\" data-tab-size=\"8\">\n      <tr>\n        <td id=\"file-djangows01-L1\" class=\"blob-num js-line-number\" data-line-number=\"1\"><\/td>\n        <td id=\"file-djangows01-LC1\" class=\"blob-code blob-code-inner js-file-line\">Sending a test message... Event ID was<\/td>\n      <\/tr>\n      <tr>\n        <td id=\"file-djangows01-L2\" class=\"blob-num js-line-number\" data-line-number=\"2\"><\/td>\n        <td id=\"file-djangows01-LC2\" class=\"blob-code blob-code-inner js-file-line\">'dafe440f48914de098a6f2c5aa6edca6'<\/td>\n      <\/tr>\n<\/table>\n\n\n  <\/div>\n\n  <\/div>\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https://gist.github.com/seanroisentul/896c0196e847cad5cffb41a10fa63ea0/raw/a88f7c496b95a8e52a391d19e5d40ed06bde1617/DjangoWS01\" style=\"float:right\">view raw<\/a>\n        <a href=\"https://gist.github.com/seanroisentul/896c0196e847cad5cffb41a10fa63ea0#file-djangows01\">DjangoWS01<\/a>\n        hosted with ❤ by <a href=\"https://github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n

Unfortunately, we couldn’t see any proper error registered to Sentry, so we checked again running:

#gist:<link rel="stylesheet" href="https://assets-cdn.github.com/assets/gist-embed-87673c31a5b37b5e6556b63e1081ebbc.css">
<div id=\"gist90272045\" class=\"gist\">\n <div class=\"gist-file\">\n <div class=\"gist-data\">\n <div class=\"js-gist-file-update-container js-task-list-container file-box\">\n <div id=\"file-djangows02\" class=\"file\">\n \n\n <div itemprop=\"text\" class=\"blob-wrapper data type-text\">\n <table class=\"highlight tab-size js-file-line-container\" data-tab-size=\"8\">\n <tr>\n <td id=\"file-djangows02-L1\" class=\"blob-num js-line-number\" data-line-number=\"1\"><\/td>\n <td id=\"file-djangows02-LC1\" class=\"blob-code blob-code-inner js-file-line\">tcpdump port 443<\/td>\n <\/tr>\n<\/table>\n\n\n <\/div>\n\n <\/div>\n<\/div>\n\n <\/div>\n <div class=\"gist-meta\">\n <a href=\"https://gist.github.com/seanroisentul/1d76fc67a72590808fd7d81a8d36c41c/raw/23b63610d85253e8ee27f7e8bd469e715a649cd8/DjangoWS02\" style=\"float:right\">view raw<\/a>\n <a href=\"https://gist.github.com/seanroisentul/1d76fc67a72590808fd7d81a8d36c41c#file-djangows02\">DjangoWS02<\/a>\n hosted with ❤ by <a href=\"https://github.com\">GitHub<\/a>\n <\/div>\n <\/div>\n<\/div>\n

to refute a network issue possibility.

After some research we imported logging with sentry error levels by adding the following code to the manage.py file:

#gist:<link rel="stylesheet" href="https://assets-cdn.github.com/assets/gist-embed-87673c31a5b37b5e6556b63e1081ebbc.css">
<div id=\"gist90272123\" class=\"gist\">\n <div class=\"gist-file\">\n <div class=\"gist-data\">\n <div class=\"js-gist-file-update-container js-task-list-container file-box\">\n <div id=\"file-djangows03\" class=\"file\">\n \n\n <div itemprop=\"text\" class=\"blob-wrapper data type-text\">\n <table class=\"highlight tab-size js-file-line-container\" data-tab-size=\"8\">\n <tr>\n <td id=\"file-djangows03-L1\" class=\"blob-num js-line-number\" data-line-number=\"1\"><\/td>\n <td id=\"file-djangows03-LC1\" class=\"blob-code blob-code-inner js-file-line\">import logging<\/td>\n <\/tr>\n <tr>\n <td id=\"file-djangows03-L2\" class=\"blob-num js-line-number\" data-line-number=\"2\"><\/td>\n <td id=\"file-djangows03-LC2\" class=\"blob-code blob-code-inner js-file-line\">logger = logging.getLogger(‘sentry.errors’)<\/td>\n <\/tr>\n <tr>\n <td id=\"file-djangows03-L3\" class=\"blob-num js-line-number\" data-line-number=\"3\"><\/td>\n <td id=\"file-djangows03-LC3\" class=\"blob-code blob-code-inner js-file-line\">logger.setLevel(logging.INFO)<\/td>\n <\/tr>\n <tr>\n <td id=\"file-djangows03-L4\" class=\"blob-num js-line-number\" data-line-number=\"4\"><\/td>\n <td id=\"file-djangows03-LC4\" class=\"blob-code blob-code-inner js-file-line\">logger.addHandler(logging.StreamHandler())<\/td>\n <\/tr>\n<\/table>\n\n\n <\/div>\n\n <\/div>\n<\/div>\n\n <\/div>\n <div class=\"gist-meta\">\n <a href=\"https://gist.github.com/seanroisentul/5cb28ee56bcf9deed160e2b323033efa/raw/1e6c5e01be68a274bbac0aef96457a486a49f842/DjangoWS03\" style=\"float:right\">view raw<\/a>\n <a href=\"https://gist.github.com/seanroisentul/5cb28ee56bcf9deed160e2b323033efa#file-djangows03\">DjangoWS03<\/a>\n hosted with ❤ by <a href=\"https://github.com\">GitHub<\/a>\n <\/div>\n <\/div>\n<\/div>\n

Trying to execute the raven test again we faced the following error:

#gist:<link rel="stylesheet" href="https://assets-cdn.github.com/assets/gist-embed-87673c31a5b37b5e6556b63e1081ebbc.css"><div id=\"gist90272152\" class=\"gist\">\n <div class=\"gist-file\">\n <div class=\"gist-data\">\n <div class=\"js-gist-file-update-container js-task-list-container file-box\">\n <div id=\"file-djangows04\" class=\"file\">\n \n\n <div itemprop=\"text\" class=\"blob-wrapper data type-text\">\n <table class=\"highlight tab-size js-file-line-container\" data-tab-size=\"8\">\n <tr>\n <td id=\"file-djangows04-L1\" class=\"blob-num js-line-number\" data-line-number=\"1\"><\/td>\n <td id=\"file-djangows04-LC1\" class=\"blob-code blob-code-inner js-file-line\">Sentry responded with an error: <\/td>\n <\/tr>\n <tr>\n <td id=\"file-djangows04-L2\" class=\"blob-num js-line-number\" data-line-number=\"2\"><\/td>\n <td id=\"file-djangows04-LC2\" class=\"blob-code blob-code-inner js-file-line\"><urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)><\/td>\n <\/tr>\n<\/table>\n\n\n <\/div>\n\n <\/div>\n<\/div>\n\n <\/div>\n <div class=\"gist-meta\">\n <a href=\"https://gist.github.com/seanroisentul/32628dd6ad5bb57211d599cb4f86ae9f/raw/fc2ba58a9037bcbf950a11b273f7989438ac8752/DjangoWS04\" style=\"float:right\">view raw<\/a>\n <a href=\"https://gist.github.com/seanroisentul/32628dd6ad5bb57211d599cb4f86ae9f#file-djangows04\">DjangoWS04<\/a>\n hosted with ❤ by <a href=\"https://github.com\">GitHub<\/a>\n <\/div>\n <\/div>\n<\/div>\n

SSL was valid using “Lets’s Encrypt” service , but we couldn't understand why it fails verifying the SSL certificate.

Well, it seemed like there was a current issue with Raven which didn’t support SNI(Server Name Indication, an extension to TLS protocol).We resolved this issue by adding the following configuration to raven:

#gist:<link rel="stylesheet" href="https://assets-cdn.github.com/assets/gist-embed-87673c31a5b37b5e6556b63e1081ebbc.css"><div id=\"gist90272170\" class=\"gist\">\n <div class=\"gist-file\">\n <div class=\"gist-data\">\n <div class=\"js-gist-file-update-container js-task-list-container file-box\">\n <div id=\"file-djangows05\" class=\"file\">\n \n\n <div itemprop=\"text\" class=\"blob-wrapper data type-text\">\n <table class=\"highlight tab-size js-file-line-container\" data-tab-size=\"8\">\n <tr>\n <td id=\"file-djangows05-L1\" class=\"blob-num js-line-number\" data-line-number=\"1\"><\/td>\n <td id=\"file-djangows05-LC1\" class=\"blob-code blob-code-inner js-file-line\">from raven.transport.requests import RequestsHTTPTransport RAVEN_CONFIG = { <\/td>\n <\/tr>\n <tr>\n <td id=\"file-djangows05-L2\" class=\"blob-num js-line-number\" data-line-number=\"2\"><\/td>\n <td id=\"file-djangows05-LC2\" class=\"blob-code blob-code-inner js-file-line\">‘dsn’: ‘…’, <\/td>\n <\/tr>\n <tr>\n <td id=\"file-djangows05-L3\" class=\"blob-num js-line-number\" data-line-number=\"3\"><\/td>\n <td id=\"file-djangows05-LC3\" class=\"blob-code blob-code-inner js-file-line\">‘transport’: RequestsHTTPTransport, <\/td>\n <\/tr>\n <tr>\n <td id=\"file-djangows05-L4\" class=\"blob-num js-line-number\" data-line-number=\"4\"><\/td>\n <td id=\"file-djangows05-LC4\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n <\/tr>\n<\/table>\n\n\n <\/div>\n\n <\/div>\n<\/div>\n\n <\/div>\n <div class=\"gist-meta\">\n <a href=\"https://gist.github.com/seanroisentul/ba1a91fa39702dc26eb6490fe69f6ff6/raw/b043ba2bc2714986529e78e238107e46fee08610/DjangoWS05\" style=\"float:right\">view raw<\/a>\n <a href=\"https://gist.github.com/seanroisentul/ba1a91fa39702dc26eb6490fe69f6ff6#file-djangows05\">DjangoWS05<\/a>\n hosted with ❤ by <a href=\"https://github.com\">GitHub<\/a>\n <\/div>\n <\/div>\n<\/div>\n

Everything is now working and the developers have started using the new Sentry server.

Further information if you are interested:

Django + Sentry On-Prem + SNI SSL= Not Working?
Zvika Nadav
Operations Engineer
Experienced in automation testing as well as a networking background, being CCNA certified with CCNP knowledge. HIs knowledge includes coding, development, networking, and automation. He has designed automation frameworks and increased the automation performance by 50%. For his enjoyment, he likes video games, movies and streaming. He is passionate about technology and how he can “make things as simple as possible, but no simpler” as Einstein once said. He is often speaking at meetups and blog posting. His strength is that he can be thrown into any ocean and he'll manage to swim. He has the ability to teach others, even on a topic that he has just been revealed to.