Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncpg: Use only the first word from query as a span name #1324

Merged
merged 5 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 Down Expand Up @@ -42,7 +45,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