Skip to content

Commit

Permalink
add trailing_metadata to _OpenTelemetryServicerContext
Browse files Browse the repository at this point in the history
The trailing_metadata method was added to grpc._server.ServicerContext
in gRPC v1.38.0, and we would like to use it with OpenTelemetry in our
custom interceptors. Doing a hasattr check to maintain support for
earlier versions of gRPC.
  • Loading branch information
jbraswell committed Jan 20, 2022
1 parent dd72d94 commit 618748d
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def send_initial_metadata(self, *args, **kwargs):
def set_trailing_metadata(self, *args, **kwargs):
return self._servicer_context.set_trailing_metadata(*args, **kwargs)

def trailing_metadata(self):
# This method was added to grpc.ServicerContext in gRPC v1.38.0. We do
# this hasattr check to maintain support for earlier gRPC versions.
if hasattr(self._servicer_context, "trailing_metadata"):
return self._servicer_context.trailing_metadata()
raise NotImplementedError()

def abort(self, code, details):
self.code = code
self.details = details
Expand Down

0 comments on commit 618748d

Please sign in to comment.