Repository navigation
feat: add context api - #44
legendecas wants to merge 3 commits into
Conversation
d5d321c to
789bde2
Compare
789bde2 to
d910408
Compare
| `microtel.context` holds a closed set of values, each with its own accessor. | ||
| There is no string-keyed access. Libraries that need other values keep them |
There was a problem hiding this comment.
I'm not quite following this. Is this saying the context object is not mutable?
There was a problem hiding this comment.
Yes, a Context is a snapshot, handed from one piece of code to the next. The OpenTelemetry Context spec also requires a context to be immutable. A receiver can't change which values a Context holds. It can only make a new Context with different ones, and pass the new Context to child receiver.
The objects that a Context refers to can still be mutable. An Operation or a Span in a Context stands for the operation itself, so the receiver can update it like setting the target info or adding attributes to the spans. Maybe the context.setTarget in this API makes this confusing, I can update it.
The intention is that a context receiver must not mutate the context directly, like a receiver must not modify the TraceContext or the Baggage, because those describe this Context's position in the trace and are meant to be scoped to it.
| It can be called once per Node.js environment, such as the main thread or a | ||
| worker. A second call throws `ERR_INVALID_STATE`. |
There was a problem hiding this comment.
Then I think setAdapter is more appropriate. register implies that it can be done more than once.
There was a problem hiding this comment.
setAdapter also sounds good to me. Open to API name suggestions.
This provides a reversed dependency graph in #29: microtel provides a context api that allows
OpenTelemetry to share the Trace Context and other propagated metadata like route info.
This PR demonstrates how microtel can coordinate with OpenTelemetry through a minimal API.
The API allows both microtel and OpenTelemetry to use a shared AsyncLocalStorage but with a
documented value and access contract.
This PR also allows web frameworks to provide their RPC metadata like routes
through a microtel API, without microtel instrumenting every web framework
individually.
Baggage, and suppress tracing (like do not create traces for trace exportations) are left as a TODO.
Refs: #25