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

docs: why does the meteric counter addition required a context object? #3618

Closed
sasha-wing opened this issue Jan 25, 2023 · 5 comments
Closed
Labels
area:metrics Part of OpenTelemetry Metrics enhancement New feature or request pkg:API Related to an API package

Comments

@sasha-wing
Copy link

It is not clear in the documentation why the counter requires the context and how it is using it.

counter.Add(ctx, 1, attribute.String("foo", "bar"))

This one for example.

@sasha-wing sasha-wing added the enhancement New feature or request label Jan 25, 2023
@MrAlias
Copy link
Contributor

MrAlias commented Jan 25, 2023

It is currently used to determine a timeout:

if err := ctx.Err(); err != nil {
return
}

I don't think this by itself justifies keeping the context in the method signature for any synchronous instrument though. The caller can just as easily check if a timeout happened and the call to Add or Record are lightweight enough that they do not need to be canceled halfway through.

Another original idea for including this parameter was so any existing span embedded in the context can be linked to the measurement. This is not currently done though.

@MrAlias MrAlias added pkg:API Related to an API package area:metrics Part of OpenTelemetry Metrics labels Jan 26, 2023
@MrAlias
Copy link
Contributor

MrAlias commented Feb 2, 2023

The context will also be needed when we add support for exemplars.

@MrAlias
Copy link
Contributor

MrAlias commented Feb 2, 2023

Given the context needs specified above, we plan to continue accepting a context argument with the Add/Record method.

@MrAlias MrAlias closed this as not planned Won't fix, can't repro, duplicate, stale Feb 2, 2023
@ravanscafi
Copy link
Contributor

Hello, sorry for reviving this @MrAlias, but how one would go about recording a metric specifically when there's a timeout/context error?

e.g., on an HTTP client implementation, I have a meter using the request context and I would like to keep track of HTTP timeouts, however, the metrics are ignored because of this timeout.

@pellared
Copy link
Member

pellared commented Nov 9, 2023

@ravanscafi We have been recently discussing it. See: #4671 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics enhancement New feature or request pkg:API Related to an API package
Projects
No open projects
Status: Done
Development

No branches or pull requests

4 participants