From 7af87e1becfe303e555347c8ed7055a08ffe8895 Mon Sep 17 00:00:00 2001 From: dbf <13336073+fullonic@users.noreply.github.com> Date: Mon, 6 Feb 2023 13:20:20 +0100 Subject: [PATCH] [TortoiseORM instrumentation] Fix `AttributeError: type object 'Config' has no attribute 'title'` (#1575) * Use pydantic model name as default `title` value * Update `CHANGELOG.md` * Format with black * Lint with `black` --- CHANGELOG.md | 2 ++ .../instrumentation/tortoiseorm/__init__.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57b92e590c..ba513aebfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fix TortoiseORM instrumentation `AttributeError: type object 'Config' has no attribute 'title'` + ([#1575](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1575)) - Fix SQLAlchemy uninstrumentation ([#1581](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1581)) - `opentelemetry-instrumentation-grpc` Fix code()/details() of _OpentelemetryServicerContext. diff --git a/instrumentation/opentelemetry-instrumentation-tortoiseorm/src/opentelemetry/instrumentation/tortoiseorm/__init__.py b/instrumentation/opentelemetry-instrumentation-tortoiseorm/src/opentelemetry/instrumentation/tortoiseorm/__init__.py index f6ef645246..0b1ae4a29e 100644 --- a/instrumentation/opentelemetry-instrumentation-tortoiseorm/src/opentelemetry/instrumentation/tortoiseorm/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tortoiseorm/src/opentelemetry/instrumentation/tortoiseorm/__init__.py @@ -291,14 +291,19 @@ async def _from_queryset(self, func, modelcls, args, kwargs): name = f"pydantic.{func.__name__}" with self._tracer.start_as_current_span( - name, kind=SpanKind.INTERNAL + name, + kind=SpanKind.INTERNAL, ) as span: if span.is_recording(): span_attributes = {} model_config = getattr(modelcls, "Config", None) if model_config: - model_title = getattr(modelcls.Config, "title") + model_title = getattr( + modelcls.Config, + "title", + modelcls.__name__, + ) if model_title: span_attributes["pydantic.model"] = model_title