Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,24 @@ async def __call__(self, scope: Any, receive: Any, send: Any) -> None:
"x_request_id", x_request_id, context=ctx,
)

# Create a NonRecordingSpan with the extracted trace context so that
# get_current_span() returns a span carrying the correct trace_id.
# Without this, the OTel LogRecord processor sees no active span and
# sets trace_id=0, causing zeroed operation_Id in Application Insights
# for logs emitted by Hypercorn's access logger.
span = trace.get_current_span(ctx)
span_ctx = span.get_span_context()
if span_ctx and span_ctx.is_valid:
non_recording = trace.NonRecordingSpan(span_ctx)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to create a non-recording span ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should validate consequent request and how traces show up.

Copy link
Copy Markdown
Author

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to create a non-recording span ? --- I think line 288 internally does create non recording span

ctx = trace.set_span_in_context(non_recording, ctx)
Comment thread
harsheet-shah marked this conversation as resolved.
Comment thread
harsheet-shah marked this conversation as resolved.

# Attach request context for app execution and detach in the same
# Task/context to avoid leaking contextvars across requests.
token = _otel_context.attach(ctx)
try:
await self.app(scope, receive, send)
finally:
try:
_otel_context.detach(token)
except ValueError:
pass
detach_context(token)


def end_span(span: Any, exc: Optional[BaseException] = None) -> None:
Expand Down