open-telemetry / opentelemetry.io

The OpenTelemetry website and documentation
https://opentelemetry.io
Creative Commons Attribution 4.0 International
508 stars 1.08k forks source link

Does setting span status to Error automatically create span event? #4823

Closed cheempz closed 1 month ago

cheempz commented 1 month ago

Original slack post, links changed to relative repo paths:

Just read the excellent article about errors and there's something puzzling me, really appreciate if someone can help clarify. the blog mentioned here and restated similar behaviour here:

When a span status is set to Error, a span event is created automatically, capturing the span’s resulting error message and stack trace as an event on that span.

is this something specified in the tracing API or SDK specs, or implicitly for autoinstrumentation libraries to do if it collects a span and sets Error status on it? from quick scan of specs and Python SDK implementation i'm not seeing anything. thanks!

What needs to be changed? Per @svrnm please verify if there is something in the blog post that needs to be fixed or if a reference to the spec is missing.

svrnm commented 1 month ago

Thanks for raising this @cheempz!

@reese-lee @avillela can you verify if this is somewhere defined in the spec and just not available in Python, or if this is not in the spec?

If it is in the spec, we can raise an issue with python or check if one exists already and close this issue If it is not in the spec, let's remove that sentence from the blog post. Although we try to avoid changing blog posts after publication, I think it would be justified in this case to avoid future confusion.

svrnm commented 1 month ago

@open-telemetry/python-approvers if someone can take a look and help with answering this question, this would be great/can help to expedite the investigation

xrmx commented 1 month ago

I don't think we have that kind of magic in Python other than sdk's Span constructor will add to the span every event it get passed to it. Span.record_exception will add the exception as event automatically, maybe they meant that?

cartermp commented 1 month ago

It's a convention in instrumentations to create a span event with a stack trace (or other error details), so that may be what was referred to? There's nothing inherent in OTel SDKs that create a span event automatically, though.

avillela commented 1 month ago

Apologies - I think the wording we used might have been a bit confusing.

From my understanding in Python, if you have:

with tracer.start_as_current_span("do_roll", set_status_on_exception=True)

and your span throws an exception, then that span will be marked as an error span.

I believe that tracks with the above comments? If so, I'm happy to modify that sentence in the blog post to clarify the confusion.

cheempz commented 1 month ago

Thanks everyone. From the response so far it seems safe to say that various SDKs and instrumentations may automatically collect span exception events when setting the span status to ERROR, but we (specifically our vendor platform) should not make this assumption, correct?

svrnm commented 1 month ago

@avillela can you take a look at your blog post and figure out if the sentence can be rephrased to match what is discussed here. As a quick fix, I am also OK with removing the sentence entirely.

Thanks everyone. From the response so far it seems safe to say that various SDKs and instrumentations may automatically collect span exception events when setting the span status to ERROR, but we (specifically our vendor platform) should not make this assumption, correct?

That's my understanding as well, yes.

tiffany76 commented 1 month ago

Closing as completed by #4844.