opentracing-contrib / python-django

OpenTracing instrumentation for the Django framework
BSD 3-Clause "New" or "Revised" License
105 stars 54 forks source link

Example of setting up tracer without lightstep? #17

Open viperfx opened 6 years ago

viperfx commented 6 years ago

How do I configure a trace and connect it to a local docker container let's say, exposed at localhost.

How would I change settings.py to connect to the default Jaeger docker image?

elnappo commented 6 years ago

I could not confirm this because I'm using python3 only but this could work in settings.py for localhost:

def initialize_tracer():
  config = Config(
      config={
          'sampler': {'type': 'const', 'param': 1}
      },
      service_name='hello-world')
  return config.initialize_tracer()

OPENTRACING_TRACE_ALL = True 
OPENTRACING_TRACED_ATTRIBUTES = ['META']

OPENTRACING_TRACER = django_opentracing.DjangoTracer(initialize_tracer())
SEJeff commented 6 years ago

First, setup the all in one jaeger docker container. Then update your settings to look like this. The key is adding django_opentracing.OpenTracingMiddleware to MIDDLEWARE_CLASSES and the OPENTRACING_* settings.

Confirmed working.

ror6ax commented 6 years ago

I think adding separate example using Jaeger to mirror flask examples would be beneficial.

spybdai commented 5 years ago

I think adding separate example using Jaeger to mirror flask examples would be beneficial.

Yes, think this should be more helpful.

spybdai commented 5 years ago

First, setup the all in one jaeger docker container. Then update your settings to look like this. The key is adding django_opentracing.OpenTracingMiddleware to MIDDLEWARE_CLASSES and the OPENTRACING_* settings.

Confirmed working.

Hi guys, the latest version of django_opentracing requires version of opentracing >= 2.0, while the latest version of jaeger-client-python requires version of opentracing < 2,

How should make them work together?

I know django_opentracing version 0.1.20 works with opentracing version < 2.0, but there are some obvious features which are absent comparing with the latest version.

bj00rn commented 5 years ago

Hi guys, the latest version of django_opentracing requires version of opentracing >= 2.0, while the latest version of jaeger-client-python requires version of opentracing < 2

dependency issue was apparently fixed in 1.1.0 https://github.com/opentracing-contrib/python-django/commit/ef50385946010c7639d225f2d59e76f8376178a0

bj00rn commented 5 years ago

First, setup the all in one jaeger docker container. Then update your settings to look like this. The key is adding django_opentracing.OpenTracingMiddleware to MIDDLEWARE_CLASSES and the OPENTRACING_* settings.

Confirmed working.

How about OPENTRACING_TRACING setting?

I wan't to do

views.py

from django.conf import settings

tracing = settings.OPENTRACING_TRACING

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

from docs:

# some_opentracing_tracer can be any valid OpenTracing tracer implementation
OPENTRACING_TRACING = django_opentracing.DjangoTracing(some_opentracing_tracer)

sorry for partial repost of https://github.com/opentracing-contrib/python-django/issues/56