-
Notifications
You must be signed in to change notification settings - Fork 8
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
Nested lib spans #25
Comments
Hi @while-loop , Yes, it can be done, but with a caveat! def test_trace_flask_sqlalchemy_nested():
recorder = Recorder()
recorder.spans = []
tracer = BasicTracer(recorder=recorder)
tracer.register_required_propagators()
opentracing.tracer = tracer
engine = create_engine('sqlite://')
User.metadata.create_all(engine)
session = sessionmaker(bind=engine)()
app = Flask('test_app')
@app.route('/')
@trace(span_extractor=extract_span_from_flask_request) # We need this to provide a clear parent for any child spans (in our case sqlalchemy operations)
def root():
user = User(name='Tracer', is_active=True)
session.add(user)
session.commit()
return 'OK'
trace_flask(app)
trace_sqlalchemy()
with app.app_context():
print(app.test_client().get('/').data)
assert len(recorder.spans) == 3
sql_span = recorder.spans[0]
assert sql_span.operation_name == 'insert'
assert sql_span.tags['db.statement'] == 'INSERT INTO users (name, is_active) VALUES (?, ?)'
trace_span = recorder.spans[1]
assert trace_span.operation_name == 'root'
flask_span = recorder.spans[2]
assert flask_span.operation_name == 'root'
assert sql_span.parent_id == trace_span.context.span_id
assert trace_span.parent_id == flask_span.context.span_id The reason we need the If you want to show only two spans, then you have 2 options:
@app.route('/')
def root():
# This edge span variable will help the sqlalchemy to find a parent - via callstack inspection
# Although it is not used
flask_edge_span = extract_span_from_flask_request() # noqa
user = User(name='Tracer', is_active=True)
session.add(user)
session.commit()
return 'OK'
trace_sqlalchemy(span_extractor=extract_span_from_flask_request) I believe with I have created couple of issue to enhance the quick start and make these usecases clearer: |
Awesome! Thanks for the insight and examples! |
Does this library support spans across multiple libraries?
Like using flask and sqlalchemy within the same trace?
With 1 flask trace with a child sql span
The text was updated successfully, but these errors were encountered: