@@ -278,7 +278,7 @@ async def sync(
278278
279279 # initial paths from db to sync
280280 # path -> checksum
281- with telemetry .span ("sync.project.scan" , force_full = force_full ):
281+ with telemetry .scope ("sync.project.scan" , force_full = force_full ):
282282 report = await self .scan (directory , force_full = force_full )
283283
284284 # order of sync matters to resolve relations effectively
@@ -287,7 +287,7 @@ async def sync(
287287 + f"deleted_files={ len (report .deleted )} , moved_files={ len (report .moves )} "
288288 )
289289
290- with telemetry .span (
290+ with telemetry .scope (
291291 "sync.project.apply_changes" ,
292292 new_count = len (report .new ),
293293 modified_count = len (report .modified ),
@@ -350,15 +350,15 @@ async def sync(
350350 # Only resolve relations if there were actual changes
351351 # If no files changed, no new unresolved relations could have been created
352352 if report .total > 0 :
353- with telemetry .span ("sync.project.resolve_relations" , relation_scope = "all_pending" ):
353+ with telemetry .scope ("sync.project.resolve_relations" , relation_scope = "all_pending" ):
354354 await self .resolve_relations ()
355355 else :
356356 logger .info ("Skipping relation resolution - no file changes detected" )
357357
358358 # Batch-generate vector embeddings for all synced entities
359359 if synced_entity_ids and self .app_config .semantic_search_enabled :
360360 try :
361- with telemetry .span (
361+ with telemetry .scope (
362362 "sync.project.sync_embeddings" ,
363363 entity_count = len (synced_entity_ids ),
364364 ):
@@ -382,7 +382,7 @@ async def sync(
382382 # Update scan watermark after successful sync
383383 # Use the timestamp from sync start (not end) to ensure we catch files
384384 # created during the sync on the next iteration
385- with telemetry .span ("sync.project.update_watermark" ):
385+ with telemetry .scope ("sync.project.update_watermark" ):
386386 current_file_count = await self ._quick_count_files (directory )
387387 if self .entity_repository .project_id is not None :
388388 project = await self .project_repository .find_by_id (
@@ -458,7 +458,7 @@ async def scan(self, directory, force_full: bool = False):
458458 if project is None :
459459 raise ValueError (f"Project not found: { self .entity_repository .project_id } " )
460460
461- with telemetry .span ("sync.project.select_scan_strategy" , force_full = force_full ):
461+ with telemetry .scope ("sync.project.select_scan_strategy" , force_full = force_full ):
462462 # Step 1: Quick file count
463463 logger .debug ("Counting files in directory" )
464464 current_count = await self ._quick_count_files (directory )
@@ -502,13 +502,12 @@ async def scan(self, directory, force_full: bool = False):
502502 logger .warning ("No scan watermark available, falling back to full scan" )
503503 scan_coro = self ._scan_directory_full (directory )
504504
505- with telemetry .contextualize (scan_type = scan_type ):
506- with telemetry .span ("sync.project.filesystem_scan" , scan_type = scan_type ):
507- file_paths_to_scan = await scan_coro
508- if scan_type == "incremental" :
509- logger .debug (
510- f"Incremental scan found { len (file_paths_to_scan )} potentially changed files"
511- )
505+ with telemetry .scope ("sync.project.filesystem_scan" , scan_type = scan_type ):
506+ file_paths_to_scan = await scan_coro
507+ if scan_type == "incremental" :
508+ logger .debug (
509+ f"Incremental scan found { len (file_paths_to_scan )} potentially changed files"
510+ )
512511
513512 # Step 3: Process each file with mtime-based comparison
514513 scanned_paths : Set [str ] = set ()
@@ -569,7 +568,7 @@ async def scan(self, directory, force_full: bool = False):
569568
570569 # Step 4: Detect moves (for both full and incremental scans)
571570 # Check if any "new" files are actually moves by matching checksums
572- with telemetry .span ("sync.project.detect_moves" , new_count = len (report .new )):
571+ with telemetry .scope ("sync.project.detect_moves" , new_count = len (report .new )):
573572 for new_path in list (
574573 report .new
575574 ): # Use list() to allow modification during iteration
@@ -604,7 +603,7 @@ async def scan(self, directory, force_full: bool = False):
604603 # Step 5: Detect deletions (only for full scans)
605604 # Incremental scans can't reliably detect deletions since they only see modified files
606605 if scan_type in ("full_initial" , "full_deletions" , "full_fallback" , "full_forced" ):
607- with telemetry .span ("sync.project.detect_deletions" , scan_type = scan_type ):
606+ with telemetry .scope ("sync.project.detect_deletions" , scan_type = scan_type ):
608607 # Use optimized query for just file paths (not full entities)
609608 db_file_paths = await self .entity_repository .get_all_file_paths ()
610609 logger .debug (f"Found { len (db_file_paths )} db paths for deletion detection" )
@@ -693,7 +692,7 @@ async def sync_file(
693692 except FileNotFoundError :
694693 # File exists in database but not on filesystem
695694 # This indicates a database/filesystem inconsistency - treat as deletion
696- with telemetry .span (
695+ with telemetry .scope (
697696 "sync.file.failure" ,
698697 failure_type = "file_not_found" ,
699698 path = path ,
@@ -715,7 +714,7 @@ async def sync_file(
715714 if isinstance (e , SyncFatalError ) or isinstance (
716715 e .__cause__ , SyncFatalError
717716 ): # pragma: no cover
718- with telemetry .span (
717+ with telemetry .scope (
719718 "sync.file.failure" ,
720719 failure_type = failure_type ,
721720 path = path ,
@@ -728,7 +727,7 @@ async def sync_file(
728727
729728 # Otherwise treat as recoverable file-level error
730729 error_msg = str (e )
731- with telemetry .span (
730+ with telemetry .scope (
732731 "sync.file.failure" ,
733732 failure_type = failure_type ,
734733 path = path ,
@@ -1133,7 +1132,7 @@ async def resolve_relations(self, entity_id: int | None = None):
11331132 # update search index only on successful resolution
11341133 await self .search_service .index_entity (resolved_entity )
11351134 except IntegrityError :
1136- with telemetry .span (
1135+ with telemetry .scope (
11371136 "sync.relation.resolve_conflict" ,
11381137 relation_id = relation .id ,
11391138 relation_type = relation .relation_type ,
@@ -1154,7 +1153,7 @@ async def resolve_relations(self, entity_id: int | None = None):
11541153 try :
11551154 await self .relation_repository .delete (relation .id )
11561155 except Exception as e :
1157- with telemetry .span (
1156+ with telemetry .scope (
11581157 "sync.relation.cleanup_failure" ,
11591158 relation_id = relation .id ,
11601159 relation_type = relation .relation_type ,
0 commit comments