lchenn / py-grpc-prometheus

Python gRPC Prometheus
Apache License 2.0
48 stars 25 forks source link

Integration with OpenTelemetry Autotracing #17

Closed RyanSiu1995 closed 3 years ago

RyanSiu1995 commented 3 years ago

When I tried to integrate the OpenTelemetry with this interceptor, it will throw the following exception.

Traceback (most recent call last):
  File "/home/appuser/.local/lib/python3.8/site-packages/grpc/_server.py", line 435, in _call_behavior
    response_or_iterator = behavior(argument, context)
  File "/home/appuser/.local/lib/python3.8/site-packages/opentelemetry/instrumentation/grpc/_server.py", line 273, in telemetry_interceptor
    raise error
  File "/home/appuser/.local/lib/python3.8/site-packages/opentelemetry/instrumentation/grpc/_server.py", line 264, in telemetry_interceptor
    return behavior(request_or_iterator, context)
  File "/home/appuser/.local/lib/python3.8/site-packages/py_grpc_prometheus/prometheus_server_interceptor.py", line 88, in new_behavior
    self._compute_status_code(
  File "/home/appuser/.local/lib/python3.8/site-packages/py_grpc_prometheus/prometheus_server_interceptor.py", line 122, in _compute_status_code
    if servicer_context._state.client == "cancelled":
AttributeError: '_OpenTelemetryServicerContext' object has no attribute '_state'

I propose to have an environment variable or configuration in the interceptor to ignore all the exception raised in the interceptor. Instead, those exceptions can either stream to the logger or mute it. All in all, the interceptor should not fail the request when it has an issue with it.

lchenn commented 3 years ago

Setting it via a configuration to be able to turn it off sounds like a good idea, would you mind send a PR? I think we are already doing so for another config.