uber-common / opentracing-python-instrumentation

A collection of Python instrumentation tools for the OpenTracing API
MIT License
164 stars 58 forks source link

Should span_in_stack_context be throwing exceptions? #111

Open yurishkuro opened 4 years ago

yurishkuro commented 4 years ago

@Jamim I'm interested in your thoughts. One of our users complained about getting this error:

# .../python2/local/lib/python2.7/site-packages/opentracing_instrumentation/client_hooks/boto3.pyc in perform_call(self, original_func, kind, service_name, operation_name, *args, **kwargs)
    135         span.set_tag('boto3.service_name', service_name)
    136 
--> 137         with span, span_in_stack_context(span):
    138             try:
    139                 response = original_func(*args, **kwargs)

# .../python2/local/lib/python2.7/site-packages/opentracing_instrumentation/request_context.pyc in span_in_stack_context(span)
    210 
    211     if not isinstance(opentracing.tracer.scope_manager, TornadoScopeManager):
--> 212         raise RuntimeError('scope_manager is not TornadoScopeManager')
    213 
    214     # Enter the newly created stack context so we have

They were running Jupyter notebook and trying to upload data using boto client. The notebook runs inside managed workspace for notebooks, which (apparently) enables Jaeger for all sessions automatically, but since they are not Tornado-based apps, it does not enable TornadoScopeManager.

it appears that boto instrumentation is just not usable wit non-tornado code. Would it make more sense for span_in_stack_context to fallback onto span_in_context when not in the tornado environment?