aws / aws-xray-sdk-python

AWS X-Ray SDK for the Python programming language
Apache License 2.0
329 stars 143 forks source link

TypeError: __init__() takes exactly 2 arguments (1 given) #25

Closed michaelhelmick closed 6 years ago

michaelhelmick commented 6 years ago
Django==1.11.8
aws-xray-sdk==0.95
Traceback (most recent call last):
  File "/Users/mikehelmick/.virtualenvs/test-x-ray/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/Users/mikehelmick/.virtualenvs/test-x-ray/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 147, in inner_run
    handler = self.get_handler(*args, **options)
  File "/Users/mikehelmick/.virtualenvs/test-x-ray/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 28, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/Users/mikehelmick/.virtualenvs/test-x-ray/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 68, in get_handler
    return get_internal_wsgi_application()
  File "/Users/mikehelmick/.virtualenvs/test-x-ray/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 44, in get_internal_wsgi_application
    return get_wsgi_application()
  File "/Users/mikehelmick/.virtualenvs/test-x-ray/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/Users/mikehelmick/.virtualenvs/test-x-ray/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 151, in __init__
    self.load_middleware()
  File "/Users/mikehelmick/.virtualenvs/test-x-ray/lib/python2.7/site-packages/django/core/handlers/base.py", line 58, in load_middleware
    mw_instance = mw_class()
TypeError: __init__() takes exactly 2 arguments (1 given)

I tried setting up my env based off of documentation I pieced together from:

settings.py

XRAY_RECORDER = {
    'AUTO_INSTRUMENT': True,  # If turned on built-in database queries and template rendering will be recorded as subsegments
    'AWS_XRAY_CONTEXT_MISSING': 'LOG_ERROR',
    'AWS_XRAY_TRACING_NAME': 'Site',
    'DYNAMIC_NAMING': '*.local.site.net', # defines a pattern that host names should match
}

I added the MIDDLEWARE and the INSTALLED_APP.

Prior to this error I was getting something similar to #4

aws_xray_sdk.core.exceptions.exceptions.SegmentNotFoundException: cannot find the current segment/subsegment, please make sure you have a segment open

I had to set the AWS_XRAY_CONTEXT_MISSING setting to LOG_ERROR to avoid it and then got this error. Any help is appreciated.

haotianw465 commented 6 years ago

Hi, I was unable to reproduce the issue you reported. What is the X-Ray SDK version you are using? Do you mind sharing your settings.py file with parts that has X-Ray related configs? Do you use python manage.py runserver to start your application or some other commands?

michaelhelmick commented 6 years ago

Please see my edited comment. I accidentally submitted the issues before pasting helpful information.

Sent from my iPhone

On Feb 23, 2018, at 4:17 PM, Haotian Wu notifications@github.com wrote:

Hi, I was unable to reproduce the issue you reported. What is the X-Ray SDK version you are using? Do you mind sharing your settings.py file with parts that has X-Ray related configs? Do you use python manage.py runserver to start your application or some other commands?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

michaelhelmick commented 6 years ago

And yes, locally I use runserver

Sent from my iPhone

On Feb 23, 2018, at 4:17 PM, Haotian Wu notifications@github.com wrote:

Hi, I was unable to reproduce the issue you reported. What is the X-Ray SDK version you are using? Do you mind sharing your settings.py file with parts that has X-Ray related configs? Do you use python manage.py runserver to start your application or some other commands?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

haotianw465 commented 6 years ago

Are you using pre-1.10 style middeware config? https://github.com/django/django/blob/stable/1.11.x/django/core/handlers/base.py#L55 The error you are seeing comes from loading key MIDDLEWARE_CLASSES from settings file.

The X-Ray SDK currently only supports 1.10 style middleware with key MIDDLEWARE as you can see on the README.

michaelhelmick commented 6 years ago

Ah, I am. Thank you. Ill reopen if that doesn’t work!

Sent from my iPhone

On Feb 23, 2018, at 4:38 PM, Haotian Wu notifications@github.com wrote:

Are you using pre-1.10 style middeware config? https://github.com/django/django/blob/stable/1.11.x/django/core/handlers/base.py#L55 The error you are seeing comes from loading key MIDDLEWARE_CLASSES from settings file.

The X-Ray SDK currently only supports 1.10 style middleware with key MIDDLEWARE as you can see on the README.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

haotianw465 commented 6 years ago

Feel free to open new issues with any additional problem you hit. Thanks.

michaelhelmick commented 6 years ago

Changing to MIDDLEWARE got rid of the error in this issue but is throwing an issue similar to #4 still.

Traceback (most recent call last):
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 30, in check_all_models
    errors.extend(model.check(**kwargs))
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/models/base.py", line 1284, in check
    errors.extend(cls._check_fields(**kwargs))
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/models/base.py", line 1359, in _check_fields
    errors.extend(field.check(**kwargs))
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 913, in check
    errors = super(AutoField, self).check(**kwargs)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 219, in check
    errors.extend(self._check_backend_specific_checks(**kwargs))
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 322, in _check_backend_specific_checks
    return connections[db].validation.check_field(self, **kwargs)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 49, in check_field
    field_type = field.db_type(self.connection)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 644, in db_type
    return connection.data_types[self.get_internal_type()] % data
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 174, in data_types
    if self.features.supports_microsecond_precision:
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/backends/mysql/features.py", line 53, in supports_microsecond_precision
    return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 386, in mysql_version
    cursor.execute('SELECT VERSION()')
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/aws_xray_sdk/core/recorder.py", line 307, in wrapper
    meta_processor=None,
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/aws_xray_sdk/core/recorder.py", line 315, in record_subsegment
    subsegment = self.begin_subsegment(name, namespace)
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/aws_xray_sdk/core/recorder.py", line 190, in begin_subsegment
    segment = self.current_segment()
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/aws_xray_sdk/core/recorder.py", line 174, in current_segment
    entity = self.get_trace_entity()
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/aws_xray_sdk/core/recorder.py", line 237, in get_trace_entity
    return self.context.get_trace_entity()
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/aws_xray_sdk/core/context.py", line 93, in get_trace_entity
    return self.handle_context_missing()
  File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/aws_xray_sdk/core/context.py", line 118, in handle_context_missing
    raise SegmentNotFoundException(MISSING_SEGMENT_MSG)
aws_xray_sdk.core.exceptions.exceptions.SegmentNotFoundException: cannot find the current segment/subsegment, please make sure you have a segment open
haotianw465 commented 6 years ago

Based on this line of your stack trace

File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 386, in mysql_version
    cursor.execute('SELECT VERSION()')

I believe https://docs.aws.amazon.com/xray-sdk-for-python/latest/reference/frameworks.html#django section "Local Development" can answer your question.

4 is about S3 resource level API provided by boto3.

michaelhelmick commented 6 years ago

Ah. I think everything was solved once I actually ran the daemon locally. Prior, no events were sent.

Sent from my iPhone

On Feb 23, 2018, at 6:09 PM, Haotian Wu notifications@github.com wrote:

Based on this line of your stack trace

File "/Users/mikehelmick/.virtualenvs/test-xray/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 386, in mysql_version cursor.execute('SELECT VERSION()') I believe https://docs.aws.amazon.com/xray-sdk-for-python/latest/reference/frameworks.html#django section "Local Development" can answer your question.

4 is about S3 resource level API provided by boto3.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

haotianw465 commented 6 years ago

Sounds great. I'm glad everything works out for you. Feel free to provide any general feedback at our forum: https://forums.aws.amazon.com/forum.jspa?forumID=241&start=0 or open new issues for Python SDK specifically.

patrickohemeng commented 6 years ago

I've implemented what has been discussed on this thread. Now getting this error when i runserver

TypeError: object() takes no parameters

michaelhelmick commented 6 years ago

Chances are one of your other Middlware has t been updated using the Django compat middleware. I can post a code example of how to fix it manually in a couple hours when I’m home. I suggest trying to upgrade any third party libraries that implement middleware first though. Easiest way is probably commenting out all third party middleware and enabling one by one and find the culprit

Sent from my iPhone

On Mar 18, 2018, at 9:43 AM, farcorn notifications@github.com wrote:

I've implemented what has been discussed on this thread. Now getting this error when i runserver

TypeError: object() takes no parameters

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

patrickohemeng commented 6 years ago

Apparently one of my middleware libraries was not up to date. runserver is ok now. However, i'm getting

SegmentNameMissingException.

my xray configuration is

XRAY_RECORDER = { 'AUTO_INSTRUMENT': True, 'AWS_XRAY_CONTEXT_MISSING': 'LOG_ERROR', 'AWS_XRAY_DAEMON_ADDRESS': '127.0.0.1:2000', 'AWS_XRAY_TRACING_NAME': 'example config', 'DYNAMIC_NAMING': '*.example.com', 'PLUGINS': ('ElasticBeanstalkPlugin', 'EC2Plugin', 'ECSPlugin'), 'SAMPLING': False, }

Any help on this would be appreciated. Thanks

patrickohemeng commented 6 years ago

I set the AWS_XRAY_TRACING_NAME as an environmental variable and everything works now.