mseep-agentops 0.4.18__py3-none-any.whl → 0.4.23__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.
- agentops/__init__.py +0 -0
- agentops/client/api/base.py +28 -30
- agentops/client/api/versions/v3.py +29 -25
- agentops/client/api/versions/v4.py +87 -46
- agentops/client/client.py +98 -29
- agentops/client/http/README.md +87 -0
- agentops/client/http/http_client.py +126 -172
- agentops/config.py +8 -2
- agentops/instrumentation/OpenTelemetry.md +133 -0
- agentops/instrumentation/README.md +167 -0
- agentops/instrumentation/__init__.py +13 -1
- agentops/instrumentation/agentic/ag2/__init__.py +18 -0
- agentops/instrumentation/agentic/ag2/instrumentor.py +922 -0
- agentops/instrumentation/agentic/agno/__init__.py +19 -0
- agentops/instrumentation/agentic/agno/attributes/__init__.py +20 -0
- agentops/instrumentation/agentic/agno/attributes/agent.py +250 -0
- agentops/instrumentation/agentic/agno/attributes/metrics.py +214 -0
- agentops/instrumentation/agentic/agno/attributes/storage.py +158 -0
- agentops/instrumentation/agentic/agno/attributes/team.py +195 -0
- agentops/instrumentation/agentic/agno/attributes/tool.py +210 -0
- agentops/instrumentation/agentic/agno/attributes/workflow.py +254 -0
- agentops/instrumentation/agentic/agno/instrumentor.py +1313 -0
- agentops/instrumentation/agentic/crewai/LICENSE +201 -0
- agentops/instrumentation/agentic/crewai/NOTICE.md +10 -0
- agentops/instrumentation/agentic/crewai/__init__.py +6 -0
- agentops/instrumentation/agentic/crewai/crewai_span_attributes.py +335 -0
- agentops/instrumentation/agentic/crewai/instrumentation.py +535 -0
- agentops/instrumentation/agentic/crewai/version.py +1 -0
- agentops/instrumentation/agentic/google_adk/__init__.py +19 -0
- agentops/instrumentation/agentic/google_adk/instrumentor.py +68 -0
- agentops/instrumentation/agentic/google_adk/patch.py +767 -0
- agentops/instrumentation/agentic/haystack/__init__.py +1 -0
- agentops/instrumentation/agentic/haystack/instrumentor.py +186 -0
- agentops/instrumentation/agentic/langgraph/__init__.py +3 -0
- agentops/instrumentation/agentic/langgraph/attributes.py +54 -0
- agentops/instrumentation/agentic/langgraph/instrumentation.py +598 -0
- agentops/instrumentation/agentic/langgraph/version.py +1 -0
- agentops/instrumentation/agentic/openai_agents/README.md +156 -0
- agentops/instrumentation/agentic/openai_agents/SPANS.md +145 -0
- agentops/instrumentation/agentic/openai_agents/TRACING_API.md +144 -0
- agentops/instrumentation/agentic/openai_agents/__init__.py +30 -0
- agentops/instrumentation/agentic/openai_agents/attributes/common.py +549 -0
- agentops/instrumentation/agentic/openai_agents/attributes/completion.py +172 -0
- agentops/instrumentation/agentic/openai_agents/attributes/model.py +58 -0
- agentops/instrumentation/agentic/openai_agents/attributes/tokens.py +275 -0
- agentops/instrumentation/agentic/openai_agents/exporter.py +469 -0
- agentops/instrumentation/agentic/openai_agents/instrumentor.py +107 -0
- agentops/instrumentation/agentic/openai_agents/processor.py +58 -0
- agentops/instrumentation/agentic/smolagents/README.md +88 -0
- agentops/instrumentation/agentic/smolagents/__init__.py +12 -0
- agentops/instrumentation/agentic/smolagents/attributes/agent.py +354 -0
- agentops/instrumentation/agentic/smolagents/attributes/model.py +205 -0
- agentops/instrumentation/agentic/smolagents/instrumentor.py +286 -0
- agentops/instrumentation/agentic/smolagents/stream_wrapper.py +258 -0
- agentops/instrumentation/agentic/xpander/__init__.py +15 -0
- agentops/instrumentation/agentic/xpander/context.py +112 -0
- agentops/instrumentation/agentic/xpander/instrumentor.py +877 -0
- agentops/instrumentation/agentic/xpander/trace_probe.py +86 -0
- agentops/instrumentation/agentic/xpander/version.py +3 -0
- agentops/instrumentation/common/README.md +65 -0
- agentops/instrumentation/common/attributes.py +1 -2
- agentops/instrumentation/providers/anthropic/__init__.py +24 -0
- agentops/instrumentation/providers/anthropic/attributes/__init__.py +23 -0
- agentops/instrumentation/providers/anthropic/attributes/common.py +64 -0
- agentops/instrumentation/providers/anthropic/attributes/message.py +541 -0
- agentops/instrumentation/providers/anthropic/attributes/tools.py +231 -0
- agentops/instrumentation/providers/anthropic/event_handler_wrapper.py +90 -0
- agentops/instrumentation/providers/anthropic/instrumentor.py +146 -0
- agentops/instrumentation/providers/anthropic/stream_wrapper.py +436 -0
- agentops/instrumentation/providers/google_genai/README.md +33 -0
- agentops/instrumentation/providers/google_genai/__init__.py +24 -0
- agentops/instrumentation/providers/google_genai/attributes/__init__.py +25 -0
- agentops/instrumentation/providers/google_genai/attributes/chat.py +125 -0
- agentops/instrumentation/providers/google_genai/attributes/common.py +88 -0
- agentops/instrumentation/providers/google_genai/attributes/model.py +284 -0
- agentops/instrumentation/providers/google_genai/instrumentor.py +170 -0
- agentops/instrumentation/providers/google_genai/stream_wrapper.py +238 -0
- agentops/instrumentation/providers/ibm_watsonx_ai/__init__.py +28 -0
- agentops/instrumentation/providers/ibm_watsonx_ai/attributes/__init__.py +27 -0
- agentops/instrumentation/providers/ibm_watsonx_ai/attributes/attributes.py +277 -0
- agentops/instrumentation/providers/ibm_watsonx_ai/attributes/common.py +104 -0
- agentops/instrumentation/providers/ibm_watsonx_ai/instrumentor.py +162 -0
- agentops/instrumentation/providers/ibm_watsonx_ai/stream_wrapper.py +302 -0
- agentops/instrumentation/providers/mem0/__init__.py +45 -0
- agentops/instrumentation/providers/mem0/common.py +377 -0
- agentops/instrumentation/providers/mem0/instrumentor.py +270 -0
- agentops/instrumentation/providers/mem0/memory.py +430 -0
- agentops/instrumentation/providers/openai/__init__.py +21 -0
- agentops/instrumentation/providers/openai/attributes/__init__.py +7 -0
- agentops/instrumentation/providers/openai/attributes/common.py +55 -0
- agentops/instrumentation/providers/openai/attributes/response.py +607 -0
- agentops/instrumentation/providers/openai/config.py +36 -0
- agentops/instrumentation/providers/openai/instrumentor.py +312 -0
- agentops/instrumentation/providers/openai/stream_wrapper.py +941 -0
- agentops/instrumentation/providers/openai/utils.py +44 -0
- agentops/instrumentation/providers/openai/v0.py +176 -0
- agentops/instrumentation/providers/openai/v0_wrappers.py +483 -0
- agentops/instrumentation/providers/openai/wrappers/__init__.py +30 -0
- agentops/instrumentation/providers/openai/wrappers/assistant.py +277 -0
- agentops/instrumentation/providers/openai/wrappers/chat.py +259 -0
- agentops/instrumentation/providers/openai/wrappers/completion.py +109 -0
- agentops/instrumentation/providers/openai/wrappers/embeddings.py +94 -0
- agentops/instrumentation/providers/openai/wrappers/image_gen.py +75 -0
- agentops/instrumentation/providers/openai/wrappers/responses.py +191 -0
- agentops/instrumentation/providers/openai/wrappers/shared.py +81 -0
- agentops/instrumentation/utilities/concurrent_futures/__init__.py +10 -0
- agentops/instrumentation/utilities/concurrent_futures/instrumentation.py +206 -0
- agentops/integration/callbacks/dspy/__init__.py +11 -0
- agentops/integration/callbacks/dspy/callback.py +471 -0
- agentops/integration/callbacks/langchain/README.md +59 -0
- agentops/integration/callbacks/langchain/__init__.py +15 -0
- agentops/integration/callbacks/langchain/callback.py +791 -0
- agentops/integration/callbacks/langchain/utils.py +54 -0
- agentops/legacy/crewai.md +121 -0
- agentops/logging/instrument_logging.py +4 -0
- agentops/sdk/README.md +220 -0
- agentops/sdk/core.py +75 -32
- agentops/sdk/descriptors/classproperty.py +28 -0
- agentops/sdk/exporters.py +152 -33
- agentops/semconv/README.md +125 -0
- agentops/semconv/span_kinds.py +0 -2
- agentops/validation.py +102 -63
- {mseep_agentops-0.4.18.dist-info → mseep_agentops-0.4.23.dist-info}/METADATA +30 -40
- mseep_agentops-0.4.23.dist-info/RECORD +178 -0
- {mseep_agentops-0.4.18.dist-info → mseep_agentops-0.4.23.dist-info}/WHEEL +1 -2
- mseep_agentops-0.4.18.dist-info/RECORD +0 -94
- mseep_agentops-0.4.18.dist-info/top_level.txt +0 -2
- tests/conftest.py +0 -10
- tests/unit/client/__init__.py +0 -1
- tests/unit/client/test_http_adapter.py +0 -221
- tests/unit/client/test_http_client.py +0 -206
- tests/unit/conftest.py +0 -54
- tests/unit/sdk/__init__.py +0 -1
- tests/unit/sdk/instrumentation_tester.py +0 -207
- tests/unit/sdk/test_attributes.py +0 -392
- tests/unit/sdk/test_concurrent_instrumentation.py +0 -468
- tests/unit/sdk/test_decorators.py +0 -763
- tests/unit/sdk/test_exporters.py +0 -241
- tests/unit/sdk/test_factory.py +0 -1188
- tests/unit/sdk/test_internal_span_processor.py +0 -397
- tests/unit/sdk/test_resource_attributes.py +0 -35
- tests/unit/test_config.py +0 -82
- tests/unit/test_context_manager.py +0 -777
- tests/unit/test_events.py +0 -27
- tests/unit/test_host_env.py +0 -54
- tests/unit/test_init_py.py +0 -501
- tests/unit/test_serialization.py +0 -433
- tests/unit/test_session.py +0 -676
- tests/unit/test_user_agent.py +0 -34
- tests/unit/test_validation.py +0 -405
- {tests → agentops/instrumentation/agentic/openai_agents/attributes}/__init__.py +0 -0
- /tests/unit/__init__.py → /agentops/instrumentation/providers/openai/attributes/tools.py +0 -0
- {mseep_agentops-0.4.18.dist-info → mseep_agentops-0.4.23.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
"""Utilities for OpenAI instrumentation.
|
2
|
+
|
3
|
+
This module provides utility functions used across the OpenAI instrumentation
|
4
|
+
components.
|
5
|
+
"""
|
6
|
+
|
7
|
+
import os
|
8
|
+
from importlib.metadata import version
|
9
|
+
|
10
|
+
from agentops.instrumentation.providers.openai.config import Config
|
11
|
+
|
12
|
+
# Get OpenAI version
|
13
|
+
try:
|
14
|
+
_OPENAI_VERSION = version("openai")
|
15
|
+
except Exception:
|
16
|
+
_OPENAI_VERSION = "0.0.0"
|
17
|
+
|
18
|
+
|
19
|
+
def is_openai_v1() -> bool:
|
20
|
+
"""Check if the installed OpenAI version is v1 or later."""
|
21
|
+
return _OPENAI_VERSION >= "1.0.0"
|
22
|
+
|
23
|
+
|
24
|
+
def is_azure_openai(instance) -> bool:
|
25
|
+
"""Check if the instance is using Azure OpenAI."""
|
26
|
+
if not is_openai_v1():
|
27
|
+
return False
|
28
|
+
|
29
|
+
try:
|
30
|
+
import openai
|
31
|
+
|
32
|
+
return isinstance(instance._client, (openai.AsyncAzureOpenAI, openai.AzureOpenAI))
|
33
|
+
except Exception:
|
34
|
+
return False
|
35
|
+
|
36
|
+
|
37
|
+
def is_metrics_enabled() -> bool:
|
38
|
+
"""Check if metrics collection is enabled."""
|
39
|
+
return (os.getenv("TRACELOOP_METRICS_ENABLED") or "true").lower() == "true"
|
40
|
+
|
41
|
+
|
42
|
+
def should_record_stream_token_usage() -> bool:
|
43
|
+
"""Check if stream token usage should be recorded."""
|
44
|
+
return Config.enrich_token_usage
|
@@ -0,0 +1,176 @@
|
|
1
|
+
"""OpenAI v0 API Instrumentation for AgentOps
|
2
|
+
|
3
|
+
This module provides instrumentation for OpenAI API v0 (before v1.0.0).
|
4
|
+
It's kept for backward compatibility.
|
5
|
+
"""
|
6
|
+
|
7
|
+
from typing import Collection
|
8
|
+
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
9
|
+
from opentelemetry.trace import get_tracer
|
10
|
+
from opentelemetry.metrics import get_meter
|
11
|
+
from wrapt import wrap_function_wrapper
|
12
|
+
|
13
|
+
from agentops.instrumentation.providers.openai import LIBRARY_NAME, LIBRARY_VERSION
|
14
|
+
from agentops.instrumentation.providers.openai.utils import is_metrics_enabled
|
15
|
+
from agentops.semconv import Meters
|
16
|
+
|
17
|
+
# Import our wrappers
|
18
|
+
from agentops.instrumentation.providers.openai.v0_wrappers import (
|
19
|
+
chat_wrapper,
|
20
|
+
achat_wrapper,
|
21
|
+
completion_wrapper,
|
22
|
+
acompletion_wrapper,
|
23
|
+
embeddings_wrapper,
|
24
|
+
aembeddings_wrapper,
|
25
|
+
)
|
26
|
+
|
27
|
+
_instruments = ("openai >= 0.27.0", "openai < 1.0.0")
|
28
|
+
|
29
|
+
|
30
|
+
class OpenAIV0Instrumentor(BaseInstrumentor):
|
31
|
+
"""An instrumentor for OpenAI API v0."""
|
32
|
+
|
33
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
34
|
+
return _instruments
|
35
|
+
|
36
|
+
def _instrument(self, **kwargs):
|
37
|
+
"""Instrument the OpenAI API v0."""
|
38
|
+
tracer_provider = kwargs.get("tracer_provider")
|
39
|
+
tracer = get_tracer(LIBRARY_NAME, LIBRARY_VERSION, tracer_provider)
|
40
|
+
|
41
|
+
meter_provider = kwargs.get("meter_provider")
|
42
|
+
meter = get_meter(LIBRARY_NAME, LIBRARY_VERSION, meter_provider)
|
43
|
+
|
44
|
+
# Initialize metrics if enabled
|
45
|
+
if is_metrics_enabled():
|
46
|
+
tokens_histogram = meter.create_histogram(
|
47
|
+
name=Meters.LLM_TOKEN_USAGE,
|
48
|
+
unit="token",
|
49
|
+
description="Measures number of input and output tokens used",
|
50
|
+
)
|
51
|
+
|
52
|
+
chat_choice_counter = meter.create_counter(
|
53
|
+
name=Meters.LLM_GENERATION_CHOICES,
|
54
|
+
unit="choice",
|
55
|
+
description="Number of choices returned by chat completions call",
|
56
|
+
)
|
57
|
+
|
58
|
+
duration_histogram = meter.create_histogram(
|
59
|
+
name=Meters.LLM_OPERATION_DURATION,
|
60
|
+
unit="s",
|
61
|
+
description="GenAI operation duration",
|
62
|
+
)
|
63
|
+
|
64
|
+
chat_exception_counter = meter.create_counter(
|
65
|
+
name=Meters.LLM_COMPLETIONS_EXCEPTIONS,
|
66
|
+
unit="time",
|
67
|
+
description="Number of exceptions occurred during chat completions",
|
68
|
+
)
|
69
|
+
|
70
|
+
streaming_time_to_first_token = meter.create_histogram(
|
71
|
+
name=Meters.LLM_STREAMING_TIME_TO_FIRST_TOKEN,
|
72
|
+
unit="s",
|
73
|
+
description="Time to first token in streaming chat completions",
|
74
|
+
)
|
75
|
+
|
76
|
+
streaming_time_to_generate = meter.create_histogram(
|
77
|
+
name=Meters.LLM_STREAMING_TIME_TO_GENERATE,
|
78
|
+
unit="s",
|
79
|
+
description="Time between first token and completion in streaming chat completions",
|
80
|
+
)
|
81
|
+
|
82
|
+
embeddings_vector_size_counter = meter.create_counter(
|
83
|
+
name=Meters.LLM_EMBEDDINGS_VECTOR_SIZE,
|
84
|
+
unit="element",
|
85
|
+
description="The size of returned vector",
|
86
|
+
)
|
87
|
+
|
88
|
+
embeddings_exception_counter = meter.create_counter(
|
89
|
+
name=Meters.LLM_EMBEDDINGS_EXCEPTIONS,
|
90
|
+
unit="time",
|
91
|
+
description="Number of exceptions occurred during embeddings operation",
|
92
|
+
)
|
93
|
+
else:
|
94
|
+
(
|
95
|
+
tokens_histogram,
|
96
|
+
chat_choice_counter,
|
97
|
+
duration_histogram,
|
98
|
+
chat_exception_counter,
|
99
|
+
streaming_time_to_first_token,
|
100
|
+
streaming_time_to_generate,
|
101
|
+
embeddings_vector_size_counter,
|
102
|
+
embeddings_exception_counter,
|
103
|
+
) = (None, None, None, None, None, None, None, None)
|
104
|
+
|
105
|
+
# Wrap Completion methods
|
106
|
+
wrap_function_wrapper("openai", "Completion.create", completion_wrapper(tracer))
|
107
|
+
wrap_function_wrapper("openai", "Completion.acreate", acompletion_wrapper(tracer))
|
108
|
+
|
109
|
+
# Wrap ChatCompletion methods
|
110
|
+
wrap_function_wrapper(
|
111
|
+
"openai",
|
112
|
+
"ChatCompletion.create",
|
113
|
+
chat_wrapper(
|
114
|
+
tracer,
|
115
|
+
tokens_histogram,
|
116
|
+
chat_choice_counter,
|
117
|
+
duration_histogram,
|
118
|
+
chat_exception_counter,
|
119
|
+
streaming_time_to_first_token,
|
120
|
+
streaming_time_to_generate,
|
121
|
+
),
|
122
|
+
)
|
123
|
+
wrap_function_wrapper(
|
124
|
+
"openai",
|
125
|
+
"ChatCompletion.acreate",
|
126
|
+
achat_wrapper(
|
127
|
+
tracer,
|
128
|
+
tokens_histogram,
|
129
|
+
chat_choice_counter,
|
130
|
+
duration_histogram,
|
131
|
+
chat_exception_counter,
|
132
|
+
streaming_time_to_first_token,
|
133
|
+
streaming_time_to_generate,
|
134
|
+
),
|
135
|
+
)
|
136
|
+
|
137
|
+
# Wrap Embedding methods
|
138
|
+
wrap_function_wrapper(
|
139
|
+
"openai",
|
140
|
+
"Embedding.create",
|
141
|
+
embeddings_wrapper(
|
142
|
+
tracer,
|
143
|
+
tokens_histogram,
|
144
|
+
embeddings_vector_size_counter,
|
145
|
+
duration_histogram,
|
146
|
+
embeddings_exception_counter,
|
147
|
+
),
|
148
|
+
)
|
149
|
+
wrap_function_wrapper(
|
150
|
+
"openai",
|
151
|
+
"Embedding.acreate",
|
152
|
+
aembeddings_wrapper(
|
153
|
+
tracer,
|
154
|
+
tokens_histogram,
|
155
|
+
embeddings_vector_size_counter,
|
156
|
+
duration_histogram,
|
157
|
+
embeddings_exception_counter,
|
158
|
+
),
|
159
|
+
)
|
160
|
+
|
161
|
+
def _uninstrument(self, **kwargs):
|
162
|
+
"""Remove instrumentation from OpenAI API v0."""
|
163
|
+
# Unwrap all the methods
|
164
|
+
from opentelemetry.instrumentation.utils import unwrap
|
165
|
+
|
166
|
+
# Unwrap Completion methods
|
167
|
+
unwrap("openai.Completion", "create")
|
168
|
+
unwrap("openai.Completion", "acreate")
|
169
|
+
|
170
|
+
# Unwrap ChatCompletion methods
|
171
|
+
unwrap("openai.ChatCompletion", "create")
|
172
|
+
unwrap("openai.ChatCompletion", "acreate")
|
173
|
+
|
174
|
+
# Unwrap Embedding methods
|
175
|
+
unwrap("openai.Embedding", "create")
|
176
|
+
unwrap("openai.Embedding", "acreate")
|