-
Notifications
You must be signed in to change notification settings - Fork 890
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
Add Context
parameter to Enabled for metrics instruments
#4256
Comments
Why? |
Description updated. Thanks |
There's no corresponding SDK behavior that would allow the enabled API to change its response based on context. |
A custom API implementation (e.g. SDK wrapper) could change its response based on context. I find that adding is important for Go that require passing Context explicitly. Adding it later to the API would be a burden. CC @open-telemetry/go-maintainers, @open-telemetry/collector-maintainers |
@open-telemetry/technical-committee since there is precedence for this already, we think that we can move forward with this, any objections? (cc @pellared @jpkrohling @danielgblanco) |
Agree with @pellared that adding this is important for Go |
IMO there is no need to modify the specification here. To me, this is a Go-specific question. Golang uses explicit context, and all API calls should have context independent of whether OTel specifications explicitly mention context. There is no need to modify the OTel specification to add a Context parameter in Golang. Most OTel APIs rely on implicit context, like being able to get a thread-local context object. Golang does not have thread-local state, so we always expect a Context argument. It shouldn't require a lot of imagination to see how context is useful for customized SDK purposes. A custom metric SDK could record metric events to the active span when the context is sampled, for example. |
This is why in almost all places |
@pellared I can't find what you're referring to. In the metrics
this implies that Enabled() should accept a context. In the trace Moreover, if you look at the one operation that absolutely requires a context, tracer.Start(), we see it is permitted to be implicit:
This seems to set a precedent that context can be implicit. The definition of Context itself also repeats this:
I still believe it is not necessary to modify the specification in this case. |
@jmacd, I added all these in the description of #4262
Is there any reason that adding the OTel concept of context would be bad in this scenario? Especially given that in most languages it is always implicitly available.
I prefer the specification to be less ambiguous. I would rather change the specification and call out that adding a |
+1 for making our specification explicit in its meaning. |
+1 as well, for explicitness, but also consistency. When tracing mentions the context, we should also mention it for similar appropriate cases with other signals. |
Mentioned here, but will repeat again here: Including I don't think there are actually many operations that benefit from |
I do think However, this must also be balanced by the expense/cost of context. I think it's appropriate that we be super careful in terms of what we promote and push into context. For example, the reason "green threads" and "co-routines" have such a huge performance win over "raw threads" or "native threads" is due to the context passing - they are able to ignore MOST of the stack copying that would occur in raw threads. As OTEL adds back in things which must be passed, we need to understand the overhead of this and its usage. To me this means we should assume the following:
To me this means a pattern of: var myContext = doTheExpensiveConcurrentAccessThingToGetContext();
if (logger.isEnabled(myContext)) {
logger.log(myContext, ...expensive to compute things...)
} Is fine under a few assumptions:
Basically, I don't see Context adding significant burden here, given its design and use in OTEL. However, I also am concerned if we partition out enablement checks in very fine grained fashion that we may locally optimise a benchmark at the cost of overhead increasing across the application. TL;DR; it would be nice to see some prototypes and benchmarks here to address concerns. I'm theoretically supportive, but I really want to understand what is being checked to understand if we're introducing a foot-gun here. |
Notice that In OTel Go, we might need the For example, in future, the user may want the Logs SDK to filter out span events (emitted via Logs SDK) when they are not inside a recording span. This could be implemented in the SDK by adding if logger.Enabled(ctx, params) {
logger.Emit(ctx, createHeavyLogRecord(payload))
} Alternatively, the caller could check if the span is being recorded by himself: if trace.SpanFromContext(ctx).IsRecording() && logger.Enabled(params) {
logger.Emit(ctx, createHeavyLogRecord(payload))
} This alternative might be better because the caller usually knows better whether the log record is related to tracing. However, adding the But maybe we indeed do not want cross-cutting concerns for I find the principle "Do not break users" very important. Adding Most of the reasons above also apply to Can you elaborate on
We don't need synchronization when interacting with context because it is immutable.
I think this relates to the purpose of the
This might be possible for users of the Logs API when emitting events. But |
That's an interesting use case. And you've still retained the ability to have the SDK config be static (i.e. no user provided function that consumes context). I like it. 👍 |
Quick response to this: You need to get access to the current context. |
From the specification SIG on 19-Nov, it sounds like there isn't a strong need to have the context parameter at this time. Will close this issue in 2 weeks if there's no one that brings a strong argument by then. |
As the author of this issue I am OK on closing (for metrics) this issue as long as the @open-telemetry/technical-committee DOES NOT block having |
Thanks @pellared |
I support closing this issue. I'll make an argument against using the context parameter to the metrics-enabled API. In the Lightstep metrics SDK, we have added a MeasurementProcessor API which has been discussed in the OpenTelemetry specification as far back as the OpenCensus origin. I would like to see OTel add this feature! MeasurementProcessor absolutely uses the context to derive metric attributes. However, to conditionally enable or disable a metric instrument based on context would introduce an undetectable bias in the data. For example, if you only enable a metric instrument when the context is traced, then the metric instrument will under-count depending on sampling rate and the consumer of the data will have no way of knowing this. Metric instruments should strive to measure everything--users should let the context be used to adjust which attributes are used, not to conditionalize. |
While I typically want to future proof APIs, I support closing this issue since adding it later would be relatively easy and with a relatively low cost in terms of maintenance burden. I shared this issue on the #otel-maintainers CNCF Slack channel: https://cloud-native.slack.com/archives/C01NJ7V1KRC/p1732034582753799 and I also added an item to the discussion topics in the Maintainers call to make sure other people see this. I am not able to join the maintainers call, so I would appreciate if somebody else raises this on my behalf :) |
We should add
Context
as a parameter similarly to https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/bridge-api.md#enabled.Context is needed for allowing "context related" behavior. For instance, it enables to user to disable the instrument for some key/value in the context has been set. It can also used to see if the call is within a span. Related PR: #4203
Created here.
The text was updated successfully, but these errors were encountered: