Add user_id to stt_traced decorator

This commit is contained in:
Mark Backman
2025-07-01 11:09:57 -07:00
parent f6112713e8
commit 8cbce555e4
3 changed files with 10 additions and 6 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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,