-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
trace.WithAttributes does not satisfy SpanEndOption #5921
Comments
The specification only allows setting the end timestamp, not attributes when calling |
My read of the specification was that one can set the end timestamp when calling Digging in a bit further, I can see that the reason that Also surprising is that passing With the possible exception of the issues around Once there's alignment on a general path forward I'll be happy to take a stab at implementing any changes (likely mostly documentation) and raise a PR for further review. |
I don't know whether we should allow setting attributes while we call Setting the end timestamp is related to finishing the span, since that value is set during that call. It looks to me like the specification needs to be clarified before we make changes to the API. |
span.SetAttributes(/*...*/)
span.End() This is how you set attributes at span end. |
Agreed, and as I stated above I'm fine with that. Mostly I'm trying to make sure the community of developers I support are able to understand and use this API correctly and effectively, hence the desire to make the documentation unambiguous and consistent with the code. If you feel the specification should also be more explicit in this area, I'm happy to help with that too. Meanwhile, making the documentation for the existing API and its behavior more complete and correct seems like an orthogonal issue to improving the specification. If the specification ends up changing such that it requires modifications to the API, that should be taken on separately. BTW, the documentation for the implementation of // The only SpanOption currently supported is WithTimestamp which will set the
// end time for a Span's life-cycle.
//
// If this method is called while panicking an error event is added to the
// Span before ending it and the panic is continued. This of course doesn't get propagated to the published documentation. |
Description
The documentation of
trace.WithAttributes
states:However, it returns a
SpanStartEventOption
instead of aSpanEventOption
andSpanStartEventOption
satisfies onlySpanStartOption
andEventOption
, notSpanEndOption
.Either the code or the documentation is incorrect. I expect that it's the code that's incorrect, because it's often the case that useful span attribute values are not known before a span's operation has started. This can still be done using
Span.SetAttributes
, but the text fortrace.WithAttributes
quoted above implies that the option it produces can be passed toSpan.End
. The wording is also a bit confusing because it refers to what must be calls toTracer.Start
andSpan.End
as "events", using that word in a different sense than the "span events" for which this function can be used to supply attributes.Environment
Steps To Reproduce
(Complete example at https://go.dev/play/p/QpkKDVYmnxp)
Expected behavior
The above code should compile cleanly and behave as already described, or the documentation for
trace.WithAttributes
should not imply that it can be used withSpan.End
. In the former case, it would also be good to include text that follows the instructions in the specification:The text was updated successfully, but these errors were encountered: