serverless / dashboard

MIT License
26 stars 10 forks source link

Cannot send event to Sentry with serverless_sdk: send_envelope_wrapper internal error #828

Closed fafrd closed 11 months ago

fafrd commented 1 year ago

I'm running a basic aws lambda using Serverless framework and I can't seem to send any messages to Sentry. This code works just fine locally, but I get an internal error when running on AWS Lambda.

import sentry_sdk
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration

sentry_sdk.init(
    dsn="https://<my-dsn>",
    debug=True,
    integrations=[
        AwsLambdaIntegration(timeout_warning=True),
    ],
    traces_sample_rate=1.0,
)

def handler(event, context):
    from sentry_sdk import capture_message
    capture_message("testing sentry 123")

I see this error in Sentry SDK's debug logs, it's ultimately coming out of sls_sdk/lib/instrumentation/http.py:

2023-06-29 23:32:44,473 - sentry_sdk.errors - DEBUG - Sending envelope [envelope with 1 items (internal)] project:4505444184293376 host:o1112958.ingest.sentry.io
[sentry] ERROR: Internal error in sentry_sdk
Traceback (most recent call last):
File "/var/task/sentry_sdk/transport.py", line 492, in send_envelope_wrapper
self._send_envelope(envelope)
File "/var/task/sentry_sdk/transport.py", line 388, in _send_envelope
self._send_request(
File "/var/task/sentry_sdk/transport.py", line 231, in _send_request
response = self._pool.request(
File "/var/task/urllib3/request.py", line 78, in request
return self.request_encode_body(
File "/var/task/urllib3/request.py", line 170, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "/var/task/urllib3/poolmanager.py", line 376, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/var/task/serverless_sdk/vendor/wrapt/wrappers.py", line 610, in __call__
return self._self_wrapper(self.__wrapped__, self._self_instance,
File "/var/task/serverless_sdk/__init__.py", line 568, in wrapper
raise e
File "/var/task/serverless_sdk/__init__.py", line 563, in wrapper
response = wrapped(*args, **kwargs)
File "/opt/python/sls_sdk/lib/instrumentation/wrapper.py", line 16, in _target_method
return self.target_method(
File "/opt/python/sls_sdk/lib/instrumentation/http.py", line 404, in _patched_call
self._capture_request_body(trace_span, body)
File "/opt/python/sls_sdk/lib/instrumentation/http.py", line 104, in _capture_request_body
length = len(decoded)
TypeError: object of type 'NoneType' has no len()

Related issue in https://github.com/getsentry/sentry-python/issues/2216

medikoo commented 1 year ago

@fafrd Great thanks for reporting. Fix will be coming shortly. In a meantime you can workaround that by adding SLS_DISABLE_HTTP_MONITORING set to 1 in environment variables

medikoo commented 1 year ago

@fafrd this also looks as clear issue on our side, so you can close https://github.com/getsentry/sentry-python/issues/2216

fafrd commented 11 months ago

Looks like it's resolved, I can run lambdas without setting SLS_DISABLE_HTTP_MONITORING=1 anymore. Closing