-
Notifications
You must be signed in to change notification settings - Fork 251
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
OnEnding should make spans readonly, except within the processor. #1740
Comments
cc @pantuza |
Two ways this can be done: Java does it by storing the ID of the thread that runs OnEnding, and prevents any other thread from doing so. Go is going to setup a wrapper span that allows bypassing the span being read-only, and will be provided to the processor. |
👋 This issue has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the |
Should this be reported elsewhere? |
@dmathieu this is the appropriate place, though I am not sure this is the bug we will run into when our users start to make changes to the span. Span mutation methods leverage a In
That is where I think the real problem is. I assert that when a span processor attempts to mutate the underlying span, it will run into a thread deadlock situation. Has anyone implemented one of these processors in the wild yet? |
Hi folks, I agree that Probably, calling this processor method directly isn't desirable, but we are never fully aware of how users will use the library. Thus, might be necessary to protect this method individually. Does it make sense? @arielvalentin , I did not understand how the |
It's likely not a deadlock situation as much as an error. I am concerned that mutexes are not re-entrant. Assuming that is the case then when a span processor attempts to mutate it, then it will hit an additional synchronize block and that may result in errors. |
You are totally right! If any given I see two alternatives:
|
If I understand correctly, the span should store
|
Not exactly. We want the ability for spans to be mutable in a fiber and thread safe way. Spans may be writable from any thread or fiber as long as access is synchronized. When a span is "finished", then it changes to a state that is Immutable, a.k.a Read Only. The span has an OnEnding stage where it notifies processors that it's about to transition to Read Only state. This is the final opportunity to make changes to the span before enqueing it for export. So it's a case where a fiber would have an exclusive re-entrant lock on the span when it's in its transitioning state. If we capture the fiber that initialized it and "locked" on that then the span could not be mutated at any other time or could not be finished by a different fiber. |
That's a good starting point for a workable solution, though. Similar to Go, you can pass a wrapper to the callback that has "special" access to the Span's internals, but which bypasses the mutex and instead checks that the owning Thread (or Fiber) is the current one. |
The OnEnding spec mentions:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#onending
The current OnEnding implementation doesn't prevent the span from being modified in another thread, concurrently with the processor's action.
The text was updated successfully, but these errors were encountered: