observagent 0.1.0__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.
observagent/__init__.py
ADDED
observagent/core.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# observagent_sdk/src/observagent/client.py
|
|
2
|
+
import os
|
|
3
|
+
from contextlib import contextmanager
|
|
4
|
+
from opentelemetry import trace, metrics
|
|
5
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
6
|
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
|
7
|
+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
|
8
|
+
|
|
9
|
+
# Added imports for Metrics
|
|
10
|
+
from opentelemetry.sdk.metrics import MeterProvider
|
|
11
|
+
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
|
|
12
|
+
from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter
|
|
13
|
+
|
|
14
|
+
from opentelemetry.sdk.resources import Resource
|
|
15
|
+
from opentelemetry.instrumentation.google_genai import GoogleGenAiSdkInstrumentor
|
|
16
|
+
|
|
17
|
+
class Observagent:
|
|
18
|
+
_trace_provider = None
|
|
19
|
+
_tracer = None
|
|
20
|
+
_metric_provider = None
|
|
21
|
+
_meter = None
|
|
22
|
+
|
|
23
|
+
@staticmethod
|
|
24
|
+
def init(service_name: str, endpoint: str = "http://34.186.209.74:30080"):
|
|
25
|
+
print(f"👁️ Initializing Observagent for service: '{service_name}'...")
|
|
26
|
+
|
|
27
|
+
os.environ["OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"] = "true"
|
|
28
|
+
|
|
29
|
+
resource = Resource.create({"service.name": service_name})
|
|
30
|
+
|
|
31
|
+
# ------------------------------------------------------------
|
|
32
|
+
# 1. Tracing Setup
|
|
33
|
+
# ------------------------------------------------------------
|
|
34
|
+
Observagent._trace_provider = TracerProvider(resource=resource)
|
|
35
|
+
trace_exporter = OTLPSpanExporter(f"{endpoint}/v1/traces")
|
|
36
|
+
span_processor = BatchSpanProcessor(trace_exporter)
|
|
37
|
+
Observagent._trace_provider.add_span_processor(span_processor)
|
|
38
|
+
trace.set_tracer_provider(Observagent._trace_provider)
|
|
39
|
+
Observagent._tracer = trace.get_tracer("observagent.core")
|
|
40
|
+
|
|
41
|
+
# ------------------------------------------------------------
|
|
42
|
+
# 2. Metrics Setup
|
|
43
|
+
# ------------------------------------------------------------
|
|
44
|
+
metric_exporter = OTLPMetricExporter(endpoint=f"{endpoint}/v1/metrics")
|
|
45
|
+
# PeriodicExportingMetricReader batches and sends metrics at regular intervals
|
|
46
|
+
reader = PeriodicExportingMetricReader(metric_exporter)
|
|
47
|
+
|
|
48
|
+
Observagent._metric_provider = MeterProvider(
|
|
49
|
+
resource=resource,
|
|
50
|
+
metric_readers=[reader]
|
|
51
|
+
)
|
|
52
|
+
metrics.set_meter_provider(Observagent._metric_provider)
|
|
53
|
+
Observagent._meter = metrics.get_meter("observagent.core")
|
|
54
|
+
|
|
55
|
+
# ------------------------------------------------------------
|
|
56
|
+
# 3. Instrumentation
|
|
57
|
+
# ------------------------------------------------------------
|
|
58
|
+
# This instrumentor will now automatically pick up both the tracer and meter providers
|
|
59
|
+
GoogleGenAiSdkInstrumentor().instrument()
|
|
60
|
+
|
|
61
|
+
print("🚀 Observagent is active and monitoring AI interactions (Traces & Metrics).")
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
@contextmanager
|
|
65
|
+
def track_session(conversation_id: str, user_id: str = "anonymous"):
|
|
66
|
+
"""
|
|
67
|
+
A context manager wrapper that links a conversation flow together
|
|
68
|
+
and attaches specific user metadata context to the execution.
|
|
69
|
+
"""
|
|
70
|
+
if not Observagent._tracer:
|
|
71
|
+
yield
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
# Start an explicit orchestration span
|
|
75
|
+
with Observagent._tracer.start_as_current_span("observagent.chat_session") as span:
|
|
76
|
+
# Inject official OpenTelemetry GenAI Semantic Convention tags
|
|
77
|
+
span.set_attribute("gen_ai.conversation.id", conversation_id)
|
|
78
|
+
span.set_attribute("enduser.id", user_id)
|
|
79
|
+
try:
|
|
80
|
+
yield span
|
|
81
|
+
except Exception as e:
|
|
82
|
+
span.record_exception(e)
|
|
83
|
+
span.set_status(trace.StatusCode.ERROR, str(e))
|
|
84
|
+
raise
|
|
85
|
+
|
|
86
|
+
@staticmethod
|
|
87
|
+
def shutdown():
|
|
88
|
+
# Clean shutdown for both providers to ensure remaining data is flushed
|
|
89
|
+
if Observagent._trace_provider:
|
|
90
|
+
Observagent._trace_provider.shutdown()
|
|
91
|
+
if Observagent._metric_provider:
|
|
92
|
+
Observagent._metric_provider.shutdown()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: observagent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An OpenTelemetry-based SDK for monitoring GenAI applications.
|
|
5
|
+
Author-email: Andre <your.email@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/yourusername/observagent
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: opentelemetry-api
|
|
15
|
+
Requires-Dist: opentelemetry-sdk
|
|
16
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http
|
|
17
|
+
Requires-Dist: opentelemetry-instrumentation-google-genai
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# Observagent SDK
|
|
21
|
+
|
|
22
|
+
An OpenTelemetry-based observability SDK for automatically capturing Traces and Metrics from Agents
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
Install the SDK directly from PyPI
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install observagent
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
observagent/__init__.py,sha256=WVb7RVzQ64mv-4hqrMK4mQz-qcPKH8C_T_8jVkyClLI,102
|
|
2
|
+
observagent/core.py,sha256=X7gKFfBif7IMm41VJ_50B3HG9HnjlDFr_J6RykgH0UQ,4050
|
|
3
|
+
observagent-0.1.0.dist-info/licenses/LICENSE,sha256=zK1or5JeP0aAEBQU-Mcb1MfQtkcZGHLol1L71FJswMo,1061
|
|
4
|
+
observagent-0.1.0.dist-info/METADATA,sha256=GVahGw4WX11kCjkxtIRHDVkiCLy1RK4bhy_FmvawEHg,889
|
|
5
|
+
observagent-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
observagent-0.1.0.dist-info/top_level.txt,sha256=LYpvNra-bWofIxK0f6pV0cPOASeXcvTaIo2YQ5_iH40,12
|
|
7
|
+
observagent-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andre
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
observagent
|