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

Summary

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 (closed)):

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 by Abdulla Gaibullaev