diff --git a/instrumentation/opentelemetry-instrumentation-redis/CHANGELOG.md b/instrumentation/opentelemetry-instrumentation-redis/CHANGELOG.md index bac3153a811..e7f8d248741 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/CHANGELOG.md +++ b/instrumentation/opentelemetry-instrumentation-redis/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Update default SpanKind to `SpanKind.CLIENT` ([#965](https://github.com/open-telemetry/opentelemetry-python/pull/965)) - Change package name to opentelemetry-instrumentation-redis ([#966](https://github.com/open-telemetry/opentelemetry-python/pull/966)) @@ -9,4 +10,4 @@ Released 2020-05-12 -- Initial release \ No newline at end of file +- Initial release diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py index fef856041e8..e2ab78b5356 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py @@ -72,7 +72,9 @@ def _set_connection_attributes(span, conn): def _traced_execute_command(func, instance, args, kwargs): tracer = getattr(redis, "_opentelemetry_tracer") query = _format_command_args(args) - with tracer.start_as_current_span(_CMD) as span: + with tracer.start_as_current_span( + _CMD, kind=trace.SpanKind.CLIENT + ) as span: span.set_attribute("service", tracer.instrumentation_info.name) span.set_attribute(_RAWCMD, query) _set_connection_attributes(span, instance) @@ -86,7 +88,9 @@ def _traced_execute_pipeline(func, instance, args, kwargs): cmds = [_format_command_args(c) for c, _ in instance.command_stack] resource = "\n".join(cmds) - with tracer.start_as_current_span(_CMD) as span: + with tracer.start_as_current_span( + _CMD, kind=trace.SpanKind.CLIENT + ) as span: span.set_attribute("service", tracer.instrumentation_info.name) span.set_attribute(_RAWCMD, resource) _set_connection_attributes(span, instance) diff --git a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py index 86b2459c112..c306dca3637 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py +++ b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py @@ -17,9 +17,23 @@ from opentelemetry.instrumentation.redis import RedisInstrumentor from opentelemetry.test.test_base import TestBase +from opentelemetry.trace import SpanKind class TestRedis(TestBase): + def test_span_properties(self): + redis_client = redis.Redis() + RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) + + with mock.patch.object(redis_client, "connection"): + redis_client.get("key") + + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 1) + span = spans[0] + self.assertEqual(span.name, "redis.command") + self.assertEqual(span.kind, SpanKind.CLIENT) + def test_instrument_uninstrument(self): redis_client = redis.Redis() RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)