Sentry is attempting to send 2 pending error messages

django: sending an event from settings module swallows exceptions #1148 Comments I’ve noticed that using the recommended way of setting up Sentry in Django’s settings.py causes exceptions to be swallowed, if you also trigger sending an event from there directly. Given the following in settings.py , before INSTALLED_APPS : If there then is an […]

Содержание

  1. django: sending an event from settings module swallows exceptions #1148
  2. Comments
  3. Sentry SDK 407 Proxy Auth #1246
  4. Comments
  5. Environment
  6. Steps to Reproduce
  7. Expected Result
  8. Actual Result
  9. fmriprep recon-all #1554
  10. Comments
  11. Sentry is noisy on process exit #904
  12. Comments
  13. Public DSN not working — requires private DSN #24
  14. Comments

django: sending an event from settings module swallows exceptions #1148

I’ve noticed that using the recommended way of setting up Sentry in Django’s settings.py causes exceptions to be swallowed, if you also trigger sending an event from there directly.

Given the following in settings.py , before INSTALLED_APPS :

If there then is an error later in settings.py , e.g. an ImportError like above, it gets swallowed, which results in the following:

Whereas when putting the failing import before sending of the event it will result in the expected (far more helpful) output:

The problem appears to be that sending of the event triggers settings to be touched
It looks like (queuing of) sending an event triggers Django’s django.conf.settings.configured to become True, via:

Relevant code in Django, where this is happening, and it then either has settings configured there then (when an event is sent through Sentry), or not (when no event is being sent already): https://github.com/django/django/blob/843c34b3ab921c1acf77ee2014a97bc7975595b8/django/core/management/__init__.py#L362-L369

I can investigate further, but wanted to leave this here already for now.
Also, I think that the recommended way / suitable workaround probably is to not send an event from there already, but only when apps are ready anyway.

Note that when not emitting a manual event before the error (in settings.py ) it will not get swallowed, but also not reported to Sentry.

It also happens with the current sentry-sdk==1.3.0.

The text was updated successfully, but these errors were encountered:

Источник

Sentry SDK 407 Proxy Auth #1246

Environment

How do you use Sentry?
Sentry SaaS (sentry.io)

Which SDK and version?
sentry-sdk>=0.17.

Steps to Reproduce

  1. I setup a docker running python3.7 image
  2. I initialized the Sentry sdk with Google Cloud Functions integration
  3. When an error comes it fails to send the messages to sentry.

Expected Result

I expect the errors to appear in sentry.

Actual Result

The text was updated successfully, but these errors were encountered:

It looks like it is failing because I have logging.basicConfig(stream=sys.stdout, level=logging.INFO) . When I remove that line, everything works. I tried adding the LoggingIntegration and included that line but it still gives me those errors.

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress , I will leave it alone . forever!

«A weed is but an unloved flower.» ― Ella Wheeler Wilcox 🥀

Hey @atlys-osmar !
Thanks for reporting this and sorry for getting back at you that late.

One thought: Could it be that setting this logging.basicConfig sets the logging in Google Cloud Platform to log to a Google Logging service, and you do not have permissions or the setup for this logging service?
(I am just guessing here, I have no clue about Google Cloud Platform 🙂 )

As you are using a quite old SDK try to upgrade to the newest version.

Or maybe you have already solved your issue? If yes, I would be curious how you fixed this problem?

Источник

fmriprep recon-all #1554

Hi everybody,
I am new user with python and fmriprep and I tried to run the fmriprep using fieldmap less correction of distortions.
I couldn’t succed in for the moment and I am looking for some feedbacks to solve this. I put a copy of the message here:

bpo70+1 (2017-02-24) x86_64 x86_64 x86_64 GNU/Linux ‘/opt/freesurfer/bin/recon-all’ -> ‘/out/freesurfer/sub-01/scripts/recon-all.local-copy’ #——————————————— #@# MotionCor Wed Mar 20 13:29:55 UTC 2019 ERROR: no run data found in /out/freesurfer/sub-01/mri. Make sure to have a volume called 001.mgz in /out/freesurfer/sub-01/mri/orig. If you have a second run of data call it 002.mgz, etc. See also: http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Conversion Linux 1350f8924bf1 3.16.0-0.bpo.4-amd64 #1 SMP Debian 3.16.39-1+deb8u1

bpo70+1 (2017-02-24) x86_64 x86_64 x86_64 GNU/Linux recon-all -s sub-01 exited with ERRORS at Wed Mar 20 13:29:55 UTC 2019 For more details, see the log file /out/freesurfer/sub-01/scripts/recon-all.log To report a problem, see http://surfer.nmr.mgh.harvard.edu/fswiki/BugReporting Standard error: Return code: 1 Preprocessing did not finish successfully. Errors occurred while processing data from participants: 01 (1). Check the HTML reports for details. Traceback (most recent call last): File «/usr/local/miniconda/bin/fmriprep», line 11, in load_entry_point(‘fmriprep==1.3.1.post2’, ‘console_scripts’, ‘fmriprep’)() File «/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/cli/run.py», line 436, in main fmriprep_wf.run(**plugin_settings) File «/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/workflows.py», line 599, in run runner.run(execgraph, updatehash=updatehash, config=self.config) File «/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/plugins/base.py», line 161, in run self._clean_queue(jobid, graph, result=result)) File «/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/plugins/base.py», line 224, in _clean_queue raise RuntimeError(«».join(result[‘traceback’])) RuntimeError: Traceback (most recent call last): File «/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/plugins/multiproc.py», line 69, in run_node result[‘result’] = node.run(updatehash=updatehash) File «/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py», line 473, in run result = self._run_interface(execute=True) File «/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py», line 557, in _run_interface return self._run_command(execute) File «/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py», line 637, in _run_command result = self._interface.run(cwd=outdir) File «/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/base/core.py», line 375, in run runtime = self._run_interface(runtime) File «/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/base/core.py», line 758, in _run_interface self.raise_exception(runtime) File «/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/base/core.py», line 695, in raise_exception ).format(**runtime.dictcopy())) RuntimeError: Command: recon-all -autorecon1 -noskullstrip -openmp 8 -subjid sub-01 -sd /out/freesurfer Standard output: Subject Stamp: freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.1-f53a55a Current Stamp: freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.1-f53a55a INFO: SUBJECTS_DIR is /out/freesurfer Actual FREESURFER_HOME /opt/freesurfer -rw-rw-r— 1 root root 34452 Mar 20 11:33 /out/freesurfer/sub-01/scripts/recon-all.log Linux 1350f8924bf1 3.16.0-0.bpo.4-amd64 #1 SMP Debian 3.16.39-1+deb8u1

bpo70+1 (2017-02-24) x86_64 x86_64 x86_64 GNU/Linux ‘/opt/freesurfer/bin/recon-all’ -> ‘/out/freesurfer/sub-01/scripts/recon-all.local-copy’ #——————————————— #@# MotionCor Wed Mar 20 13:29:55 UTC 2019 ERROR: no run data found in /out/freesurfer/sub-01/mri. Make sure to have a volume called 001.mgz in /out/freesurfer/sub-01/mri/orig. If you have a second run of data call it 002.mgz, etc. See also: http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/Conversion Linux 1350f8924bf1 3.16.0-0.bpo.4-amd64 #1 SMP Debian 3.16.39-1+deb8u1

bpo70+1 (2017-02-24) x86_64 x86_64 x86_64 GNU/Linux recon-all -s sub-01 exited with ERRORS at Wed Mar 20 13:29:55 UTC 2019 For more details, see the log file /out/freesurfer/sub-01/scripts/recon-all.log To report a problem, see http://surfer.nmr.mgh.harvard.edu/fswiki/BugReporting Standard error: Return code: 1 Sentry is attempting to send 2 pending error messages Waiting up to 2.0 seconds Press Ctrl-C to quit fMRIPrep: Please report errors to https://github.com/poldracklab/fmriprep/issues»>

The text was updated successfully, but these errors were encountered:

Источник

Sentry is noisy on process exit #904

We are using Sentry to report errors from cron tasks. We have MAILTO set as a backup so that we receive emails about critical errors which happen before raven has a chance to initialize.

This leads to us getting the occasional email containing:

It happens because there’s a hardcoded initial_timeout of 0.1 seconds in the process exit hook. Is there any chance you could make this timeout configurable the way shutdown_timeout is?

The text was updated successfully, but these errors were encountered:

And we are receiving this message even if —verbosity 0 is set.

Since all django commands accept the verbosity option, it would be nice if raven_compat complies with it.

@ollb this isn’t a Django feature, and while I agree we should allow some ability to make this less noisy, we’re not going to make a one-off to try and support an arbitrary Django flag.

@dcramer At least would it be ok to have an option to control raven verbosity ? (I’m very new with raven and so I do not understand what is at stake).

By the way, I’m not sure what do you mean by «an arbitrary django flag». Since —verbosity is a flag defined in BaseCommand django class it should be usable by any django command. That said, I understand this might be a specific issue. So let’s handle the first one.

@OliB I mean arbitrary in that sentry is far wider reaching than just Django and it’s not a management command that is happening for Sentry reporting.

Is it ok if this noise will be printed to stderr? I want to do so, but I’m not sure if it’s enough.

We ended up solving the problem by putting a call to this function at the end of our scripts:

It’s ugly, but I think it’s the best we can do without forking the library.

what about this issue? is there any progress?

Источник

Public DSN not working — requires private DSN #24

We’ve been attempting to make use of this plugin, however we found that a public DSN doesn’t quite work for us. We see this appear in the logs but nothing in Sentry itself.

However, the moment we switch to a private DSN (one where it contains the secret). then it works fine.

I’m using the latest version of this plugin (at time of writing), Airflow version 1.10.3 & Sentry SDK 0.11.2.

Any reason as to why it was originally coded to work with a public DSN only? Is there some config we are missing?

The text was updated successfully, but these errors were encountered:

The plugin should allow you to use a public DSN. Do you mind describing how you are running Sentry (on-premise docker, SAAS, etc)?

Sure, it’s on-premise, version 8.12.0.

How are you setting the DSN? Are you using the SENTRY_DSN environmental variable, or are you setting a sentry_dsn connection in the Airflow webserver UI?

We tried both but public DSN just didn’t work for some reason — maybe it could be down to how our Sentry is setup, but either way the private DSN works just fine 🙂

We did have to make a subtle tweak to the Sentry hook ( def get_dsn(conn): ) to get the private DSN to work
dsn = ‘https://:@/‘.format(conn=conn)

Yh we hardcoded the protocol to HTTPS as our Sentry is lives behind HTTPS but in Airflow, there is only a HTTP connection type, no . HTTPS yet.

Without more context on your setup, I’m not sure I can debug further, I will be closing the issue seeing that using a private DSN still works fine.

Источник

Skip to content



Open


Issue created Nov 13, 2021 by Alick@Alick

Integrated Error Tracking: ParseError (809: unexpected token at »)

Summary

  • I am using self-hosted Gitlab with traefik as a load-balancer.
  • I’ve upgraded my image to the latest (14.5) release.
  • Made everything by instructions (https://docs.gitlab.com/ee/operations/error_tracking.html#error-tracking)

But using sentry-sdk it doesn’t works, shows me 400-bad request error.

Logs from the client looks like this:

 [sentry] DEBUG: Setting up integrations (with default = True)
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.django.DjangoIntegration: Django not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.flask.FlaskIntegration: Flask is not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.bottle.BottleIntegration: Bottle not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.falcon.FalconIntegration: Falcon not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.sanic.SanicIntegration: Sanic not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.celery.CeleryIntegration: Celery not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.rq.RqIntegration: RQ not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.aiohttp.AioHttpIntegration: AIOHTTP not installed
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.sqlalchemy.SqlalchemyIntegration: SQLAlchemy not installed.
 [sentry] DEBUG: Did not import default integration sentry_sdk.integrations.boto3.Boto3Integration: botocore is not installed
 [sentry] DEBUG: Setting up previously not enabled integration logging
 [sentry] DEBUG: Setting up previously not enabled integration stdlib
 [sentry] DEBUG: Setting up previously not enabled integration excepthook
 [sentry] DEBUG: Setting up previously not enabled integration dedupe
 [sentry] DEBUG: Setting up previously not enabled integration atexit
 [sentry] DEBUG: Setting up previously not enabled integration modules
 [sentry] DEBUG: Setting up previously not enabled integration argv
 [sentry] DEBUG: Setting up previously not enabled integration threading
 [sentry] DEBUG: Setting up previously not enabled integration tornado
 [sentry] DEBUG: Did not enable default integration tornado: The tornado integration for Sentry requires Python 3.7+ or the aiocontextvars package

With asyncio/ASGI applications, the Sentry SDK requires a functional
installation of `contextvars` to avoid leaking scope/context data across
requests.

Please refer to https://docs.sentry.io/platforms/python/contextvars/ for more information.

 [sentry] DEBUG: Enabling integration logging
 [sentry] DEBUG: Enabling integration stdlib
 [sentry] DEBUG: Enabling integration excepthook
 [sentry] DEBUG: Enabling integration dedupe
 [sentry] DEBUG: Enabling integration atexit
 [sentry] DEBUG: Enabling integration modules
 [sentry] DEBUG: Enabling integration argv
 [sentry] DEBUG: Enabling integration threading
 [sentry] DEBUG: Enabling integration tornado
 [sentry] DEBUG: Sending event, type:null level:error event_id:<actual-value-hidden> project:4 host:git.wader.dev
 [sentry] DEBUG: atexit: got shutdown signal
 [sentry] DEBUG: atexit: shutting down client
 [sentry] DEBUG: Flushing HTTP transport
 [sentry] DEBUG: background worker got flush request
 [sentry] DEBUG: [Tracing] Adding `sentry-trace` header <actual-value-hidden> to outgoing request to https://<actual-value-hidden>/api/v4/error_tracking/collector/api/4/store/.
 [sentry] DEBUG: 2 event(s) pending on flush
Sentry is attempting to send 2 pending error messages
Waiting up to 2 seconds
Press Ctrl-Break to quit
 [sentry] ERROR: Unexpected status code: 400 (body: b'')
 [sentry] DEBUG: Sending envelope [envelope with 1 items (internal)] project:4 host:<actual-value-hidden>
 [sentry] DEBUG: [Tracing] Adding `sentry-trace` header <actual-value-hidden> to outgoing request to https://<actual-value-hidden>/api/v4/error_tracking/collector/api/4/envelope/.
 [sentry] ERROR: Unexpected status code: 400 (body: b'{"message":"400 Bad Request"}')
 [sentry] DEBUG: background worker flushed
 [sentry] DEBUG: Killing HTTP transport
 [sentry] DEBUG: background worker got kill request

From the gitlab logs I see this:

 ==> /var/log/gitlab/nginx/gitlab_access.log <==
 172.19.0.5 - - [13/Nov/2021:10:00:18 +0000] "POST /api/v4/jobs/request HTTP/1.1" 204 0 "" "gitlab-runner 14.3.2 (14-3-stable; go1.13.8; linux/amd64)" -

 ==> /var/log/gitlab/gitlab-rails/production.log <==
 Started POST "/api/v4/error_tracking/collector/api/4/store/" for 109.252.72.42 at 2021-11-13 10:00:18 +0000

 ActionDispatch::Http::Parameters::ParseError (809: unexpected token at '^_�^H'):

 lib/gitlab/middleware/handle_malformed_strings.rb:37:in `request_contains_malformed_string?'
 lib/gitlab/middleware/handle_malformed_strings.rb:19:in `call'
 lib/gitlab/middleware/basic_health_check.rb:25:in `call'
 lib/gitlab/middleware/handle_ip_spoof_attack_error.rb:25:in `call'
 lib/gitlab/middleware/request_context.rb:21:in `call'
 config/initializers/fix_local_cache_middleware.rb:11:in `call'
 lib/gitlab/middleware/rack_multipart_tempfile_factory.rb:19:in `call'
 lib/gitlab/middleware/sidekiq_web_static.rb:20:in `call'
 lib/gitlab/metrics/requests_rack_middleware.rb:75:in `call'
 lib/gitlab/middleware/release_env.rb:12:in `call'

This logs I get redirecting output to file and opening it in vim. Using usual cat or docker logs command I see unexpected token at ''. It seems that it’s unprintable characters.

Steps to reproduce

Traefik has been setup to work with https and redirect all http requests to https.
I am using next code to test error tracking (from #340178):

import sentry_sdk

sentry_sdk.init(
    'https://glet_HASH@HOST/api/v4/error_tracking/collector/4,
    debug=True,
    traces_sample_rate=1.0,
)

sentry_sdk.capture_exception(Exception("asd"))
#division_by_zero = 1 / 0

Some details

Using dsn from usual sentry (sentry.io) in test script everything works.

I also have changed dsn value get from my gitlab.

I’ve tried to use original ‘http://…’ but I get error 404-page not found and nothing in gitlab logs, so I’ve changed it to ‘https://…’ (changed http to https only) and get a different error and something in gitlab logs.

Edited Nov 13, 2021 by Alick

Recommend Projects

  • React photo

    React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo

    Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo

    Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo

    TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo

    Django

    The Web framework for perfectionists with deadlines.

  • Laravel photo

    Laravel

    A PHP framework for web artisans

  • D3 photo

    D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Visualization

    Some thing interesting about visualization, use data art

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo

    Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo

    Microsoft

    Open source projects and samples from Microsoft.

  • Google photo

    Google

    Google ❤️ Open Source for everyone.

  • Alibaba photo

    Alibaba

    Alibaba Open Source for everyone

  • D3 photo

    D3

    Data-Driven Documents codes.

  • Tencent photo

    Tencent

    China tencent open source team.

Sentry is an open source application exception tracking system, which is supported by Django+DRF+Celery+ celery-beat. If you are Pythoner and are familiar with these technical stack, Sentry uses Django+DRF+Celery+ celery-beat. You can read the relevant source code, and there are a lot of things to learn. It is worth mentioning that Sentry only supports Python2, not Python3, when deployed.

In this article we will deploy Sentry as Docker, which is the official recommended deployment, and write a simple Django application that uses email and spikes to notify the developer of any exceptions that occur.

The environment

I ran a cloud server on Vultr for this test, using CentOS7.

Initialization operation

Install the epel source


     
  1. $ yum install epel-release -y

Copy the code

Update the system


     
  1. $ yum update -y

Copy the code

Install some toolkits


     
  1. $ yum install python-pip vim git -y

Copy the code

You are advised to restart the system


     
  1. $ reboot

Copy the code

The basic configuration

  • memory


     
  1. $ free -h

  2.              total        used        free      shared  buff/cache   available

  3. Mem:           3.7G         95M        3.4G        8.4M        168M        3.4G

  4. Swap:            0B          0B          0B

Copy the code
  • CPU


     
  1. $ cat /proc/cpuinfo | grep processor | wc -l

  2. 2

Copy the code

The configuration is also 2H4G, if you are a server with 1G memory, it seems that IT is difficult for me to run on Tencent cloud, I feel at least 2G.

Install the Docker

The installation of CentOS series of documents on: https://docs.docker.com/install/linux/docker-ce/centos/, interested can go to reading, I’ll simplify some operations here.

  • Install some software packages


     
  1. $ yum install -y yum-utils device-mapper-persistent-data lvm2

Copy the code
  • Add the Docker’s repo source


     
  1. $ yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Copy the code
  • Install the docker


     
  1. $ yum install docker-ce -y

Copy the code
  • Start the docker


     
  1. $ systemctl start docker

Copy the code
  • Self-start upon startup


     
  1. $ systemctl enable docker

Copy the code
  • View the Docker version


     
  1. $ docker --version

  2. Docker version 18.03.1-ce, build 9ee9f40

Copy the code
  • Run a hello-world


     
  1. $ docker run hello-world

  2. Unable to find image 'hello-world:latest' locally

  3. latest: Pulling from library/hello-world

  4. 9db2ca6ccae0: Pull complete

  5. Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc

  6. Status: Downloaded newer image for hello-world:latest

  7. Hello from Docker!

  8. This message shows that your installation appears to be working correctly.

  9. To generate this message, Docker took the following steps:

  10. 1. The Docker client contacted the Docker daemon.

  11. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

  12.    (amd64)

  13. 3. The Docker daemon created a new container from that image which runs the

  14.    executable that produces the output you are currently reading.

  15. 4. The Docker daemon streamed that output to the Docker client, which sent it

  16.    to your terminal.

  17. To try something more ambitious, you can run an Ubuntu container with:

  18. $ docker run -it ubuntu bash

  19. Share images, automate workflows, and more with a free Docker ID:

  20. https://hub.docker.com/

  21. For more examples and ideas, visit:

  22. https://docs.docker.com/engine/userguide/

Copy the code

If you get the same results as ME, then, OK, Docker is installed.

If you use a domestic server, it may be unusually slow in the pull image, so the official provides domestic Docker image acceleration, point me point me, after the configuration must remember to restart the Docker service, otherwise the configuration cannot be loaded, restart the command is as follows:

                                
     
  1. $ systemctl restart docker

Copy the code

Install the docker — compose


     
  1. https://github.com/docker/compose/releases/download/1.21.2/docker-compose- $curl - L ` ` uname - s - ` uname -m ` - o /usr/local/bin/docker-compose

  2. $ chmod +x /usr/local/bin/docker-compose

Copy the code

I installed is 1.21.2 version, usually you install the docker and docker — compose is the latest version will not have what problem, check the docker — compose version

                                    
     
  1. $ docker -compose -- version

  2. Docker-compose version 1.21.2, Build A133471

Copy the code

Install the Sentry

Finally, the key step, Sentry, officially provides a complete set of Docker deployment mode to run Sentry.

  • Download the project


     
  1. $ cd /opt/

  2. $ git clone https://github.com/getsentry/onpremise.git sentry

  3. $ cd sentry

Copy the code
  • Create the database and Sentry configuration directory


     
  1. $ mkdir -p data/{sentry,postgres}

Copy the code
  • Add some dependency libraries


     
  1. $ vim requirements.txt

  2. # Add plugins here

  3. Sentry-dingding ~=0.0.1 # pin notification plugin

  4. Django-smtp-ssl ~=1.0 # Supports SSL for sending emails

Copy the code
  • Build the Docker image


     
  1. $ docker-compose build

Copy the code
  • Generate the key


     
  1. $ docker-compose run --rm web config generate-secret-key

  2. .

  3. The last line will output a secret key similar to the following

  4. kbjodp(idb0^kbnxijn112e6xuvy1(oini! -zl)pl610nv

Copy the code

Add the above key to the SENTRY_SECRET_KEY environment variable in the docker-comemage. yml file

                                            
     
  1. $ vim docker -compose. yml

  2. .

  3. SENTRY_SECRET_KEY : 'kbjodp(idb0^kbnxijn112e6xuvy1(oini! -zl)pl610nv'

Copy the code
  • Generate database tables and create administrator users


     
  1. $ docker-compose run --rm web upgrade

  2. .

  3. Would you like to create a user account now? [Y/n]: Y # Create a user

  4. Email: [email protected] #

  5. Password: # Password

  6. Repeat for confirmation: #

  7. Should this user be a superuser? [y/N]: y # is the super administrator

Copy the code
  • Start the service


     
  1. $ docker-compose up -d

Copy the code

You can use docker-compose PS to see which containers are started

                                                
     
  1. $ docker -compose ps

  2. Name Command State Ports

  3. ------------------------------------------------------------------------------------

  4. sentry_cron_1 /entrypoint. sh run cron Up 9000 /tcp

  5. sentry_memcached_1 docker -entrypoint. sh memcached Up 11211 /tcp

  6. sentry_postgres_1 docker -entrypoint. sh postgres Up 5432 /tcp

  7. sentry_redis_1 docker -entrypoint. sh redis ... Up 6379 /tcp

  8. sentry_smtp_1 docker -entrypoint. sh tini ... Up 25 /tcp

  9. Sentry_web_1 /entrypoint. sh run Web Up 0.0.0.0 :9000 -9000 / TCP

  10. sentry_worker_1 /entrypoint. sh run worker Up 9000 /tcp

Copy the code

The above services are described as follows:

The name of the describe
sentry_cron Scheduled task, usingcelery-beat
sentry_memcached memcached
sentry_postgres PGSQL database
sentry_redis Run celery required services
sentry_smtp email
sentry_web usedjango+drfWrite a setSentry Web interface
sentry_worker Celery worker service, used to run asynchronous tasks

When the service is started, it listens on port 9000 by default. If you want to change it, you can do so in docker-comemage.yml.

I added an A record to my domain name ansheng.me. The record value is sentry, which points to the cloud server of Sentry, so it can be accessed through sentry.ansheng. me.

Basic Sentry Settings

The browser open http://sentry.ansheng.me:9000/, enter email address and password to log in

Once logged in successfully, enter the corresponding RootURL and Admin Email, and click Continue

Clicking takes you to the main Sentry screen

Add a Python project

Click Addnew in the upper right corner and select Project

And then create the project

After the project has been created, a use screen appears

Testing Python programs

Following the above steps, let’s do it step by step. I’m operating on my server, and the Python version is as follows:


     
  1. $ python -V

  2. Python 2.7.5

Copy the code
  • Install the raven


     
  1. $ pip install raven --upgrade

Copy the code
  • Adding test code


     
  1. $ vim sentry_python_test.py

  2. from raven import Client

  3. client = Client('http://ce5502f746a4484f9b2c391a54d2d1c4:[email protected]:9000/2')

  4. try:

  5. 1/0

  6. except ZeroDivisionError:

  7.    client.captureException()

Copy the code
  • run


     
  1. $ python sentry_python_test.py

  2. Sentry is attempting to send 1 pending error messages

  3. Waiting up to 10 seconds

  4. Press Ctrl-C to quit

Copy the code

Check the abnormal

In the usage screen above, click Gotit~Takeme to theIssueStream. Enter the project’s Issue page, or error page

You can see that there is already an exception. This exception is the error that we caught when we tested. Click on the heading of ZeroDivisionError to enter the detailed page of the exception.

On the project page, you can see MESSAGE and EXCEPTION, which output the error details

Basically the steps are the same as above, the flow is similar

Add Django projects and monitor them

Follow the steps above to create the PythonSentry project and add a Django framework project named Cash and save the DSN record values

http://9ad8168873a94fb1927e14111b9bca1e:[email protected]:9000/3

Creating a Django project

Django projects I created on my computer.

  • Add a virtual environment named Cash


     
  1. $pyEnv VirtualEnv 3.6.5 cash

Copy the code
  • Switching virtual Environments


     
  1. $ pyenv activate cash

Copy the code
  • Install django


     
  1. $ pip install django

Copy the code
  • Create a project


     
  1. $ cd /tmp

  2. $ django-admin startproject cash

  3. $ cd cash

  4. $ python manage.py migrate

Copy the code
  • Start the project


     
  1. $ python manage.py runserver 0:9999

  2. Performing system checks...

  3. System check identified no issues (0 silenced).

  4. July 17, 2018 - 03:35:05

  5. Django version 2.0.7, using settings 'cash.settings'

  6. Starting development server at http://0:9999/

  7. Quit the server with CONTROL-C.

Copy the code

Port listening at 9999, you can use curl to test access

                                                                                                                                            
     
  1. $curl -i HTTP :// 127.0.1:9999

  2. HTTP / 1.1 200 OK

  3. .

Copy the code

A status of 200 indicates no problem

  • Viewing the directory Structure


     
  1. ➜  cash tree ./

  2. . /

  3. ├ ─ ─ cash

  4. │ ├ ─ ─ just set py

  5. │ ├ ─ ─ Settings. Py

  6. │ ├ ─ ─ urls. Py

  7. │ ├ ─ ─ views. Py

  8. │ └ ─ ─ wsgi. Py

  9. ├ ─ ─ the sqlite3

  10. └ ─ ─ the manage. Py

Copy the code
  • Write a simple view


     
  1. $ vim cash/views.py

  2. from django.http import HttpResponse

  3. def success(request):

  4.    return HttpResponse("OK")

  5. def error(request):

  6. 1/0

  7.    return HttpResponse("Not OK")

Copy the code
  • Add the url


     
  1. $ vim cash/urls.py

  2. from django.urls import path

  3. from . import views

  4. urlpatterns = [

  5.    path('success', views.success, name='success'),

  6.    path('error', views.error, name='error'),

  7. ]

Copy the code
  • Access to the test

Access the API that returns success


     
  1. $curl http://127.0.0.1:9999/success

  2. OK

Copy the code

Accessing an ERROR reporting API


     
  1. $curl -i http://127.0.0.1:9999/error

  2. HTTP/1.1 500 Internal Server Error

  3. .

Copy the code

An error of 500 was reported, and the log output is as follows

                                                                                                                                                
     
  1. Internal Server Error : /error

  2. Traceback ( most recent call last ):

  3. The File "/ Users/shengan /. / lib/python3.6 pyenv/versions/cash/site - packages/django/core/handlers/exception. Py", line 35, in inner

  4. response = get_response (request )

  5. The File "/ Users/shengan /. / lib/python3.6 pyenv/versions/cash/site - packages/django/core/handlers/base. Py", line 128, in _get_response

  6. response = self. process_exception_by_middleware( e, request)

  7. The File "/ Users/shengan /. / lib/python3.6 pyenv/versions/cash/site - packages/django/core/handlers/base. Py", line 126, in _get_response

  8. response = wrapped_callback (request , *callback_args , **callback_kwargs )

  9. File "/private/tmp/cash/cash/views.py", line 8 , in error

  10. 1/0

  11. ZeroDivisionError : division by zero

  12. [17/ Jul/ 2018 03:50:55] "HTTP/1.1" 500 60675

Copy the code

Integrated Sentry

  • Install the raven


     
  1. $ pip install raven --upgrade

Copy the code
  • Add raven.contrib.django.raven_compat to INSTALLED_APPS


     
  1. INSTALLED_APPS = (

  2. .

  3.    'raven.contrib.django.raven_compat',

  4. )

Copy the code
  • Add the Sentry configuration in Setting


     
  1. import os

  2. import raven

  3. RAVEN_CONFIG = {

  4. 'dsn': 'http://9ad8168873a94fb1927e14111b9bca1e:[email protected]:9000/3' # DSN enter DSN we just recorded

  5. }

Copy the code
  • After that, I’ll let’s test it out

Wrong API access


     
  1. $curl -i http://127.0.0.1:9999/error

Copy the code
  • Exception list

  • Exception details

Configuring Email Notification

I use netease email here, and the specific operations are as follows

  • Modify the config.yml file to add the Mail Server configuration


     
  1. $ vim config.yml

  2. mail.backend: 'django_smtp_ssl.SSLEmailBackend'  # Use dummy if you want to disable email entirely

  3. mail.host: 'smtp.163.com'

  4. mail.port: 465

  5. mail.username: '[email protected]'

  6. Mail. password: '14RJg5vzGFWUNKiP'

  7. mail.use-tls: false

  8. # The email address to send on behalf of

  9. mail.from: '[email protected]'

Copy the code
  • Rebuild the image


     
  1. $ docker-compose build

  2. $ docker-compose up -d

Copy the code

After the restart, the configuration of the mailbox can be found under Admin== mail

Then click below to send a test email to [email protected], and then go to your email to see if you received the email

I can receive the test email sent successfully. Usually, I can receive the abnormal notification after the email configuration is completed.

  • Verify the user’s mailbox

Find the Settings = Account = Emails

Then click Resendverification and you receive a verification email

Click Confirm to Confirm email.

  • Exception notification test

And then, we’re accessing the wrong API


     
  1. $curl -i http://127.0.0.1:9999/error

  2. HTTP/1.1 500 Internal Server Error

Copy the code
  • Check your mailbox for alarm emails

Basically, you’ll get an error email similar to the one above. Somehow that avatar doesn’t show up. Anyway, if you want to see the error details, click on ViewonSentry to open the exception details.

Configure pin notification

As we all know, the timeliness of mailbox notification is too poor to be delivered without delay, so we focus on the group notification of Dingdingrobot.

  • Create a pin group to add a custom robot and obtain an access_token

I’m here for the access_token dadfa77dfc3fe3b34e91237665afbef165e745dd93ec191c48bf4843b1ad63c 4

  • configuration

Find all integrations for the Cash project

Then locate the DingDing Plugin, enable the Plugin, and click Configure Plugin to Configure the Plugin

Enter the access_token you just obtained and click Save Changes to Save your Changes

  • Test Exception Notification

Then we access the API for the following exception


     
  1. $curl -i http://127.0.0.1:9999/error

  2. HTTP/1.1 500 Internal Server Error

  3. .

Copy the code

Your stitching robot should now send the following error

Click the href above to jump to the error details page, and this article ends.

Понравилась статья? Поделить с друзьями:
  • Sentinel rms development kit error 93 the given license code is already added
  • Sentinel hasp run time installation error
  • Sentinel hasp key not found h0007 ошибка
  • Sentinel error when starting the aksfridge
  • Sentence error rate