python-django icon indicating copy to clipboard operation
python-django copied to clipboard

Usage with Tracer client: 'Settings' object has no attribute 'OPENTRACING_TRACING'

Open bj00rn opened this issue 6 years ago • 4 comments

Scratching my head over how to use this library with a Tracer client (jaeger) inside my views

Do i need to explicitly set OPENTRACING_TRACING in settings.py?

Getting the following error on startup

AttributeError: 'Settings' object has no attribute 'OPENTRACING_TRACING'

settings.py

# default tracer is opentracing.Tracer(), which does nothing
OPENTRACING_TRACER_CALLABLE = __name__ + '.tracer'

def tracer():
    from jaeger_client import Config
    config = Config(
        config={
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'local_agent': {
                'reporting_host': os.environ.get('JAEGER_HOST', "localhost"),
                'reporting_port': os.environ.get('JAEGER_PORT', 6831),
            },
            'logging': True,
        },
        service_name='-'.join([os.environ.get('JAEGER_SERVICE_NAME', ''), 'api']))

    return config.initialize_tracer()


# default is False
OPENTRACING_TRACE_ALL = True

# default is []
OPENTRACING_TRACED_ATTRIBUTES = ['META']



views.py

from django.conf import settings

tracing = settings.OPENTRACING_TRACING

@tracing.trace(optional_args)
def some_view_func(request):
    ... # do some stuff

bj00rn avatar Jun 25 '19 07:06 bj00rn

Hi i was wondering the same thing, is there any working example with a client ?

liorco3000 avatar Jun 26 '19 14:06 liorco3000

Hi i was wondering the same thing, is there any working example with a client ?

here is another example project i started off from.

still not sure about the OPENTRACING_TRACING part though

bj00rn avatar Jun 26 '19 20:06 bj00rn

You can print OPENTRACING_TRACER_CALLABLE value, then import the value later in your views.

e.g.

> from settings import OPENTRACING_TRACER_CALLABLE
> print OPENTRACING_TRACER_CALLABLE
opentracing.tracer

then

import opentracing.tracer
opentracing.tracer.active_span.set_tag('tag', '10')

romainr avatar Jul 30 '19 23:07 romainr

@romainr im trying to use the @trace decorator not the tracer itself.

according to docs this would be sufficient in the views file:

from django.conf import settings

tracing = settings.OPENTRACING_TRACING

@tracing.trace(optional_args)
def some_view_func(request):
    ... # do some stuff

however this gives the error

AttributeError: 'Settings' object has no attribute 'OPENTRACING_TRACING'

bj00rn avatar Aug 29 '19 07:08 bj00rn