-
Notifications
You must be signed in to change notification settings - Fork 612
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
set error.type
to asgi-instrumentation attributes when having exceptions
#2719
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -549,23 +549,18 @@ def __init__( | |
sem_conv_opt_in_mode = _OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode( | ||
_OpenTelemetryStabilitySignalType.HTTP, | ||
) | ||
schema_url = _get_schema_url(sem_conv_opt_in_mode) | ||
self.app = guarantee_single_callable(app) | ||
self.tracer = ( | ||
trace.get_tracer( | ||
__name__, | ||
__version__, | ||
tracer_provider, | ||
schema_url=_get_schema_url(sem_conv_opt_in_mode), | ||
__name__, __version__, tracer_provider, schema_url=schema_url | ||
) | ||
if tracer is None | ||
else tracer | ||
) | ||
self.meter = ( | ||
get_meter( | ||
__name__, | ||
__version__, | ||
meter_provider, | ||
schema_url=_get_schema_url(sem_conv_opt_in_mode), | ||
__name__, __version__, meter_provider, schema_url=schema_url | ||
) | ||
if meter is None | ||
else meter | ||
|
@@ -693,6 +688,7 @@ async def __call__( | |
|
||
if scope["type"] == "http": | ||
self.active_requests_counter.add(1, active_requests_count_attrs) | ||
exception = None | ||
try: | ||
with trace.use_span(span, end_on_exit=False) as current_span: | ||
if current_span.is_recording(): | ||
|
@@ -729,7 +725,20 @@ async def __call__( | |
) | ||
|
||
await self.app(scope, otel_receive, otel_send) | ||
except Exception as exc: # pylint: disable=broad-except | ||
exception = exc | ||
finally: | ||
if exception is not None and _report_new( | ||
self._sem_conv_opt_in_mode | ||
): | ||
_set_status( | ||
span=span, | ||
metrics_attributes=attributes, | ||
status_code=-1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't say I like it either. We are actually doing that in several places where we try to int the status_code, and if it fails, we set status_code as -1. Let me see what can I do here to improve the way we are handling this. |
||
status_code_str=type(exception).__qualname__, | ||
server_span=True, | ||
sem_conv_opt_in_mode=self._sem_conv_opt_in_mode, | ||
) | ||
if scope["type"] == "http": | ||
target = _collect_target_attribute(scope) | ||
if target: | ||
|
@@ -791,6 +800,9 @@ async def __call__( | |
if span.is_recording(): | ||
span.end() | ||
|
||
if exception is not None: | ||
raise exception.with_traceback(exception.__traceback__) | ||
|
||
# pylint: enable=too-many-branches | ||
|
||
def _get_otel_receive(self, server_span_name, scope, receive): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a style thing, but I'm wondering if it would be worthwhile to break this method into functions for readability. Perhaps those functions could stand to be further modularized, but this would be a step in that direction. Something like
Not a blocking comment, just a suggestion while we're in here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another suggestion would also to wait and implement this for the various instrumentations that still require this (like flask, wsgi (for metrics), django, etc) and see if there are any commonalities we can refactor out. Difficult to say what we can abstract/modularize without seeing more implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Indeed, while reviewing the transition PRs I identified several instrumentations we are not handling exceptions and setting the exception in
error.type
, even for the ones that are already migrated to the new semconv. I will mark this as draft for now while I think in a better way to handle this. Maybe we'll have a better idea on the commonalities after more transitions.