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

Add Context parameter to Enabled for metrics instruments #4256

Open
pellared opened this issue Oct 11, 2024 · 12 comments · May be fixed by #4262
Open

Add Context parameter to Enabled for metrics instruments #4256

pellared opened this issue Oct 11, 2024 · 12 comments · May be fixed by #4262
Labels
area:api Cross language API specification issue spec:metrics Related to the specification/metrics directory triage:deciding:tc-inbox

Comments

@pellared
Copy link
Member

pellared commented Oct 11, 2024

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.

@jack-berg
Copy link
Member

Why?

@pellared
Copy link
Member Author

pellared commented Oct 12, 2024

Why?

Description updated. Thanks

@pellared pellared added area:api Cross language API specification issue spec:metrics Related to the specification/metrics directory labels Oct 12, 2024
@jack-berg
Copy link
Member

There's no corresponding SDK behavior that would allow the enabled API to change its response based on context.

@pellared
Copy link
Member Author

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.
The SDK can add such behavior in future.

I find that adding is important for Go that require passing Context explicitly. Adding it later to the API would be a burden.
For reference: https://go.dev/wiki/CodeReviewComments#contexts.

CC @open-telemetry/go-maintainers, @open-telemetry/collector-maintainers

@svrnm
Copy link
Member

svrnm commented Oct 14, 2024

@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)

@mx-psi
Copy link
Member

mx-psi commented Oct 14, 2024

Agree with @pellared that adding this is important for Go

pellared added a commit to pellared/opentelemetry-specification that referenced this issue Oct 15, 2024
@jmacd
Copy link
Contributor

jmacd commented Oct 16, 2024

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.

@pellared
Copy link
Member Author

OTel APIs rely on implicit context

This is why in almost all places Context is added as required for languages requiring explicit context. I would prefer to have the specification consistent.

@jmacd
Copy link
Contributor

jmacd commented Oct 16, 2024

@pellared I can't find what you're referring to. In the metrics api.md the word "Context" appears very little, certainly not as a required parameter anywhere. For metrics, we see:

  [Measurements](#measurement) recorded by synchronous instruments can be
  associated with the [Context](../context/README.md).

this implies that Enabled() should accept a context.

In the trace api.md, Context is used but it refers to the OTel context concept, not the Golang Context object.

Moreover, if you look at the one operation that absolutely requires a context, tracer.Start(), we see it is permitted to be implicit:

  The API MAY also have an option for implicitly using
  the current Context as parent as a default behavior.

This seems to set a precedent that context can be implicit. The definition of Context itself also repeats this:

Depending on the language, its usage may be either explicit or implicit.

I still believe it is not necessary to modify the specification in this case.

@pellared
Copy link
Member Author

pellared commented Oct 16, 2024

@pellared I can't find what you're referring to.

@jmacd, I added all these in the description of #4262

Context is used but it refers to the OTel context concept

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 still believe it is not necessary to modify the specification in this case.

I prefer the specification to be less ambiguous. I would rather change the specification and call out that adding a Context parameter MAY be added to any operation if the language does not support implicit Context and requires passing Context explicitly.

@MrAlias
Copy link
Contributor

MrAlias commented Oct 17, 2024

+1 for making our specification explicit in its meaning.

@dmathieu
Copy link
Member

+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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:api Cross language API specification issue spec:metrics Related to the specification/metrics directory triage:deciding:tc-inbox
Projects
None yet
7 participants