quraite 0.1.0__py3-none-any.whl → 0.1.2__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.
- quraite/__init__.py +3 -3
- quraite/adapters/__init__.py +134 -134
- quraite/adapters/agno_adapter.py +157 -159
- quraite/adapters/base.py +123 -123
- quraite/adapters/bedrock_agents_adapter.py +343 -343
- quraite/adapters/flowise_adapter.py +275 -275
- quraite/adapters/google_adk_adapter.py +211 -209
- quraite/adapters/http_adapter.py +255 -239
- quraite/adapters/{langgraph_adapter.py → langchain_adapter.py} +305 -304
- quraite/adapters/{langgraph_server_adapter.py → langchain_server_adapter.py} +252 -252
- quraite/adapters/langflow_adapter.py +192 -192
- quraite/adapters/n8n_adapter.py +220 -220
- quraite/adapters/openai_agents_adapter.py +267 -269
- quraite/adapters/pydantic_ai_adapter.py +307 -312
- quraite/adapters/smolagents_adapter.py +148 -152
- quraite/logger.py +61 -61
- quraite/schema/message.py +91 -91
- quraite/schema/response.py +16 -16
- quraite/serve/__init__.py +1 -1
- quraite/serve/cloudflared.py +210 -210
- quraite/serve/local_agent.py +360 -360
- quraite/traces/traces_adk_openinference.json +379 -0
- quraite/traces/traces_agno_multi_agent.json +669 -0
- quraite/traces/traces_agno_openinference.json +321 -0
- quraite/traces/traces_crewai_openinference.json +155 -0
- quraite/traces/traces_langgraph_openinference.json +349 -0
- quraite/traces/traces_langgraph_openinference_multi_agent.json +2705 -0
- quraite/traces/traces_langgraph_traceloop.json +510 -0
- quraite/traces/traces_openai_agents_multi_agent_1.json +402 -0
- quraite/traces/traces_openai_agents_openinference.json +341 -0
- quraite/traces/traces_pydantic_openinference.json +286 -0
- quraite/traces/traces_pydantic_openinference_multi_agent_1.json +399 -0
- quraite/traces/traces_pydantic_openinference_multi_agent_2.json +398 -0
- quraite/traces/traces_smol_agents_openinference.json +397 -0
- quraite/traces/traces_smol_agents_tool_calling_openinference.json +704 -0
- quraite/tracing/__init__.py +25 -24
- quraite/tracing/constants.py +15 -16
- quraite/tracing/span_exporter.py +101 -115
- quraite/tracing/span_processor.py +47 -49
- quraite/tracing/tool_extractors.py +309 -290
- quraite/tracing/trace.py +564 -564
- quraite/tracing/types.py +179 -179
- quraite/tracing/utils.py +170 -170
- quraite/utils/json_utils.py +269 -269
- quraite-0.1.2.dist-info/METADATA +386 -0
- quraite-0.1.2.dist-info/RECORD +49 -0
- {quraite-0.1.0.dist-info → quraite-0.1.2.dist-info}/WHEEL +1 -1
- quraite-0.1.0.dist-info/METADATA +0 -44
- quraite-0.1.0.dist-info/RECORD +0 -35
quraite/tracing/__init__.py
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
"""Tracing infrastructure for OpenTelemetry span collection and processing."""
|
|
2
|
-
|
|
3
|
-
from quraite.tracing.span_exporter import QuraiteInMemorySpanExporter
|
|
4
|
-
from quraite.tracing.span_processor import QuraiteSimpleSpanProcessor
|
|
5
|
-
from quraite.tracing.tool_extractors import Framework, ToolCallInfo, get_tool_extractor
|
|
6
|
-
from quraite.tracing.trace import AgentSpan, AgentTrace, CostInfo, TokenInfo
|
|
7
|
-
from quraite.tracing.types import Event, Link, Resource, SpanContext, Status
|
|
8
|
-
|
|
9
|
-
__all__ = [
|
|
10
|
-
"AgentSpan",
|
|
11
|
-
"AgentTrace",
|
|
12
|
-
"CostInfo",
|
|
13
|
-
"TokenInfo",
|
|
14
|
-
"Framework",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
1
|
+
"""Tracing infrastructure for OpenTelemetry span collection and processing."""
|
|
2
|
+
|
|
3
|
+
from quraite.tracing.span_exporter import QuraiteInMemorySpanExporter
|
|
4
|
+
from quraite.tracing.span_processor import QuraiteSimpleSpanProcessor
|
|
5
|
+
from quraite.tracing.tool_extractors import Framework, ToolCallInfo, get_tool_extractor
|
|
6
|
+
from quraite.tracing.trace import AgentSpan, AgentTrace, CostInfo, TokenInfo
|
|
7
|
+
from quraite.tracing.types import Event, Link, Resource, SpanContext, Status
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"AgentSpan",
|
|
11
|
+
"AgentTrace",
|
|
12
|
+
"CostInfo",
|
|
13
|
+
"TokenInfo",
|
|
14
|
+
"Framework",
|
|
15
|
+
"Tool",
|
|
16
|
+
"ToolCallInfo",
|
|
17
|
+
"get_tool_extractor",
|
|
18
|
+
"QuraiteInMemorySpanExporter",
|
|
19
|
+
"QuraiteSimpleSpanProcessor",
|
|
20
|
+
"Event",
|
|
21
|
+
"Link",
|
|
22
|
+
"Resource",
|
|
23
|
+
"SpanContext",
|
|
24
|
+
"Status",
|
|
25
|
+
]
|
quraite/tracing/constants.py
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
from enum import Enum
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
SMOLAGENTS = "smolagents"
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
QURAITE_TRACER_NAME = "quraite.instrumentation"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Framework(str, Enum):
|
|
7
|
+
"""Supported agent frameworks."""
|
|
8
|
+
|
|
9
|
+
DEFAULT = "default"
|
|
10
|
+
PYDANTIC_AI = "pydantic_ai"
|
|
11
|
+
LANGCHAIN = "langchain"
|
|
12
|
+
GOOGLE_ADK = "google_adk"
|
|
13
|
+
OPENAI_AGENTS = "openai_agents"
|
|
14
|
+
AGNO = "agno"
|
|
15
|
+
SMOLAGENTS = "smolagents"
|
quraite/tracing/span_exporter.py
CHANGED
|
@@ -1,115 +1,101 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
import threading
|
|
4
|
-
import typing
|
|
5
|
-
from collections import defaultdict
|
|
6
|
-
|
|
7
|
-
from opentelemetry.sdk.trace import ReadableSpan
|
|
8
|
-
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class QuraiteInMemorySpanExporter(SpanExporter):
|
|
12
|
-
def __init__(self) -> None:
|
|
13
|
-
# self.spans: typing.List[ReadableSpan] = []
|
|
14
|
-
self.traces: typing.Dict[int, typing.List[ReadableSpan]] = defaultdict(list)
|
|
15
|
-
self.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
def
|
|
55
|
-
"""Get
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
def
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
print(f"{
|
|
81
|
-
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
#
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def save_traces_to_file(self, filename: typing.Optional[str] = "traces.json"):
|
|
103
|
-
"""Save a trace to a file"""
|
|
104
|
-
traces = []
|
|
105
|
-
for trace_id, spans in self.traces.items():
|
|
106
|
-
traces.append(
|
|
107
|
-
{
|
|
108
|
-
"trace_id": trace_id,
|
|
109
|
-
"spans": [json.loads(span.to_json()) for span in spans],
|
|
110
|
-
}
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
os.makedirs(os.path.dirname(f"traces/{filename}"), exist_ok=True)
|
|
114
|
-
with open(f"traces/{filename}", "w") as f:
|
|
115
|
-
json.dump(traces, f, indent=2)
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import threading
|
|
4
|
+
import typing
|
|
5
|
+
from collections import defaultdict
|
|
6
|
+
|
|
7
|
+
from opentelemetry.sdk.trace import ReadableSpan
|
|
8
|
+
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class QuraiteInMemorySpanExporter(SpanExporter):
|
|
12
|
+
def __init__(self) -> None:
|
|
13
|
+
# self.spans: typing.List[ReadableSpan] = []
|
|
14
|
+
self.traces: typing.Dict[int, typing.List[ReadableSpan]] = defaultdict(list)
|
|
15
|
+
self._stopped = False
|
|
16
|
+
self._lock = threading.Lock()
|
|
17
|
+
|
|
18
|
+
def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult:
|
|
19
|
+
"""Stores a list of spans in memory."""
|
|
20
|
+
if self._stopped:
|
|
21
|
+
return SpanExportResult.FAILURE
|
|
22
|
+
|
|
23
|
+
with self._lock:
|
|
24
|
+
for span in spans:
|
|
25
|
+
# print(f"🟢 span formatted context trace id: {formatted_trace_id}")
|
|
26
|
+
self.traces[span.context.trace_id].append(span)
|
|
27
|
+
# self.spans.append(span)
|
|
28
|
+
|
|
29
|
+
return SpanExportResult.SUCCESS
|
|
30
|
+
|
|
31
|
+
def get_spans_by_trace_id(self, trace_id: int) -> typing.List[ReadableSpan]:
|
|
32
|
+
"""Get all spans for a specific trace ID"""
|
|
33
|
+
return self.traces.get(trace_id, [])
|
|
34
|
+
|
|
35
|
+
def shutdown(self) -> None:
|
|
36
|
+
"""Shut downs the exporter.
|
|
37
|
+
|
|
38
|
+
Calls to export after the exporter has been shut down will fail.
|
|
39
|
+
"""
|
|
40
|
+
print("Shutting down exporter")
|
|
41
|
+
self._stopped = True
|
|
42
|
+
|
|
43
|
+
def force_flush(self, timeout_millis: int = 30000) -> bool:
|
|
44
|
+
return True
|
|
45
|
+
|
|
46
|
+
def get_traces(self) -> typing.Dict[int, typing.List[ReadableSpan]]:
|
|
47
|
+
"""Get all spans grouped by trace ID"""
|
|
48
|
+
return dict(self.traces)
|
|
49
|
+
|
|
50
|
+
def get_trace(self, trace_id: int) -> typing.List[ReadableSpan]:
|
|
51
|
+
"""Get all spans for a specific trace"""
|
|
52
|
+
return self.traces.get(trace_id, [])
|
|
53
|
+
|
|
54
|
+
def get_trace_count(self) -> int:
|
|
55
|
+
"""Get the number of unique traces"""
|
|
56
|
+
return len(self.traces)
|
|
57
|
+
|
|
58
|
+
def print_trace_summary(self):
|
|
59
|
+
"""Print a summary of all traces"""
|
|
60
|
+
print(f"\n{'='*60}")
|
|
61
|
+
print(f"Total Traces: {self.get_trace_count()}")
|
|
62
|
+
for trace_id, spans in self.traces.items():
|
|
63
|
+
print(f"Trace ID: {trace_id}...")
|
|
64
|
+
print(f"Spans in trace: {len(spans)}")
|
|
65
|
+
print(f"TraceIDs: {self.traces.keys()}")
|
|
66
|
+
print(f"{'='*60}\n")
|
|
67
|
+
|
|
68
|
+
# for trace_id, spans in self.traces.items():
|
|
69
|
+
# trace_id_hex = format(trace_id, '032x')
|
|
70
|
+
# print(f"📊 Trace ID: {trace_id_hex}")
|
|
71
|
+
# print(f" Spans in trace: {len(spans)}")
|
|
72
|
+
|
|
73
|
+
# # Sort spans by start time to show execution order
|
|
74
|
+
# sorted_spans = sorted(spans, key=lambda s: s.start_time)
|
|
75
|
+
|
|
76
|
+
# for span in sorted_spans:
|
|
77
|
+
# duration_ms = (span.end_time - span.start_time) / 1e6
|
|
78
|
+
# parent_id = format(span.parent.span_id, '016x') if span.parent else "None"
|
|
79
|
+
# indent = " " if span.parent else ""
|
|
80
|
+
# print(f" {indent}├─ {span.name}")
|
|
81
|
+
# print(f" {indent} ├─ Span ID: {format(span.context.span_id, '016x')}")
|
|
82
|
+
# print(f" {indent} ├─ Parent ID: {parent_id}")
|
|
83
|
+
# print(f" {indent} ├─ Duration: {duration_ms:.2f}ms")
|
|
84
|
+
# if span.attributes:
|
|
85
|
+
# print(f" {indent} └─ Attributes: {dict(span.attributes)}")
|
|
86
|
+
# print()
|
|
87
|
+
|
|
88
|
+
def save_traces_to_file(self, filename: typing.Optional[str] = "traces.json"):
|
|
89
|
+
"""Save a trace to a file"""
|
|
90
|
+
traces = []
|
|
91
|
+
for trace_id, spans in self.traces.items():
|
|
92
|
+
traces.append(
|
|
93
|
+
{
|
|
94
|
+
"trace_id": trace_id,
|
|
95
|
+
"spans": [json.loads(span.to_json()) for span in spans],
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
os.makedirs(os.path.dirname(f"traces/{filename}"), exist_ok=True)
|
|
100
|
+
with open(f"traces/{filename}", "w") as f:
|
|
101
|
+
json.dump(traces, f, indent=2)
|
|
@@ -1,49 +1,47 @@
|
|
|
1
|
-
import typing
|
|
2
|
-
|
|
3
|
-
from opentelemetry.context import (
|
|
4
|
-
_SUPPRESS_INSTRUMENTATION_KEY,
|
|
5
|
-
Context,
|
|
6
|
-
attach,
|
|
7
|
-
detach,
|
|
8
|
-
set_value,
|
|
9
|
-
)
|
|
10
|
-
from opentelemetry.sdk.trace.export import ReadableSpan, SpanExporter, SpanProcessor
|
|
11
|
-
from opentelemetry.trace import Span, logger
|
|
12
|
-
|
|
13
|
-
from quraite.tracing.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
# pylint: disable=unused-argument
|
|
49
|
-
return True
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from opentelemetry.context import (
|
|
4
|
+
_SUPPRESS_INSTRUMENTATION_KEY,
|
|
5
|
+
Context,
|
|
6
|
+
attach,
|
|
7
|
+
detach,
|
|
8
|
+
set_value,
|
|
9
|
+
)
|
|
10
|
+
from opentelemetry.sdk.trace.export import ReadableSpan, SpanExporter, SpanProcessor
|
|
11
|
+
from opentelemetry.trace import Span, logger
|
|
12
|
+
|
|
13
|
+
from quraite.tracing.span_exporter import QuraiteInMemorySpanExporter
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class QuraiteSimpleSpanProcessor(SpanProcessor):
|
|
17
|
+
"""Simple SpanProcessor implementation.
|
|
18
|
+
|
|
19
|
+
SimpleSpanProcessor is an implementation of `SpanProcessor` that
|
|
20
|
+
passes ended spans directly to the configured `SpanExporter`.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, span_exporter: SpanExporter):
|
|
24
|
+
self.span_exporter: QuraiteInMemorySpanExporter = span_exporter
|
|
25
|
+
|
|
26
|
+
def on_start(
|
|
27
|
+
self, span: Span, parent_context: typing.Optional[Context] = None
|
|
28
|
+
) -> None:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
def on_end(self, span: ReadableSpan) -> None:
|
|
32
|
+
if not span.context.trace_flags.sampled:
|
|
33
|
+
return
|
|
34
|
+
token = attach(set_value(_SUPPRESS_INSTRUMENTATION_KEY, True))
|
|
35
|
+
try:
|
|
36
|
+
self.span_exporter.export((span,))
|
|
37
|
+
# pylint: disable=broad-exception-caught
|
|
38
|
+
except Exception:
|
|
39
|
+
logger.exception("Exception while exporting Span.")
|
|
40
|
+
detach(token)
|
|
41
|
+
|
|
42
|
+
def shutdown(self) -> None:
|
|
43
|
+
self.span_exporter.shutdown()
|
|
44
|
+
|
|
45
|
+
def force_flush(self, timeout_millis: int = 30000) -> bool:
|
|
46
|
+
# pylint: disable=unused-argument
|
|
47
|
+
return True
|