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

NoneType object has no attribute put http meta #152

Open
Ismael opened this issue Apr 2, 2019 · 11 comments
Open

NoneType object has no attribute put http meta #152

Ismael opened this issue Apr 2, 2019 · 11 comments
Labels

Comments

@Ismael
Copy link

Ismael commented Apr 2, 2019

Using sdk version 2.4.2

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 227, in process_exception_by_middleware
    response = middleware_method(request, exception)
  File "/usr/local/lib/python2.7/dist-packages/aws_xray_sdk/ext/django/middleware.py", line 102, in process_exception
    segment.put_http_meta(http.STATUS, 500)
AttributeError: 'NoneType' object has no attribute 'put_http_meta'
@chanchiem
Copy link
Contributor

Hey,

Can you give a code snippet of what's triggering this? Is this ran on Lambda? I need a little bit more information so that I can try reproducing this and isolating the cause. By any chance, is this ran using the Serverless model? Thanks in advance.

@Ismael
Copy link
Author

Ismael commented Apr 2, 2019

I'm doing this in urls.py, to patch all libraries

from aws_xray_sdk.core import xray_recorder, patch_all
xray_recorder.begin_segment('startup')
patch_all()
xray_recorder.end_segment()

This is my config

XRAY_RECORDER = {
    'AUTO_INSTRUMENT': True,
    'AWS_XRAY_CONTEXT_MISSING': 'LOG_ERROR',
    'AWS_XRAY_TRACING_NAME': 'nTitleMe',
    'PLUGINS': ('ECSPlugin',),
}

This is run locally.

I can reproduce this with even a simple view that only raises an exception

def aview(request):
  raise Exception()

I have lots of custom middlewares, but XRay's is first.

@chanchiem
Copy link
Contributor

Everything looks good with your configuration. What version of Django are you using?

We currently support only the following versions:
django >= 1.10, <2.0

@Ismael
Copy link
Author

Ismael commented Apr 3, 2019 via email

@chanchiem
Copy link
Contributor

Is it possible for you to temporarily disable the other middlewares and see if this issue still persists? I'm thinking that maybe there's a middleware that's causing this issue. If the issue does goes away, can you also isolate which middleware is causing this exception? I still can't seem to reproduce this issue you're having on my local system, which is leading me to think that maybeone of the middlewares is causing issues with X-Ray.

I also notice that you're using an ECS plugin. Is this plugin being used with X-Ray when you develop in your local development as well? Just as a sanity check, does removing the plugin from the configuration help?

@aarcro
Copy link

aarcro commented Jul 18, 2019

I'm getting this on Runsever as well, Django 2.2.3

@aarcro
Copy link

aarcro commented Jul 18, 2019

I rolled Django Rest Framework back to 3.9.4 And this went away. 3.10 was not working

@levesquejf
Copy link
Contributor

I just had the same issue with flask 1.1.1 and aws-xray-sdk 2.4.2 running on AWS Lambda (Python 3.7) and deployed with Zappa. Everything (pynamodb, botocore, requests) is patched with patch_all(). I have not been able to reproduce.

File "/var/task/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/var/task/flask/app.py", line 1952, in full_dispatch_request
    return self.finalize_request(rv)
  File "/var/task/flask/app.py", line 1969, in finalize_request
    response = self.process_response(response)
  File "/var/task/flask/app.py", line 2266, in process_response
    response = handler(response)
  File "/var/task/aws_xray_sdk/ext/flask/middleware.py", line 74, in _after_request
    segment.put_http_meta(http.STATUS, response.status_code)
AttributeError: 'NoneType' object has no attribute 'put_http_meta'

@awssandra awssandra added the bug label Jan 10, 2020
@OJFord
Copy link

OJFord commented Aug 6, 2024

quart==0.18.4, flask==2.2.5, aws-xray-sdk==2.14.0

Traceback (most recent call last):
  File "/var/task/quart/app.py", line 1735, in finalize_request
    response = await self.process_response(response, request_context)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/task/quart/app.py", line 1762, in process_response
    response = await self.ensure_async(function)(response)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/task/quart/utils.py", line 61, in _wrapper
    result = await loop.run_in_executor(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/lang/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/task/aws_xray_sdk/ext/flask/middleware.py", line 74, in _after_request
    segment.put_http_meta(http.STATUS, response.status_code)
    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'put_http_meta'

Even if unable to reproduce, perhaps we could just fail gracefully if no segment? i.e. best effort to set annotations but not error?

@jcampbell05
Copy link

This appears to happen after "Subsegment api discarded due to Lambda worker still initializing" they could be related ?

@jcampbell05
Copy link

It looks like for whatever reason the flask/django integrations fail to start a segement which causes the problem, especially when lambda is still setting up.

I had to add this code xray_recorder.begin_segment("DefaultSegment", traceid=None) and it no longer crashes, however I do not think this is the correct approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants