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

[redis] Unable to initiate tracer #405

Closed
ashok-an opened this issue Apr 5, 2021 · 6 comments · Fixed by #399 or open-telemetry/opentelemetry-python#1726
Closed

[redis] Unable to initiate tracer #405

ashok-an opened this issue Apr 5, 2021 · 6 comments · Fixed by #399 or open-telemetry/opentelemetry-python#1726
Labels
bug Something isn't working

Comments

@ashok-an
Copy link

ashok-an commented Apr 5, 2021

Describe your environment
Unable to initiate tracer

Steps to reproduce

 ## Redis
 from opentelemetry.instrumentation.redis import RedisInstrumentor
 import redis
 RedisInstrumentor().instrument()
 redis_client = redis.StrictRedis(host="localhost", port=6379)

What is the expected behavior?
tracer instance

What is the actual behavior?

Overriding of current TracerProvider is not allowed
Traceback (most recent call last):
  File "/tmp/tracing/example/scrubber_app.py", line 9, in <module>
    tracer = utils.init_tracer('sample_app')
  File "/tmp/utils.py", line 40, in init_tracer
    trace.get_tracer_provider().add_span_processor(
AttributeError: '_DefaultTracerProvider' object has no attribute 'add_span_processor'

Additional context
Reference: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py

@ashok-an ashok-an added the bug Something isn't working label Apr 5, 2021
@dgzlopes
Copy link
Contributor

dgzlopes commented Apr 5, 2021

I have the same problem, but with the Flask instrumentation.

@srikanthccv
Copy link
Member

You need to set the trace pipeline with concrete implementation of tracer provider before adding span processor. Please share more context.

@codeboten
Copy link
Contributor

hey @ashok-an and @dgzlopes, in both cases you will need to configure a TracerProvider in the code before any instrumentation can make calls to the tracer. If you're using auto-instrumentation, this can be set via environment variables, otherwise you would need something like this in the code:

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider

trace.set_tracer_provider(TracerProvider())

@dgzlopes
Copy link
Contributor

dgzlopes commented Apr 6, 2021

Thanks, @lonewolf3739 and @codeboten!

Fixed my code by moving the TraceProvider configuration to the top. On my case:

# This works!
trace.set_tracer_provider(TracerProvider())
jaeger_exporter = JaegerExporter(
...
)
trace.get_tracer_provider().add_span_processor(
    BatchSpanProcessor(jaeger_exporter)
)
# This doesn't work
jaeger_exporter = JaegerExporter(
...
)
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
    BatchSpanProcessor(jaeger_exporter)
)

@owais
Copy link
Contributor

owais commented Apr 7, 2021

@dgzlopes glad you found a way to make it work. What you did to fix it is still the recommended way to setup tracing i.e, registering a global tracer provider before other things. We'll still ship a fix for this in the next release so cases where users cannot control the order in which things are setup will work as expected as well.

@dgzlopes
Copy link
Contributor

dgzlopes commented Apr 8, 2021

Thanks for the response @owais! I'll keep that in mind :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants