aiqa-client 0.1.4__py3-none-any.whl → 0.1.6__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.
- aiqa/__init__.py +1 -1
- aiqa/tracing.py +18 -7
- {aiqa_client-0.1.4.dist-info → aiqa_client-0.1.6.dist-info}/METADATA +1 -1
- aiqa_client-0.1.6.dist-info/RECORD +9 -0
- aiqa_client-0.1.4.dist-info/RECORD +0 -9
- {aiqa_client-0.1.4.dist-info → aiqa_client-0.1.6.dist-info}/WHEEL +0 -0
- {aiqa_client-0.1.4.dist-info → aiqa_client-0.1.6.dist-info}/licenses/LICENSE +0 -0
- {aiqa_client-0.1.4.dist-info → aiqa_client-0.1.6.dist-info}/top_level.txt +0 -0
aiqa/__init__.py
CHANGED
aiqa/tracing.py
CHANGED
|
@@ -12,6 +12,7 @@ from functools import wraps
|
|
|
12
12
|
from opentelemetry import trace
|
|
13
13
|
from opentelemetry.sdk.trace import TracerProvider
|
|
14
14
|
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
|
15
|
+
from opentelemetry.sdk.trace.sampling import ALWAYS_ON
|
|
15
16
|
from opentelemetry.sdk.resources import Resource
|
|
16
17
|
from opentelemetry.semconv.resource import ResourceAttributes
|
|
17
18
|
from opentelemetry.trace import Status, StatusCode
|
|
@@ -24,12 +25,14 @@ logger = logging.getLogger(__name__)
|
|
|
24
25
|
exporter = AIQASpanExporter()
|
|
25
26
|
|
|
26
27
|
# Initialize OpenTelemetry
|
|
28
|
+
# Use ALWAYS_ON sampler to ensure all spans are recorded (important for FastAPI async contexts)
|
|
27
29
|
provider = TracerProvider(
|
|
28
30
|
resource=Resource.create(
|
|
29
31
|
{
|
|
30
32
|
ResourceAttributes.SERVICE_NAME: os.getenv("OTEL_SERVICE_NAME", "aiqa-service"),
|
|
31
33
|
}
|
|
32
|
-
)
|
|
34
|
+
),
|
|
35
|
+
sampler=ALWAYS_ON
|
|
33
36
|
)
|
|
34
37
|
|
|
35
38
|
provider.add_span_processor(BatchSpanProcessor(exporter))
|
|
@@ -185,11 +188,13 @@ def WithTracing(
|
|
|
185
188
|
del input_data[key]
|
|
186
189
|
|
|
187
190
|
# Use start_as_current_span to ensure span is recorded by BatchSpanProcessor
|
|
188
|
-
# This automatically manages context and ends the span when exiting
|
|
189
191
|
with tracer.start_as_current_span(fn_name) as span:
|
|
190
|
-
#
|
|
192
|
+
# Check if span is recording - if not, spans won't be exported
|
|
191
193
|
if not span.is_recording():
|
|
192
|
-
logger.warning(f"Span {fn_name} is not recording -
|
|
194
|
+
logger.warning(f"Span {fn_name} is not recording - will not be exported")
|
|
195
|
+
return await fn(*args, **kwargs)
|
|
196
|
+
|
|
197
|
+
logger.debug(f"Span {fn_name} is recording, trace_id={format(span.get_span_context().trace_id, '032x')}")
|
|
193
198
|
|
|
194
199
|
if input_data is not None:
|
|
195
200
|
# Serialize for span attributes (OpenTelemetry only accepts primitives or JSON strings)
|
|
@@ -217,12 +222,16 @@ def WithTracing(
|
|
|
217
222
|
span.set_attribute("output", _serialize_for_span(output_data))
|
|
218
223
|
span.set_status(Status(StatusCode.OK))
|
|
219
224
|
|
|
225
|
+
logger.debug(f"Span {fn_name} completed successfully, is_recording={span.is_recording()}")
|
|
220
226
|
return result
|
|
221
227
|
except Exception as exception:
|
|
222
228
|
error = exception if isinstance(exception, Exception) else Exception(str(exception))
|
|
223
229
|
span.record_exception(error)
|
|
224
230
|
span.set_status(Status(StatusCode.ERROR, str(error)))
|
|
225
231
|
raise
|
|
232
|
+
finally:
|
|
233
|
+
# Log when span context exits - span should be ended automatically by context manager
|
|
234
|
+
logger.debug(f"Span {fn_name} context exiting, is_recording={span.is_recording()}")
|
|
226
235
|
|
|
227
236
|
async_traced_fn._is_traced = True
|
|
228
237
|
logger.debug(f"Function {fn_name} is now traced (async)")
|
|
@@ -240,11 +249,13 @@ def WithTracing(
|
|
|
240
249
|
del input_data[key]
|
|
241
250
|
|
|
242
251
|
# Use start_as_current_span to ensure span is recorded by BatchSpanProcessor
|
|
243
|
-
# This automatically manages context and ends the span when exiting
|
|
244
252
|
with tracer.start_as_current_span(fn_name) as span:
|
|
245
|
-
#
|
|
253
|
+
# Check if span is recording - if not, spans won't be exported
|
|
246
254
|
if not span.is_recording():
|
|
247
|
-
logger.warning(f"Span {fn_name} is not recording -
|
|
255
|
+
logger.warning(f"Span {fn_name} is not recording - will not be exported")
|
|
256
|
+
return fn(*args, **kwargs)
|
|
257
|
+
|
|
258
|
+
logger.debug(f"Span {fn_name} is recording, trace_id={format(span.get_span_context().trace_id, '032x')}")
|
|
248
259
|
|
|
249
260
|
if input_data is not None:
|
|
250
261
|
# Serialize for span attributes (OpenTelemetry only accepts primitives or JSON strings)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
aiqa/__init__.py,sha256=KXcAhHf_aZCgs6bn5Gw3IHccunqZzjbj8md0RuWSRAg,470
|
|
2
|
+
aiqa/aiqa_exporter.py,sha256=vXyX6Q_iOjrDz3tCPOMXuBTQg7ocACdOOqzpkUqhy9g,19131
|
|
3
|
+
aiqa/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
aiqa/tracing.py,sha256=mWYIZ2Pla91oUY5a6OXOJWUR2eYtjoQkYPaJdBTpho8,13522
|
|
5
|
+
aiqa_client-0.1.6.dist-info/licenses/LICENSE,sha256=kIzkzLuzG0HHaWYm4F4W5FeJ1Yxut3Ec6bhLWyw798A,1062
|
|
6
|
+
aiqa_client-0.1.6.dist-info/METADATA,sha256=Yu-H7t101WTN5rdwJl8-7AAVemL9hHZVxSGjZifurKk,3772
|
|
7
|
+
aiqa_client-0.1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
aiqa_client-0.1.6.dist-info/top_level.txt,sha256=nwcsuVVSuWu27iLxZd4n1evVzv1W6FVTrSnCXCc-NQs,5
|
|
9
|
+
aiqa_client-0.1.6.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
aiqa/__init__.py,sha256=MwDG0A3kszFsknTCxQ3l8lX1QB2soTMSMZ2YhI7FcYU,470
|
|
2
|
-
aiqa/aiqa_exporter.py,sha256=vXyX6Q_iOjrDz3tCPOMXuBTQg7ocACdOOqzpkUqhy9g,19131
|
|
3
|
-
aiqa/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
aiqa/tracing.py,sha256=Aq4VbX6czSO7LtIcA6tTXghtw9-upZ802g3DNylzoq8,12680
|
|
5
|
-
aiqa_client-0.1.4.dist-info/licenses/LICENSE,sha256=kIzkzLuzG0HHaWYm4F4W5FeJ1Yxut3Ec6bhLWyw798A,1062
|
|
6
|
-
aiqa_client-0.1.4.dist-info/METADATA,sha256=WU-tzSni5NhyJfUHdq4f0lX6JHOPW0VRGrtkW6XL7mo,3772
|
|
7
|
-
aiqa_client-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
aiqa_client-0.1.4.dist-info/top_level.txt,sha256=nwcsuVVSuWu27iLxZd4n1evVzv1W6FVTrSnCXCc-NQs,5
|
|
9
|
-
aiqa_client-0.1.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|