grpc / grpc/grpc-rust

Getting payload size in a `tower::Layer`

Open
#2,469 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
12.5k
Forks
1.3k
Avg merge
4d 7h
Merged PRs (30d)
24

Description

I am trying to create a [`Layer`](https://docs.rs/tower/latest/tower/trait.Layer.html) that tracks metrics for my gRPC service.
I'd like to follow the [OTEL semantic conventions for RPC](https://opentelemetry.io/docs/specs/semconv/rpc/rpc-metrics).

I having trouble implementing [`rpc.server.request.size`](https://opentelemetry.io/docs/specs/semconv/rpc/rpc-metrics/#metric-rpcserverrequestsize) as I can't seem to find a way to get the size of the message we send over the wire.

I came across [`fn size_hint()`](https://docs.rs/tonic/latest/tonic/transport/trait.Body.html#method.size_hint) on body but from what I can tell its only implemented for streams? (from my testing its always `SizeHint { lower: 0, upper: None }`)

Is there any way to get the payload size from a `Layer` middleware?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.