mseep-agentops 0.4.18__py3-none-any.whl → 0.4.22__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.
Files changed (153) hide show
  1. agentops/__init__.py +0 -0
  2. agentops/client/api/base.py +28 -30
  3. agentops/client/api/versions/v3.py +29 -25
  4. agentops/client/api/versions/v4.py +87 -46
  5. agentops/client/client.py +98 -29
  6. agentops/client/http/README.md +87 -0
  7. agentops/client/http/http_client.py +126 -172
  8. agentops/config.py +8 -2
  9. agentops/instrumentation/OpenTelemetry.md +133 -0
  10. agentops/instrumentation/README.md +167 -0
  11. agentops/instrumentation/__init__.py +13 -1
  12. agentops/instrumentation/agentic/ag2/__init__.py +18 -0
  13. agentops/instrumentation/agentic/ag2/instrumentor.py +922 -0
  14. agentops/instrumentation/agentic/agno/__init__.py +19 -0
  15. agentops/instrumentation/agentic/agno/attributes/__init__.py +20 -0
  16. agentops/instrumentation/agentic/agno/attributes/agent.py +250 -0
  17. agentops/instrumentation/agentic/agno/attributes/metrics.py +214 -0
  18. agentops/instrumentation/agentic/agno/attributes/storage.py +158 -0
  19. agentops/instrumentation/agentic/agno/attributes/team.py +195 -0
  20. agentops/instrumentation/agentic/agno/attributes/tool.py +210 -0
  21. agentops/instrumentation/agentic/agno/attributes/workflow.py +254 -0
  22. agentops/instrumentation/agentic/agno/instrumentor.py +1313 -0
  23. agentops/instrumentation/agentic/crewai/LICENSE +201 -0
  24. agentops/instrumentation/agentic/crewai/NOTICE.md +10 -0
  25. agentops/instrumentation/agentic/crewai/__init__.py +6 -0
  26. agentops/instrumentation/agentic/crewai/crewai_span_attributes.py +335 -0
  27. agentops/instrumentation/agentic/crewai/instrumentation.py +535 -0
  28. agentops/instrumentation/agentic/crewai/version.py +1 -0
  29. agentops/instrumentation/agentic/google_adk/__init__.py +19 -0
  30. agentops/instrumentation/agentic/google_adk/instrumentor.py +68 -0
  31. agentops/instrumentation/agentic/google_adk/patch.py +767 -0
  32. agentops/instrumentation/agentic/haystack/__init__.py +1 -0
  33. agentops/instrumentation/agentic/haystack/instrumentor.py +186 -0
  34. agentops/instrumentation/agentic/langgraph/__init__.py +3 -0
  35. agentops/instrumentation/agentic/langgraph/attributes.py +54 -0
  36. agentops/instrumentation/agentic/langgraph/instrumentation.py +598 -0
  37. agentops/instrumentation/agentic/langgraph/version.py +1 -0
  38. agentops/instrumentation/agentic/openai_agents/README.md +156 -0
  39. agentops/instrumentation/agentic/openai_agents/SPANS.md +145 -0
  40. agentops/instrumentation/agentic/openai_agents/TRACING_API.md +144 -0
  41. agentops/instrumentation/agentic/openai_agents/__init__.py +30 -0
  42. agentops/instrumentation/agentic/openai_agents/attributes/common.py +549 -0
  43. agentops/instrumentation/agentic/openai_agents/attributes/completion.py +172 -0
  44. agentops/instrumentation/agentic/openai_agents/attributes/model.py +58 -0
  45. agentops/instrumentation/agentic/openai_agents/attributes/tokens.py +275 -0
  46. agentops/instrumentation/agentic/openai_agents/exporter.py +469 -0
  47. agentops/instrumentation/agentic/openai_agents/instrumentor.py +107 -0
  48. agentops/instrumentation/agentic/openai_agents/processor.py +58 -0
  49. agentops/instrumentation/agentic/smolagents/README.md +88 -0
  50. agentops/instrumentation/agentic/smolagents/__init__.py +12 -0
  51. agentops/instrumentation/agentic/smolagents/attributes/agent.py +354 -0
  52. agentops/instrumentation/agentic/smolagents/attributes/model.py +205 -0
  53. agentops/instrumentation/agentic/smolagents/instrumentor.py +286 -0
  54. agentops/instrumentation/agentic/smolagents/stream_wrapper.py +258 -0
  55. agentops/instrumentation/agentic/xpander/__init__.py +15 -0
  56. agentops/instrumentation/agentic/xpander/context.py +112 -0
  57. agentops/instrumentation/agentic/xpander/instrumentor.py +877 -0
  58. agentops/instrumentation/agentic/xpander/trace_probe.py +86 -0
  59. agentops/instrumentation/agentic/xpander/version.py +3 -0
  60. agentops/instrumentation/common/README.md +65 -0
  61. agentops/instrumentation/common/attributes.py +1 -2
  62. agentops/instrumentation/providers/anthropic/__init__.py +24 -0
  63. agentops/instrumentation/providers/anthropic/attributes/__init__.py +23 -0
  64. agentops/instrumentation/providers/anthropic/attributes/common.py +64 -0
  65. agentops/instrumentation/providers/anthropic/attributes/message.py +541 -0
  66. agentops/instrumentation/providers/anthropic/attributes/tools.py +231 -0
  67. agentops/instrumentation/providers/anthropic/event_handler_wrapper.py +90 -0
  68. agentops/instrumentation/providers/anthropic/instrumentor.py +146 -0
  69. agentops/instrumentation/providers/anthropic/stream_wrapper.py +436 -0
  70. agentops/instrumentation/providers/google_genai/README.md +33 -0
  71. agentops/instrumentation/providers/google_genai/__init__.py +24 -0
  72. agentops/instrumentation/providers/google_genai/attributes/__init__.py +25 -0
  73. agentops/instrumentation/providers/google_genai/attributes/chat.py +125 -0
  74. agentops/instrumentation/providers/google_genai/attributes/common.py +88 -0
  75. agentops/instrumentation/providers/google_genai/attributes/model.py +284 -0
  76. agentops/instrumentation/providers/google_genai/instrumentor.py +170 -0
  77. agentops/instrumentation/providers/google_genai/stream_wrapper.py +238 -0
  78. agentops/instrumentation/providers/ibm_watsonx_ai/__init__.py +28 -0
  79. agentops/instrumentation/providers/ibm_watsonx_ai/attributes/__init__.py +27 -0
  80. agentops/instrumentation/providers/ibm_watsonx_ai/attributes/attributes.py +277 -0
  81. agentops/instrumentation/providers/ibm_watsonx_ai/attributes/common.py +104 -0
  82. agentops/instrumentation/providers/ibm_watsonx_ai/instrumentor.py +162 -0
  83. agentops/instrumentation/providers/ibm_watsonx_ai/stream_wrapper.py +302 -0
  84. agentops/instrumentation/providers/mem0/__init__.py +45 -0
  85. agentops/instrumentation/providers/mem0/common.py +377 -0
  86. agentops/instrumentation/providers/mem0/instrumentor.py +270 -0
  87. agentops/instrumentation/providers/mem0/memory.py +430 -0
  88. agentops/instrumentation/providers/openai/__init__.py +21 -0
  89. agentops/instrumentation/providers/openai/attributes/__init__.py +7 -0
  90. agentops/instrumentation/providers/openai/attributes/common.py +55 -0
  91. agentops/instrumentation/providers/openai/attributes/response.py +607 -0
  92. agentops/instrumentation/providers/openai/config.py +36 -0
  93. agentops/instrumentation/providers/openai/instrumentor.py +312 -0
  94. agentops/instrumentation/providers/openai/stream_wrapper.py +941 -0
  95. agentops/instrumentation/providers/openai/utils.py +44 -0
  96. agentops/instrumentation/providers/openai/v0.py +176 -0
  97. agentops/instrumentation/providers/openai/v0_wrappers.py +483 -0
  98. agentops/instrumentation/providers/openai/wrappers/__init__.py +30 -0
  99. agentops/instrumentation/providers/openai/wrappers/assistant.py +277 -0
  100. agentops/instrumentation/providers/openai/wrappers/chat.py +259 -0
  101. agentops/instrumentation/providers/openai/wrappers/completion.py +109 -0
  102. agentops/instrumentation/providers/openai/wrappers/embeddings.py +94 -0
  103. agentops/instrumentation/providers/openai/wrappers/image_gen.py +75 -0
  104. agentops/instrumentation/providers/openai/wrappers/responses.py +191 -0
  105. agentops/instrumentation/providers/openai/wrappers/shared.py +81 -0
  106. agentops/instrumentation/utilities/concurrent_futures/__init__.py +10 -0
  107. agentops/instrumentation/utilities/concurrent_futures/instrumentation.py +206 -0
  108. agentops/integration/callbacks/dspy/__init__.py +11 -0
  109. agentops/integration/callbacks/dspy/callback.py +471 -0
  110. agentops/integration/callbacks/langchain/README.md +59 -0
  111. agentops/integration/callbacks/langchain/__init__.py +15 -0
  112. agentops/integration/callbacks/langchain/callback.py +791 -0
  113. agentops/integration/callbacks/langchain/utils.py +54 -0
  114. agentops/legacy/crewai.md +121 -0
  115. agentops/logging/instrument_logging.py +4 -0
  116. agentops/sdk/README.md +220 -0
  117. agentops/sdk/core.py +75 -32
  118. agentops/sdk/descriptors/classproperty.py +28 -0
  119. agentops/sdk/exporters.py +152 -33
  120. agentops/semconv/README.md +125 -0
  121. agentops/semconv/span_kinds.py +0 -2
  122. agentops/validation.py +102 -63
  123. {mseep_agentops-0.4.18.dist-info → mseep_agentops-0.4.22.dist-info}/METADATA +30 -40
  124. mseep_agentops-0.4.22.dist-info/RECORD +178 -0
  125. {mseep_agentops-0.4.18.dist-info → mseep_agentops-0.4.22.dist-info}/WHEEL +1 -2
  126. mseep_agentops-0.4.18.dist-info/RECORD +0 -94
  127. mseep_agentops-0.4.18.dist-info/top_level.txt +0 -2
  128. tests/conftest.py +0 -10
  129. tests/unit/client/__init__.py +0 -1
  130. tests/unit/client/test_http_adapter.py +0 -221
  131. tests/unit/client/test_http_client.py +0 -206
  132. tests/unit/conftest.py +0 -54
  133. tests/unit/sdk/__init__.py +0 -1
  134. tests/unit/sdk/instrumentation_tester.py +0 -207
  135. tests/unit/sdk/test_attributes.py +0 -392
  136. tests/unit/sdk/test_concurrent_instrumentation.py +0 -468
  137. tests/unit/sdk/test_decorators.py +0 -763
  138. tests/unit/sdk/test_exporters.py +0 -241
  139. tests/unit/sdk/test_factory.py +0 -1188
  140. tests/unit/sdk/test_internal_span_processor.py +0 -397
  141. tests/unit/sdk/test_resource_attributes.py +0 -35
  142. tests/unit/test_config.py +0 -82
  143. tests/unit/test_context_manager.py +0 -777
  144. tests/unit/test_events.py +0 -27
  145. tests/unit/test_host_env.py +0 -54
  146. tests/unit/test_init_py.py +0 -501
  147. tests/unit/test_serialization.py +0 -433
  148. tests/unit/test_session.py +0 -676
  149. tests/unit/test_user_agent.py +0 -34
  150. tests/unit/test_validation.py +0 -405
  151. {tests → agentops/instrumentation/agentic/openai_agents/attributes}/__init__.py +0 -0
  152. /tests/unit/__init__.py → /agentops/instrumentation/providers/openai/attributes/tools.py +0 -0
  153. {mseep_agentops-0.4.18.dist-info → mseep_agentops-0.4.22.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")