Skip to content

Commit

Permalink
add option to disable asgi intern trace
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelauv authored and raphael-ankorstore committed Nov 22, 2021
1 parent f0ac738 commit 353208e
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ def __init__(
client_request_hook: _ClientRequestHookT = None,
client_response_hook: _ClientResponseHookT = None,
tracer_provider=None,
exclude_span_receive=False,
exclude_span_send=False,
):
self.app = guarantee_single_callable(app)
self.tracer = trace.get_tracer(__name__, __version__, tracer_provider)
Expand All @@ -279,6 +281,9 @@ def __init__(
self.client_request_hook = client_request_hook
self.client_response_hook = client_response_hook

self.exclude_span_receive = exclude_span_receive
self.exclude_span_send = exclude_span_send

async def __call__(self, scope, receive, send):
"""The ASGI application
Expand Down Expand Up @@ -343,6 +348,14 @@ async def wrapped_send(message):
send_span.set_attribute("type", message["type"])
await send(message)

await self.app(scope, wrapped_receive, wrapped_send)
fn_receive = wrapped_receive
fn_send = wrapped_send

if self.exclude_span_send:
fn_receive = receive
if self.exclude_span_send:
fn_send = send

await self.app(scope, fn_receive, fn_send)
finally:
context.detach(token)

0 comments on commit 353208e

Please sign in to comment.