Skip to content

Commit

Permalink
asyncpg: Use only the first word from query as a span name (open-tele…
Browse files Browse the repository at this point in the history
  • Loading branch information
krnr authored and CircleCI committed Nov 13, 2022
1 parent b3172c0 commit 375f7da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0



- `opentelemetry-instrumentation-asyncpg` Fix high cardinality in the span name
([#1324](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1324))

### Added

- `opentelemetry-instrumentation-grpc` add supports to filter requests to instrument. ([#1241](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1241))
Expand All @@ -37,7 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1208](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1208))
- `opentelemetry-instrumentation-aiohttp-client` Fix producing additional spans with each newly created ClientSession
- ([#1246](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1246))
- Add _is_openetlemetry_instrumented check in _InstrumentedFastAPI class
- Add _is_opentelemetry_instrumented check in _InstrumentedFastAPI class
([#1313](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1313))
- Fix uninstrumentation of existing app instances in FastAPI
([#1258](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1258))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ async def _do_execute(self, func, instance, args, kwargs):
params = getattr(instance, "_params", {})
name = args[0] if args[0] else params.get("database", "postgresql")

try:
name = name.split()[0]
except IndexError:
name = ""

with self._tracer.start_as_current_span(
name, kind=SpanKind.CLIENT
) as span:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_instrumented_execute_method_without_arguments(self, *_, **__):
self.assertEqual(len(spans), 1)
self.assertIs(StatusCode.UNSET, spans[0].status.status_code)
self.check_span(spans[0])
self.assertEqual(spans[0].name, "SELECT 42;")
self.assertEqual(spans[0].name, "SELECT")
self.assertEqual(
spans[0].attributes[SpanAttributes.DB_STATEMENT], "SELECT 42;"
)
Expand All @@ -72,6 +72,7 @@ def test_instrumented_fetch_method_without_arguments(self, *_, **__):
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
self.check_span(spans[0])
self.assertEqual(spans[0].name, "SELECT")
self.assertEqual(
spans[0].attributes[SpanAttributes.DB_STATEMENT], "SELECT 42;"
)
Expand Down Expand Up @@ -189,7 +190,7 @@ def test_instrumented_execute_method_with_arguments(self, *_, **__):
self.assertIs(StatusCode.UNSET, spans[0].status.status_code)

self.check_span(spans[0])
self.assertEqual(spans[0].name, "SELECT $1;")
self.assertEqual(spans[0].name, "SELECT")
self.assertEqual(
spans[0].attributes[SpanAttributes.DB_STATEMENT], "SELECT $1;"
)
Expand All @@ -203,6 +204,7 @@ def test_instrumented_fetch_method_with_arguments(self, *_, **__):
self.assertEqual(len(spans), 1)

self.check_span(spans[0])
self.assertEqual(spans[0].name, "SELECT")
self.assertEqual(
spans[0].attributes[SpanAttributes.DB_STATEMENT], "SELECT $1;"
)
Expand Down

0 comments on commit 375f7da

Please sign in to comment.