Skip to content
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

OTel Span is not set to status "ok" when ends successfully #890

Closed
GFriedrich opened this issue Nov 14, 2024 · 6 comments · Fixed by #896
Closed

OTel Span is not set to status "ok" when ends successfully #890

GFriedrich opened this issue Nov 14, 2024 · 6 comments · Fixed by #896
Labels
bug A general bug
Milestone

Comments

@GFriedrich
Copy link
Contributor

Hi,
I'm not sure if I'm missing something in my implementation, but I would expect that if an OTel span is ended and is yet "unset", it would be set to "ok".
Right now I can see it is always "unset" at the end which is somewhat odd.
But please let me know in case I've missed anything.
Thanks for looking at it in advance.

@jonatan-ivanov jonatan-ivanov added bug A general bug and removed waiting-for-triage labels Nov 21, 2024
@jonatan-ivanov jonatan-ivanov added this to the 1.3.7 milestone Nov 21, 2024
@jonatan-ivanov
Copy link
Member

Thanks for the issue!
Are you interested in creating a PR to fix this?
OtelSpan has two end methods and the error method is already setting the status so setting in end should be straightforward.

@GFriedrich
Copy link
Contributor Author

@jonatan-ivanov first of all: Thanks for checking.
Sure, I can create a PR with a fix, but it may take until the weekend.

@jonatan-ivanov
Copy link
Member

jonatan-ivanov commented Nov 22, 2024

That's totally fine, our next release is in two weeks. I asked since this seems a good issue if one wants to contribute. If you don't or you won't find the time, that's of course 120% fine, just let me know and I'll fix it.

GFriedrich added a commit to GFriedrich/micrometer-tracing that referenced this issue Nov 24, 2024
This will fix setting the OTel span status when:
* the span ends and is not yet set
* the error state for a span is set

Fixes micrometer-metrics#890
@GFriedrich
Copy link
Contributor Author

GFriedrich commented Nov 24, 2024

hey @jonatan-ivanov,
tried to fix the issue and found a few more issues, but let me start from the beginning:

  • first tried to go with the most simple approach and set the status at the end of the span
    • but found that there is no getter for the status of the span, so you can't know if it was already set to ERROR and it could overwrite the status then to OK
  • then thought about storing the status additionally on the OtelSpan, but this would've caused issues when creating the span by wrapping some existing span, as it suffers from the same issue: not knowing the previous status
  • then thought about setting the span at the beginning, but this breaks setting the error status
    • because once it is set to OK, you can't change it anymore
  • so finally went back to the original solution and now cast the the span to a ReadableSpan, which then generates the span data to get the status
    • not the most beautiful solution, but the best I came up with

Additionally I found the following other problems:

  • on some error scenarios the error status was not set
    • fixed it in my PR because it made sense to me to create a PR which fixes the overall status of an OTel span
  • some of the builder methods are returning a copy of the OtelSpan for no good reason
    • I could see that historically others were using the same solution before they were changed to return this
    • around the same time frame though some additional methods got added which copied this behaviour before it got fixed
    • so I think they all should be changed to return this
    • let me know if I should do this and then I would create some issue and a PR

GFriedrich added a commit to GFriedrich/micrometer-tracing that referenced this issue Nov 24, 2024
This will fix setting the OTel span status when:
* the span ends and is not yet set
* the error state for a span is set

Fixes micrometer-metrics#890
jonatan-ivanov pushed a commit to GFriedrich/micrometer-tracing that referenced this issue Dec 6, 2024
This will fix setting the OTel span status when:
* the span ends and status is not yet set
* the error state for a span is set

Closes micrometer-metricsgh-890
jonatan-ivanov pushed a commit to GFriedrich/micrometer-tracing that referenced this issue Dec 6, 2024
This will fix setting the OTel span status when:
* the span ends and status is not yet set
* the error state for a span is set

Closes micrometer-metricsgh-890
jonatan-ivanov pushed a commit to GFriedrich/micrometer-tracing that referenced this issue Dec 6, 2024
This will fix setting the OTel span status when:
* the span ends and status is not yet set
* the error state for a span is set

Closes micrometer-metricsgh-890
@jonatan-ivanov
Copy link
Member

some of the builder methods are returning a copy of the OtelSpan for no good reason

Let's do this in a separate PR.

@GFriedrich
Copy link
Contributor Author

some of the builder methods are returning a copy of the OtelSpan for no good reason

Let's do this in a separate PR.

Have created a separate issue (#900) and PR (#901) for it.
Thanks @jonatan-ivanov 🤝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants