Skip to content

Commit

Permalink
Update gRPC instrumentation to comply with spec
Browse files Browse the repository at this point in the history
For open-telemetry#139 - some of these things weren't as clear before.
  • Loading branch information
Michael Stella committed Dec 10, 2020
1 parent 6514f37 commit 7271cde
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def set_trailing_metadata(self, *args, **kwargs):
def abort(self, code, details):
self.code = code
self.details = details
self._active_span.set_attribute("rpc.grpc.status_code", code.name)
self._active_span.set_attribute("rpc.grpc.status_code", code.value[0])
self._active_span.set_status(
Status(status_code=StatusCode.ERROR, description=details)
)
Expand All @@ -126,17 +126,19 @@ def set_code(self, code):
self.code = code
# use details if we already have it, otherwise the status description
details = self.details or code.value[1]
self._active_span.set_attribute("rpc.grpc.status_code", code.name)
self._active_span.set_status(
Status(status_code=StatusCode.ERROR, description=details)
)
self._active_span.set_attribute("rpc.grpc.status_code", code.value[0])
if code != grpc.StatusCode.OK:
self._active_span.set_status(
Status(status_code=StatusCode.ERROR, description=details)
)
return self._servicer_context.set_code(code)

def set_details(self, details):
self.details = details
self._active_span.set_status(
Status(status_code=StatusCode.ERROR, description=details)
)
if self.code != grpc.StatusCode.OK:
self._active_span.set_status(
Status(status_code=StatusCode.ERROR, description=details)
)
return self._servicer_context.set_details(details)


Expand Down Expand Up @@ -181,10 +183,15 @@ def _set_remote_context(self, servicer_context):

def _start_span(self, handler_call_details, context):

# split the handler method into service and method
service, method = handler_call_details.method.lstrip('/').split('/', 1)

# standard attributes
attributes = {
"rpc.method": handler_call_details.method,
"rpc.method": method,
"rpc.service": service,
"rpc.system": "grpc",
"rpc.grpc.status_code": grpc.StatusCode.OK,
"rpc.grpc.status_code": grpc.StatusCode.OK.value[0],
}

metadata = dict(context.invocation_metadata())
Expand Down

0 comments on commit 7271cde

Please sign in to comment.