open-telemetry / opentelemetry-python-contrib

OpenTelemetry instrumentation for Python modules
https://opentelemetry.io
Apache License 2.0
734 stars 606 forks source link

[redis] Redis-sentinel not working #304

Open vtdat opened 3 years ago

vtdat commented 3 years ago

The Redis auto instrumentation is not working with redis-sentinel

Steps to reproduce Setup a redis-sentinel and a redis instance, run an application with sentinel configurations.

What is the expected behavior? Information for sentinel connections

What is the actual behavior?

"Traceback (most recent call last):
  File "/home/vutuandat/.local/share/project_name-tNQ0Wzfa/lib/python3.8/site-packages/opentelemetry/instrumentation/redis/util.py", line 29, in _extract_conn_attributes
    attributes["net.peer.name"] = conn_kwargs["host"]
KeyError: 'host'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vutuandat/.local/share/project_name-tNQ0Wzfa/lib/python3.8/site-packages/opentelemetry/sdk/trace/__init__.py", line 861, in use_span
    yield span
  File "/home/vutuandat/.local/share/project_name-tNQ0Wzfa/lib/python3.8/site-packages/opentelemetry/sdk/trace/__init__.py", line 774, in start_as_current_span
    yield span_context
  File "/home/vutuandat/.local/share/project_name-tNQ0Wzfa/lib/python3.8/site-packages/opentelemetry/instrumentation/redis/__init__.py", line 84, in _traced_execute_command
    _set_connection_attributes(span, instance)
  File "/home/vutuandat/.local/share/project_name-tNQ0Wzfa/lib/python3.8/site-packages/opentelemetry/instrumentation/redis/__init__.py", line 64, in _set_connection_attributes
    for key, value in _extract_conn_attributes(
  File "/home/vutuandat/.local/share/project_name-tNQ0Wzfa/lib/python3.8/site-packages/opentelemetry/instrumentation/redis/util.py", line 33, in _extract_conn_attributes
    attributes["net.peer.name"] = conn_kwargs["path"]
KeyError: 'path'
"

Additional context

python 3.8.5 opentelemetry-sdk 0.17b0 opentelemetry-instrumentation-redis 0.17b0

I did manage to make it run by adding

        try:
            attributes["net.peer.name"] = conn_kwargs["path"]
            attributes["net.transport"] = "Unix"
        except KeyError:
            # just a quick workaround
            attributes["net.peer.name"] = conn_kwargs["connection_pool"].service_name 
            ...

to https://github.com/open-telemetry/opentelemetry-python-contrib/blob/master/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py#L33

however, I'm not sure which information we want to put in span tags.

github-actions[bot] commented 3 years ago

This issue was marked stale due to lack of activity. It will be closed in 30 days.

srikanthccv commented 3 years ago

Similar to #389

github-actions[bot] commented 3 years ago

This issue was marked stale due to lack of activity. It will be closed in 30 days.