1515from fastapi import APIRouter , HTTPException , Response , Path
1616from loguru import logger
1717
18- from basic_memory import telemetry
18+ import logfire
1919from basic_memory .deps import (
2020 ProjectConfigV2ExternalDep ,
2121 FileServiceV2ExternalDep ,
@@ -56,15 +56,15 @@ async def get_resource_content(
5656 Raises:
5757 HTTPException: 404 if entity or file not found
5858 """
59- with telemetry . operation (
59+ with logfire . span (
6060 "api.request.resource.get_content" ,
6161 entrypoint = "api" ,
6262 domain = "resource" ,
6363 action = "get_content" ,
6464 ):
6565 logger .debug (f"V2 Getting content for project { project_id } , entity_id: { entity_id } " )
6666
67- with telemetry . scope (
67+ with logfire . span (
6868 "api.resource.get_content.load_entity" ,
6969 domain = "resource" ,
7070 action = "get_content" ,
@@ -74,7 +74,7 @@ async def get_resource_content(
7474 if not entity :
7575 raise HTTPException (status_code = 404 , detail = f"Entity { entity_id } not found" )
7676
77- with telemetry . scope (
77+ with logfire . span (
7878 "api.resource.get_content.validate_path" ,
7979 domain = "resource" ,
8080 action = "get_content" ,
@@ -90,7 +90,7 @@ async def get_resource_content(
9090 detail = "Entity contains invalid file path" ,
9191 )
9292
93- with telemetry . scope (
93+ with logfire . span (
9494 "api.resource.get_content.ensure_exists" ,
9595 domain = "resource" ,
9696 action = "get_content" ,
@@ -102,7 +102,7 @@ async def get_resource_content(
102102 detail = f"File not found: { entity .file_path } " ,
103103 )
104104
105- with telemetry . scope (
105+ with logfire . span (
106106 "api.resource.get_content.read_content" ,
107107 domain = "resource" ,
108108 action = "get_content" ,
@@ -139,7 +139,7 @@ async def create_resource(
139139 Raises:
140140 HTTPException: 400 for invalid file paths, 409 if file already exists
141141 """
142- with telemetry . operation (
142+ with logfire . span (
143143 "api.request.resource.create" ,
144144 entrypoint = "api" ,
145145 domain = "resource" ,
@@ -166,7 +166,7 @@ async def create_resource(
166166 f"Use PUT /resource/{ existing_entity .external_id } to update it." ,
167167 )
168168
169- with telemetry . scope (
169+ with logfire . span (
170170 "api.resource.create.write_file" ,
171171 domain = "resource" ,
172172 action = "create" ,
@@ -175,7 +175,7 @@ async def create_resource(
175175 await file_service .ensure_directory (PathLib (data .file_path ).parent )
176176 checksum = await file_service .write_file (data .file_path , data .content )
177177
178- with telemetry . scope (
178+ with logfire . span (
179179 "api.resource.create.read_metadata" ,
180180 domain = "resource" ,
181181 action = "create" ,
@@ -197,15 +197,15 @@ async def create_resource(
197197 created_at = file_metadata .created_at ,
198198 updated_at = file_metadata .modified_at ,
199199 )
200- with telemetry . scope (
200+ with logfire . span (
201201 "api.resource.create.upsert_entity" ,
202202 domain = "resource" ,
203203 action = "create" ,
204204 phase = "upsert_entity" ,
205205 ):
206206 entity = await entity_repository .add (entity )
207207
208- with telemetry . scope (
208+ with logfire . span (
209209 "api.resource.create.search_index" ,
210210 domain = "resource" ,
211211 action = "create" ,
@@ -258,7 +258,7 @@ async def update_resource(
258258 Raises:
259259 HTTPException: 404 if entity not found, 400 for invalid paths
260260 """
261- with telemetry . operation (
261+ with logfire . span (
262262 "api.request.resource.update" ,
263263 entrypoint = "api" ,
264264 domain = "resource" ,
@@ -282,7 +282,7 @@ async def update_resource(
282282 "Path must be relative and stay within project boundaries." ,
283283 )
284284
285- with telemetry . scope (
285+ with logfire . span (
286286 "api.resource.update.write_file" ,
287287 domain = "resource" ,
288288 action = "update" ,
@@ -297,7 +297,7 @@ async def update_resource(
297297
298298 checksum = await file_service .write_file (target_file_path , data .content )
299299
300- with telemetry . scope (
300+ with logfire . span (
301301 "api.resource.update.read_metadata" ,
302302 domain = "resource" ,
303303 action = "update" ,
@@ -309,7 +309,7 @@ async def update_resource(
309309 content_type = file_service .content_type (target_file_path )
310310 note_type = "canvas" if target_file_path .endswith (".canvas" ) else "file"
311311
312- with telemetry . scope (
312+ with logfire . span (
313313 "api.resource.update.update_entity" ,
314314 domain = "resource" ,
315315 action = "update" ,
@@ -329,7 +329,7 @@ async def update_resource(
329329 if updated_entity is None :
330330 raise HTTPException (status_code = 404 , detail = f"Entity { entity_id } not found" )
331331
332- with telemetry . scope (
332+ with logfire . span (
333333 "api.resource.update.search_index" ,
334334 domain = "resource" ,
335335 action = "update" ,
0 commit comments