File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 28282 . Alternative: Use ONLY ` @trace_async() ` decorator (but lose OpenAI-specific metrics)
29293 . ** NEVER** : Mix decorators with client tracing - this always causes duplicates
3030
31- ** Confirmed Working Solution** :
31+ ** Confirmed Working Solutions** :
32+
33+ ** Option 1 - No Function Tracing** (simplest):
3234``` python
3335class say_hi :
3436 def __init__ (self ):
@@ -41,6 +43,21 @@ class say_hi:
4143 # ... rest of streaming logic
4244```
4345
46+ ** Option 2 - With Function Tracing** (recommended):
47+ ``` python
48+ class say_hi :
49+ def __init__ (self ):
50+ self .openai_client = trace_async_openai(AsyncOpenAI())
51+
52+ @trace_async () # ✅ Works when function returns string
53+ async def hi (self , cur_str : str ) -> str : # Return complete response
54+ response = await self .openai_client.chat.completions.create(... )
55+ complete_answer = " "
56+ async for chunk in response:
57+ complete_answer += chunk.choices[0 ].delta.content or " "
58+ return complete_answer # ✅ Return instead of yield
59+ ```
60+
4461## Project Structure Insights
4562
4663### Tracing Architecture
You can’t perform that action at this time.
0 commit comments