mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-01 17:34:38 +08:00
Use is_recording flag in aiopg, asyncpg, dbapi, psycopg2, pymemcache, pymongo, redis, sqlalchemy instrumentations (#1212)
This commit is contained in:
@ -112,9 +112,6 @@ class AsyncPGInstrumentor(BaseInstrumentor):
|
|||||||
unwrap(asyncpg.Connection, method)
|
unwrap(asyncpg.Connection, method)
|
||||||
|
|
||||||
async def _do_execute(self, func, instance, args, kwargs):
|
async def _do_execute(self, func, instance, args, kwargs):
|
||||||
span_attributes = _hydrate_span_from_args(
|
|
||||||
instance, args[0], args[1:] if self.capture_parameters else None,
|
|
||||||
)
|
|
||||||
tracer = getattr(asyncpg, _APPLIED)
|
tracer = getattr(asyncpg, _APPLIED)
|
||||||
|
|
||||||
exception = None
|
exception = None
|
||||||
@ -122,9 +119,14 @@ class AsyncPGInstrumentor(BaseInstrumentor):
|
|||||||
with tracer.start_as_current_span(
|
with tracer.start_as_current_span(
|
||||||
"postgresql", kind=SpanKind.CLIENT
|
"postgresql", kind=SpanKind.CLIENT
|
||||||
) as span:
|
) as span:
|
||||||
|
if span.is_recording():
|
||||||
for attribute, value in span_attributes.items():
|
span_attributes = _hydrate_span_from_args(
|
||||||
span.set_attribute(attribute, value)
|
instance,
|
||||||
|
args[0],
|
||||||
|
args[1:] if self.capture_parameters else None,
|
||||||
|
)
|
||||||
|
for attribute, value in span_attributes.items():
|
||||||
|
span.set_attribute(attribute, value)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = await func(*args, **kwargs)
|
result = await func(*args, **kwargs)
|
||||||
@ -132,11 +134,12 @@ class AsyncPGInstrumentor(BaseInstrumentor):
|
|||||||
exception = exc
|
exception = exc
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
if exception is not None:
|
if span.is_recording():
|
||||||
span.set_status(
|
if exception is not None:
|
||||||
Status(_exception_to_canonical_code(exception))
|
span.set_status(
|
||||||
)
|
Status(_exception_to_canonical_code(exception))
|
||||||
else:
|
)
|
||||||
span.set_status(Status(StatusCanonicalCode.OK))
|
else:
|
||||||
|
span.set_status(Status(StatusCanonicalCode.OK))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
Reference in New Issue
Block a user