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

otelgrpc's UnaryServerInterceptor cannot send metrics with correct grpc status code #4480

Closed
liufuyang opened this issue Oct 25, 2023 · 0 comments · Fixed by #4481
Closed
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelgrpc
Milestone

Comments

@liufuyang
Copy link
Contributor

Description

In this part of the code, as it is in a defer call, the statusCode seems to be always 0 and cannot be set to the actual status returned by the handler call.

defer func(t time.Time) {
elapsedTime := time.Since(t) / time.Millisecond
attr = append(attr, semconv.RPCGRPCStatusCodeKey.Int64(int64(statusCode)))
o := metric.WithAttributes(attr...)
cfg.rpcServerDuration.Record(ctx, int64(elapsedTime), o)
}(time.Now())
)

I guess instead of using defer and moving that piece of code after the handler call should make it work?

@liufuyang liufuyang added area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelgrpc labels Oct 25, 2023
@pellared pellared added this to the untracked milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelgrpc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants