aiqa-client 0.2.1__py3-none-any.whl → 0.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aiqa-client
3
- Version: 0.2.1
3
+ Version: 0.3.4
4
4
  Summary: OpenTelemetry-based Python client for tracing functions and sending traces to the AIQA server
5
5
  Author-email: AIQA <info@aiqa.dev>
6
6
  License: MIT
@@ -72,7 +72,15 @@ export AIQA_API_KEY="your-api-key"
72
72
  ### Basic Usage
73
73
 
74
74
  ```python
75
- from aiqa import WithTracing
75
+ from dotenv import load_dotenv
76
+ from aiqa import get_aiqa_client, WithTracing
77
+
78
+ # Load environment variables from .env file (if using one)
79
+ load_dotenv()
80
+
81
+ # Initialize client (must be called before using WithTracing)
82
+ # This loads environment variables and initializes the tracing system
83
+ get_aiqa_client()
76
84
 
77
85
  @WithTracing
78
86
  def my_function(x, y):
@@ -108,12 +116,12 @@ def my_function(data):
108
116
  Spans are automatically flushed every 5 seconds. To flush immediately:
109
117
 
110
118
  ```python
111
- from aiqa import flush_spans
119
+ from aiqa import flush_tracing
112
120
  import asyncio
113
121
 
114
122
  async def main():
115
123
  # Your code here
116
- await flush_spans()
124
+ await flush_tracing()
117
125
 
118
126
  asyncio.run(main())
119
127
  ```
@@ -144,6 +152,87 @@ def my_function():
144
152
  # ... rest of function
145
153
  ```
146
154
 
155
+ ### Grouping Traces by Conversation
156
+
157
+ To group multiple traces together that are part of the same conversation or session:
158
+
159
+ ```python
160
+ from aiqa import WithTracing, set_conversation_id
161
+
162
+ @WithTracing
163
+ def handle_user_request(user_id: str, session_id: str):
164
+ # Set conversation ID to group all traces for this user session
165
+ set_conversation_id(f"user_{user_id}_session_{session_id}")
166
+ # All spans created in this function and its children will have this gen_ai.conversation.id
167
+ # ... rest of function
168
+ ```
169
+
170
+ The `gen_ai.conversation.id` attribute allows you to filter and group traces in the AIQA server by conversation, making it easier to analyze multi-step interactions or user sessions. See the [OpenTelemetry GenAI Events specification](https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-events/) for more details.
171
+
172
+ ### Trace ID Propagation Across Services/Agents
173
+
174
+ To link traces across different services or agents, you can extract and propagate trace IDs:
175
+
176
+ #### Getting Current Trace ID
177
+
178
+ ```python
179
+ from aiqa import get_trace_id, get_span_id
180
+
181
+ # Get the current trace ID and span ID
182
+ trace_id = get_trace_id() # Returns hex string (32 chars) or None
183
+ span_id = get_span_id() # Returns hex string (16 chars) or None
184
+
185
+ # Pass these to another service (e.g., in HTTP headers, message queue, etc.)
186
+ ```
187
+
188
+ #### Continuing a Trace in Another Service
189
+
190
+ ```python
191
+ from aiqa import create_span_from_trace_id
192
+
193
+ # Continue a trace from another service/agent
194
+ # trace_id and parent_span_id come from the other service
195
+ with create_span_from_trace_id(
196
+ trace_id="abc123...",
197
+ parent_span_id="def456...",
198
+ span_name="service_b_operation"
199
+ ):
200
+ # Your code here - this span will be linked to the original trace
201
+ pass
202
+ ```
203
+
204
+ #### Using OpenTelemetry Context Propagation (Recommended)
205
+
206
+ For HTTP requests, use the built-in context propagation:
207
+
208
+ ```python
209
+ from aiqa import inject_trace_context, extract_trace_context
210
+ import requests
211
+ from opentelemetry.trace import use_span
212
+
213
+ # In the sending service:
214
+ headers = {}
215
+ inject_trace_context(headers) # Adds trace context to headers
216
+ response = requests.get("http://other-service/api", headers=headers)
217
+
218
+ # In the receiving service:
219
+ # Extract context from incoming request headers
220
+ ctx = extract_trace_context(request.headers)
221
+
222
+ # Use the context to create a span
223
+ from opentelemetry.trace import use_span
224
+ with use_span(ctx):
225
+ # Your code here
226
+ pass
227
+
228
+ # Or create a span with the context
229
+ from opentelemetry import trace
230
+ tracer = trace.get_tracer("aiqa-tracer")
231
+ with tracer.start_as_current_span("operation", context=ctx):
232
+ # Your code here
233
+ pass
234
+ ```
235
+
147
236
  ## Features
148
237
 
149
238
  - Automatic tracing of function calls (sync and async)
@@ -151,6 +240,7 @@ def my_function():
151
240
  - Automatic error tracking and exception recording
152
241
  - Thread-safe span buffering and auto-flushing
153
242
  - OpenTelemetry context propagation for nested spans
243
+ - Trace ID propagation utilities for distributed tracing
154
244
 
155
245
  ## Example
156
246
 
@@ -0,0 +1,14 @@
1
+ aiqa/__init__.py,sha256=FhkrSi0tVGWTz_KbKCrzEw68qm8Ji6txwOAo6cFZPgE,1563
2
+ aiqa/aiqa_exporter.py,sha256=ZfkIwh8H1mgBZ7fJtM_RhuancCAgcnNuEWsADib4rsc,26806
3
+ aiqa/client.py,sha256=wE6EsypbTfp3Cz39IhEycEVT0IZGdJz7yQvtZ15qKJo,6364
4
+ aiqa/experiment_runner.py,sha256=ZEDwECstAv4lWXpcdB9WSxfDQj43iqkGzB_YzoY933M,12053
5
+ aiqa/object_serialiser.py,sha256=pgcBVw5sZH8f7N6n3-qOvEcbNhuPS5yq7qdhaNT6Sks,15236
6
+ aiqa/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ aiqa/test_experiment_runner.py,sha256=LM8BuCrzBZL0Wyu_ierK0tNLsOUxxMTAHbAGW2G0qp0,5562
8
+ aiqa/test_tracing.py,sha256=mSVrhRQ6Dz5djlSUkCt097sIr84562w6E0BnuQDpMrI,8347
9
+ aiqa/tracing.py,sha256=akilXthvAz8NfJKl3293cHsdJU_P3z4kpdTDfwHipZ0,50014
10
+ aiqa_client-0.3.4.dist-info/licenses/LICENSE,sha256=kIzkzLuzG0HHaWYm4F4W5FeJ1Yxut3Ec6bhLWyw798A,1062
11
+ aiqa_client-0.3.4.dist-info/METADATA,sha256=wgrAvEjqMucY0OWU_vK0EI2HYD01uoTicSe4SkeKdqI,6712
12
+ aiqa_client-0.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ aiqa_client-0.3.4.dist-info/top_level.txt,sha256=nwcsuVVSuWu27iLxZd4n1evVzv1W6FVTrSnCXCc-NQs,5
14
+ aiqa_client-0.3.4.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- aiqa/__init__.py,sha256=Co9t4kYAXI4WKhnTlIhIcQTeJJgFF0mzgmj0yhaS6p4,539
2
- aiqa/aiqa_exporter.py,sha256=aEXMfdUL2OILt9H4CRkpoi9EgOqr1UthyQFrimZoDFk,19200
3
- aiqa/client.py,sha256=1QSZhPdpRJilASuS7YtYlzcTNARY0O6lnQB7m2Jm-jA,1421
4
- aiqa/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- aiqa/tracing.py,sha256=rtMXbcU13nQYepV-KAP5Sugui8Ox-eQCgksRp3VlwpM,20367
6
- aiqa_client-0.2.1.dist-info/licenses/LICENSE,sha256=kIzkzLuzG0HHaWYm4F4W5FeJ1Yxut3Ec6bhLWyw798A,1062
7
- aiqa_client-0.2.1.dist-info/METADATA,sha256=WgHjtG5pmyViDill6UnD3DjzE3mLl_ZLE-rE7x2ECak,3772
8
- aiqa_client-0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- aiqa_client-0.2.1.dist-info/top_level.txt,sha256=nwcsuVVSuWu27iLxZd4n1evVzv1W6FVTrSnCXCc-NQs,5
10
- aiqa_client-0.2.1.dist-info/RECORD,,