Skip to content

Commit

Permalink
refactor(cassandra_inst): Use start_active_span as scope manager
Browse files Browse the repository at this point in the history
Signed-off-by: Ferenc Géczi <[email protected]>
  • Loading branch information
Ferenc- committed Dec 27, 2023
1 parent df7c9e8 commit 6293143
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions instana/instrumentation/cassandra_inst.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def request_init_with_instana(fn):
if active_tracer is None:
return

parent_span = active_tracer.active_span
ctags = dict()
ctags = {}
if isinstance(fn.query, cassandra.query.SimpleStatement):
ctags["cassandra.query"] = fn.query.query_string
elif isinstance(fn.query, cassandra.query.BoundStatement):
Expand All @@ -67,13 +66,10 @@ def request_init_with_instana(fn):
ctags["cassandra.keyspace"] = fn.session.keyspace
ctags["cassandra.cluster"] = fn.session.cluster.metadata.cluster_name

span = active_tracer.start_span(
operation_name="cassandra",
child_of=parent_span,
tags=ctags)

fn.add_callback(cb_request_finish, span, fn)
fn.add_errback(cb_request_error, span, fn)
with active_tracer.start_active_span("cassandra", child_of=active_tracer.active_span,
tags=ctags, finish_on_close=False) as scope:
fn.add_callback(cb_request_finish, scope.span, fn)
fn.add_errback(cb_request_error, scope.span, fn)


@wrapt.patch_function_wrapper('cassandra.cluster', 'Session.__init__')
Expand Down

0 comments on commit 6293143

Please sign in to comment.