Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Jul 11, 2024
1 parent a1a7250 commit 02ba4f9
Showing 1 changed file with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,28 +431,13 @@ def get_host_port_url_tuple(scope):
return server_host, port, http_url


def maybe_inject_context(message, server_span, setter):
"""Inject the context if there's a global propagator."""
propagator = get_global_response_propagator()
if propagator:
propagator.inject(
message,
context=set_span_in_context(
server_span, trace.context_api.Context()
),
setter=setter,
)


def set_status_code(
span,
status_code,
metric_attributes=None,
sem_conv_opt_in_mode=_HTTPStabilityMode.DEFAULT,
):
"""Adds HTTP response attributes to span using the status_code argument."""
if not span.is_recording():
return
status_code_str = str(status_code)

try:
Expand Down Expand Up @@ -893,12 +878,16 @@ async def otel_send(message: dict[str, Any]):
None,
self._sem_conv_opt_in_mode,
)

maybe_inject_context(
message,
server_span=server_span,
setter=asgi_setter,
)

propagator = get_global_response_propagator()
if propagator:
propagator.inject(
message,
context=set_span_in_context(
server_span, trace.context_api.Context()
),
setter=setter,
)

content_length = asgi_getter.get(message, "content-length")
if content_length:
Expand Down

0 comments on commit 02ba4f9

Please sign in to comment.