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

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