mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-28 20:52:57 +08:00
asyncpg: Use only the first word from query as a span name (#1324)
This commit is contained in:
@ -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))
|
||||
@ -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))
|
||||
|
@ -134,6 +134,11 @@ class AsyncPGInstrumentor(BaseInstrumentor):
|
||||
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:
|
||||
|
@ -62,7 +62,7 @@ class TestFunctionalAsyncPG(TestBase):
|
||||
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;"
|
||||
)
|
||||
@ -72,6 +72,7 @@ class TestFunctionalAsyncPG(TestBase):
|
||||
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;"
|
||||
)
|
||||
@ -189,7 +190,7 @@ class TestFunctionalAsyncPG_CaptureParameters(TestBase):
|
||||
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;"
|
||||
)
|
||||
@ -203,6 +204,7 @@ class TestFunctionalAsyncPG_CaptureParameters(TestBase):
|
||||
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;"
|
||||
)
|
||||
|
Reference in New Issue
Block a user