Skip to content

Commit 029bd33

Browse files
committed
Add some telemetry to catalog internals
1 parent 1a188eb commit 029bd33

File tree

1 file changed

+53
-39
lines changed
  • services/catalog/src/simcore_service_catalog/api/rest

1 file changed

+53
-39
lines changed

services/catalog/src/simcore_service_catalog/api/rest/_services.py

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from models_library.api_schemas_catalog.services import ServiceGet, ServiceUpdate
1111
from models_library.services import ServiceKey, ServiceType, ServiceVersion
1212
from models_library.services_metadata_published import ServiceMetaDataPublished
13+
from opentelemetry import trace
1314
from pydantic import ValidationError
1415
from pydantic.types import PositiveInt
1516
from servicelib.fastapi.requests_decorators import cancel_on_disconnect
@@ -32,6 +33,8 @@
3233
_logger = logging.getLogger(__name__)
3334

3435
ServicesSelection: TypeAlias = set[tuple[str, str]]
36+
# Obtain the tracer from the global tracer provider
37+
_tracer = trace.get_tracer(__name__)
3538

3639

3740
def _compose_service_details(
@@ -105,56 +108,67 @@ async def list_services(
105108
)
106109

107110
# now get the executable or writable services
108-
services_in_db = {
109-
(s.key, s.version): s
110-
for s in await services_repo.list_services(
111-
gids=[group.gid for group in user_groups],
112-
execute_access=True,
113-
write_access=True,
114-
combine_access_with_and=False,
115-
product_name=x_simcore_products_name,
116-
)
117-
}
111+
with _tracer.start_as_current_span("services_repo.list_services") as span:
112+
span.set_attribute("osparc-gids", f"{[group.gid for group in user_groups]}")
113+
span.set_attribute("osparc-productname", f"{x_simcore_products_name}")
114+
services_in_db = {
115+
(s.key, s.version): s
116+
for s in await services_repo.list_services(
117+
gids=[group.gid for group in user_groups],
118+
execute_access=True,
119+
write_access=True,
120+
combine_access_with_and=False,
121+
product_name=x_simcore_products_name,
122+
)
123+
}
118124
# Non-detailed views from the services_repo database
119125
if not details:
120126
# only return a stripped down version
121127
# NOTE: here validation is not necessary since key,version were already validated
122128
# in terms of time, this takes the most
123-
return [
124-
ServiceGet.construct(
125-
key=key,
126-
version=version,
127-
name="nodetails",
128-
description="nodetails",
129-
type=ServiceType.COMPUTATIONAL,
130-
authors=[{"name": "nodetails", "email": "[email protected]"}],
131-
contact="[email protected]",
132-
inputs={},
133-
outputs={},
134-
deprecated=services_in_db[(key, version)].deprecated,
135-
)
136-
for key, version in services_in_db
137-
]
129+
with _tracer.start_as_current_span("return-non-detailed-view") as span:
130+
span.set_attribute("osparc-gids", f"{[group.gid for group in user_groups]}")
131+
span.set_attribute("osparc-productname", f"{x_simcore_products_name}")
132+
return [
133+
ServiceGet.construct(
134+
key=key,
135+
version=version,
136+
name="nodetails",
137+
description="nodetails",
138+
type=ServiceType.COMPUTATIONAL,
139+
authors=[{"name": "nodetails", "email": "[email protected]"}],
140+
contact="[email protected]",
141+
inputs={},
142+
outputs={},
143+
deprecated=services_in_db[(key, version)].deprecated,
144+
)
145+
for key, version in services_in_db
146+
]
138147

139148
# caching this steps brings down the time to generate it at the expense of being sometimes a bit out of date
140149
@cached(ttl=DIRECTOR_CACHING_TTL)
141150
async def cached_registry_services() -> dict[str, Any]:
142151
return cast(dict[str, Any], await director_client.get("/services"))
143152

144-
(
145-
services_in_registry,
146-
services_access_rights,
147-
services_owner_emails,
148-
) = await asyncio.gather(
149-
cached_registry_services(),
150-
services_repo.list_services_access_rights(
151-
key_versions=services_in_db,
152-
product_name=x_simcore_products_name,
153-
),
154-
groups_repository.list_user_emails_from_gids(
155-
{s.owner for s in services_in_db.values() if s.owner}
156-
),
157-
)
153+
with _tracer.start_as_current_span(
154+
"services_repo.list_services_access_rights"
155+
) as span:
156+
span.set_attribute("osparc-gids", f"{[group.gid for group in user_groups]}")
157+
span.set_attribute("osparc-productname", f"{x_simcore_products_name}")
158+
(
159+
services_in_registry,
160+
services_access_rights,
161+
services_owner_emails,
162+
) = await asyncio.gather(
163+
cached_registry_services(),
164+
services_repo.list_services_access_rights(
165+
key_versions=services_in_db,
166+
product_name=x_simcore_products_name,
167+
),
168+
groups_repository.list_user_emails_from_gids(
169+
{s.owner for s in services_in_db.values() if s.owner}
170+
),
171+
)
158172

159173
# NOTE: for the details of the services:
160174
# 1. we get all the services from the director-v0 (TODO: move the registry to the catalog)

0 commit comments

Comments
 (0)