From 8cbce555e423e490753ff790febc3b99b789d63b Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Tue, 1 Jul 2025 11:09:57 -0700 Subject: [PATCH] Add user_id to stt_traced decorator --- CHANGELOG.md | 10 ++++------ src/pipecat/utils/tracing/service_attributes.py | 5 +++++ src/pipecat/utils/tracing/service_decorators.py | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3c683b8b..f1e873569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -<<<<<<< HEAD - Added support for providing "direct" functions, which don't need an accompanying `FunctionSchema` or function definition dict. Instead, metadata (i.e. `name`, `description`, `properties`, and `required`) are automatically @@ -40,11 +39,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 tools = ToolsSchema(standard_tools=[do_something]) ``` -======= -- `user_id` is now populated in the `TranscriptionFrame` and - `InterimTranscriptionFrame` when using a service that provides a `user_id`, - like `DailyTransport` or `LiveKitTransport`. ->>>>>>> 5f958226 (Add user_id to TranscriptionFrame and InterimTranscriptionFrame pushed by STTServices) + + - `user_id` is now populated in the `TranscriptionFrame` and + `InterimTranscriptionFrame` when using a transport that provides a + `user_id`, like `DailyTransport` or `LiveKitTransport`. - Added `watchdog_coroutine()`. This is a watchdog helper for couroutines. So, if you have a coroutine that is waiting for a result and that takes a long diff --git a/src/pipecat/utils/tracing/service_attributes.py b/src/pipecat/utils/tracing/service_attributes.py index 3896bd028..fa9d21904 100644 --- a/src/pipecat/utils/tracing/service_attributes.py +++ b/src/pipecat/utils/tracing/service_attributes.py @@ -125,6 +125,7 @@ def add_stt_span_attributes( transcript: Optional[str] = None, is_final: Optional[bool] = None, language: Optional[str] = None, + user_id: Optional[str] = None, settings: Optional[Dict[str, Any]] = None, vad_enabled: bool = False, ttfb: Optional[float] = None, @@ -140,6 +141,7 @@ def add_stt_span_attributes( transcript: The transcribed text. is_final: Whether this is a final transcript. language: Detected or configured language. + user_id: User ID associated with the audio being transcribed. settings: Service configuration settings. vad_enabled: Whether voice activity detection is enabled. ttfb: Time to first byte in seconds. @@ -161,6 +163,9 @@ def add_stt_span_attributes( if language: span.set_attribute("language", language) + if user_id: + span.set_attribute("user_id", user_id) + if ttfb is not None: span.set_attribute("metrics.ttfb", ttfb) diff --git a/src/pipecat/utils/tracing/service_decorators.py b/src/pipecat/utils/tracing/service_decorators.py index 9078bba15..c5612d2b2 100644 --- a/src/pipecat/utils/tracing/service_decorators.py +++ b/src/pipecat/utils/tracing/service_decorators.py @@ -270,6 +270,7 @@ def traced_stt(func: Optional[Callable] = None, *, name: Optional[str] = None) - transcript=transcript, is_final=is_final, language=str(language) if language else None, + user_id=getattr(self, "_user_id", None), vad_enabled=getattr(self, "vad_enabled", False), settings=settings, ttfb=ttfb,