Skip to content

Commit

Permalink
Copy gRPC trailers metadata for observation context consumption (#4612)
Browse files Browse the repository at this point in the history
According to gRPC Javadoc, the metadata is not thread-safe.
Similar to the approach taken for handling headers metadata, this
commit ensures that the trailers metadata is also copied for later
consumption by `GrpcServerObservationContext`.

Signed-off-by: Tadaya Tsuyukubo <[email protected]>
  • Loading branch information
ttddyy authored Jan 24, 2024
1 parent ed31ec6 commit 2124ccf
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ public void close(Status status, Metadata trailers) {
if (status.getCause() != null) {
this.observation.error(status.getCause());
}
// Per javadoc, trailers are not thread-safe. Make a copy.
Metadata trailersToKeep = new Metadata();
trailersToKeep.merge(trailers);
GrpcServerObservationContext context = (GrpcServerObservationContext) this.observation.getContext();
context.setStatusCode(status.getCode());
context.setTrailers(trailers);
context.setTrailers(trailersToKeep);
super.close(status, trailers);
}

Expand Down

0 comments on commit 2124ccf

Please sign in to comment.