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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 openllmetry
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,10 @@
1
+ This package contains code derived from the OpenLLMetry project, which is licensed under the Apache License, Version 2.0.
2
+
3
+ Original repository: https://github.com/traceloop/openllmetry
4
+
5
+ Copyright notice from the original project:
6
+ Copyright (c) Traceloop (https://traceloop.com)
7
+
8
+ The Apache 2.0 license can be found in the LICENSE file in this directory.
9
+
10
+ This code has been modified and adapted for use in the AgentOps project.
@@ -0,0 +1,6 @@
1
+ """OpenTelemetry CrewAI instrumentation"""
2
+
3
+ from agentops.instrumentation.agentic.crewai.version import __version__
4
+ from agentops.instrumentation.agentic.crewai.instrumentation import CrewaiInstrumentor
5
+
6
+ __all__ = ["CrewaiInstrumentor", "__version__"]
@@ -0,0 +1,335 @@
1
+ """OpenTelemetry instrumentation for CrewAI."""
2
+
3
+ import json
4
+ import logging
5
+ from typing import Any
6
+ from opentelemetry.trace import Span
7
+
8
+ from agentops.semconv.span_attributes import SpanAttributes
9
+ from agentops.semconv.agent import AgentAttributes
10
+ from agentops.semconv.message import MessageAttributes
11
+
12
+ # Initialize logger for logging potential issues and operations
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ def _parse_tools(tools):
17
+ """Parse tools into a JSON string with name and description."""
18
+ result = []
19
+ for tool in tools:
20
+ res = {}
21
+ if hasattr(tool, "name") and tool.name is not None:
22
+ res["name"] = tool.name
23
+ if hasattr(tool, "description") and tool.description is not None:
24
+ res["description"] = tool.description
25
+ if res:
26
+ result.append(res)
27
+ return result
28
+
29
+
30
+ def set_span_attribute(span: Span, key: str, value: Any) -> None:
31
+ """Set a single attribute on a span."""
32
+ if value is not None and value != "":
33
+ if hasattr(value, "__str__"):
34
+ value = str(value)
35
+ span.set_attribute(key, value)
36
+
37
+
38
+ class CrewAISpanAttributes:
39
+ """Manages span attributes for CrewAI instrumentation."""
40
+
41
+ def __init__(self, span: Span, instance, skip_agent_processing=False) -> None:
42
+ self.span = span
43
+ self.instance = instance
44
+ self.skip_agent_processing = skip_agent_processing
45
+ self.process_instance()
46
+
47
+ def process_instance(self):
48
+ """Process the instance based on its type."""
49
+ instance_type = self.instance.__class__.__name__
50
+ self._set_attribute(SpanAttributes.LLM_SYSTEM, "crewai")
51
+ self._set_attribute(SpanAttributes.AGENTOPS_ENTITY_NAME, instance_type)
52
+
53
+ method_mapping = {
54
+ "Crew": self._process_crew,
55
+ "Agent": self._process_agent,
56
+ "Task": self._process_task,
57
+ "LLM": self._process_llm,
58
+ }
59
+ method = method_mapping.get(instance_type)
60
+ if method:
61
+ method()
62
+
63
+ def _process_crew(self):
64
+ """Process a Crew instance."""
65
+ crew_id = getattr(self.instance, "id", "")
66
+ self._set_attribute("crewai.crew.id", str(crew_id))
67
+ self._set_attribute("crewai.crew.type", "crewai.crew")
68
+ self._set_attribute(SpanAttributes.AGENTOPS_SPAN_KIND, "workflow")
69
+
70
+ logger.debug(f"CrewAI: Processing crew with id {crew_id}")
71
+
72
+ for key, value in self.instance.__dict__.items():
73
+ if value is None:
74
+ continue
75
+
76
+ if key == "tasks":
77
+ if isinstance(value, list):
78
+ self._set_attribute("crewai.crew.max_turns", str(len(value)))
79
+ logger.debug(f"CrewAI: Found {len(value)} tasks")
80
+ elif key == "agents":
81
+ if isinstance(value, list):
82
+ logger.debug(f"CrewAI: Found {len(value)} agents in crew")
83
+
84
+ if not self.skip_agent_processing:
85
+ self._parse_agents(value)
86
+ elif key == "llms":
87
+ self._parse_llms(value)
88
+ elif key == "result":
89
+ self._set_attribute("crewai.crew.final_output", str(value))
90
+ self._set_attribute("crewai.crew.output", str(value))
91
+ self._set_attribute(SpanAttributes.AGENTOPS_ENTITY_OUTPUT, str(value))
92
+ else:
93
+ self._set_attribute(f"crewai.crew.{key}", str(value))
94
+
95
+ def _process_agent(self):
96
+ """Process an Agent instance."""
97
+ agent = {}
98
+ self._set_attribute(SpanAttributes.AGENTOPS_SPAN_KIND, "agent")
99
+
100
+ for key, value in self.instance.__dict__.items():
101
+ if key == "tools":
102
+ parsed_tools = _parse_tools(value)
103
+ for i, tool in enumerate(parsed_tools):
104
+ tool_prefix = f"crewai.agent.tool.{i}."
105
+ for tool_key, tool_value in tool.items():
106
+ self._set_attribute(f"{tool_prefix}{tool_key}", str(tool_value))
107
+
108
+ agent[key] = json.dumps(parsed_tools)
109
+
110
+ if value is None:
111
+ continue
112
+
113
+ if key != "tools":
114
+ agent[key] = str(value)
115
+
116
+ self._set_attribute(AgentAttributes.AGENT_ID, agent.get("id", ""))
117
+ self._set_attribute(AgentAttributes.AGENT_ROLE, agent.get("role", ""))
118
+ self._set_attribute(AgentAttributes.AGENT_NAME, agent.get("name", ""))
119
+ self._set_attribute(AgentAttributes.AGENT_TOOLS, agent.get("tools", ""))
120
+
121
+ if "reasoning" in agent:
122
+ self._set_attribute(AgentAttributes.AGENT_REASONING, agent.get("reasoning", ""))
123
+
124
+ if "goal" in agent:
125
+ self._set_attribute(SpanAttributes.AGENTOPS_ENTITY_INPUT, agent.get("goal", ""))
126
+
127
+ self._set_attribute("crewai.agent.goal", agent.get("goal", ""))
128
+ self._set_attribute("crewai.agent.backstory", agent.get("backstory", ""))
129
+ self._set_attribute("crewai.agent.cache", agent.get("cache", ""))
130
+ self._set_attribute("crewai.agent.allow_delegation", agent.get("allow_delegation", ""))
131
+ self._set_attribute("crewai.agent.allow_code_execution", agent.get("allow_code_execution", ""))
132
+ self._set_attribute("crewai.agent.max_retry_limit", agent.get("max_retry_limit", ""))
133
+
134
+ if hasattr(self.instance, "llm") and self.instance.llm is not None:
135
+ model_name = (
136
+ getattr(self.instance.llm, "model", None) or getattr(self.instance.llm, "model_name", None) or ""
137
+ )
138
+ temp = getattr(self.instance.llm, "temperature", None)
139
+ max_tokens = getattr(self.instance.llm, "max_tokens", None)
140
+ top_p = getattr(self.instance.llm, "top_p", None)
141
+
142
+ self._set_attribute(SpanAttributes.LLM_REQUEST_MODEL, model_name)
143
+ if temp is not None:
144
+ self._set_attribute(SpanAttributes.LLM_REQUEST_TEMPERATURE, str(temp))
145
+ if max_tokens is not None:
146
+ self._set_attribute(SpanAttributes.LLM_REQUEST_MAX_TOKENS, str(max_tokens))
147
+ if top_p is not None:
148
+ self._set_attribute(SpanAttributes.LLM_REQUEST_TOP_P, str(top_p))
149
+
150
+ self._set_attribute("crewai.agent.llm", str(model_name))
151
+ self._set_attribute(AgentAttributes.AGENT_MODELS, str(model_name))
152
+
153
+ def _process_task(self):
154
+ """Process a Task instance."""
155
+ task = {}
156
+ self._set_attribute(SpanAttributes.AGENTOPS_SPAN_KIND, "workflow.step")
157
+
158
+ for key, value in self.instance.__dict__.items():
159
+ if value is None:
160
+ continue
161
+ if key == "tools":
162
+ parsed_tools = _parse_tools(value)
163
+ for i, tool in enumerate(parsed_tools):
164
+ tool_prefix = f"crewai.task.tool.{i}."
165
+ for tool_key, tool_value in tool.items():
166
+ self._set_attribute(f"{tool_prefix}{tool_key}", str(tool_value))
167
+
168
+ task[key] = json.dumps(parsed_tools)
169
+
170
+ elif key == "agent":
171
+ task[key] = value.role if value else None
172
+ if value:
173
+ agent_id = getattr(value, "id", "")
174
+ self._set_attribute(AgentAttributes.FROM_AGENT, str(agent_id))
175
+ else:
176
+ task[key] = str(value)
177
+
178
+ self._set_attribute("crewai.task.name", task.get("description", ""))
179
+ self._set_attribute("crewai.task.type", "task")
180
+ self._set_attribute("crewai.task.input", task.get("context", ""))
181
+ self._set_attribute("crewai.task.expected_output", task.get("expected_output", ""))
182
+
183
+ if "description" in task:
184
+ self._set_attribute(SpanAttributes.AGENTOPS_ENTITY_INPUT, task.get("description", ""))
185
+ if "output" in task:
186
+ self._set_attribute(SpanAttributes.AGENTOPS_ENTITY_OUTPUT, task.get("output", ""))
187
+ self._set_attribute("crewai.task.output", task.get("output", ""))
188
+
189
+ if "id" in task:
190
+ self._set_attribute("crewai.task.id", str(task.get("id", "")))
191
+
192
+ if "status" in task:
193
+ self._set_attribute("crewai.task.status", task.get("status", ""))
194
+
195
+ self._set_attribute("crewai.task.agent", task.get("agent", ""))
196
+ self._set_attribute("crewai.task.human_input", task.get("human_input", ""))
197
+ self._set_attribute("crewai.task.processed_by_agents", str(task.get("processed_by_agents", "")))
198
+
199
+ if "tools" in task and task["tools"]:
200
+ try:
201
+ tools = json.loads(task["tools"])
202
+ for i, tool in enumerate(tools):
203
+ self._set_attribute(MessageAttributes.TOOL_CALL_NAME.format(i=i), tool.get("name", ""))
204
+ self._set_attribute(
205
+ MessageAttributes.TOOL_CALL_DESCRIPTION.format(i=i), tool.get("description", "")
206
+ )
207
+ except (json.JSONDecodeError, TypeError):
208
+ logger.warning(f"Failed to parse tools for task: {task.get('id', 'unknown')}")
209
+
210
+ def _process_llm(self):
211
+ """Process an LLM instance."""
212
+ llm = {}
213
+ self._set_attribute(SpanAttributes.AGENTOPS_SPAN_KIND, "llm")
214
+
215
+ for key, value in self.instance.__dict__.items():
216
+ if value is None:
217
+ continue
218
+ llm[key] = str(value)
219
+
220
+ model_name = llm.get("model_name", "") or llm.get("model", "")
221
+ self._set_attribute(SpanAttributes.LLM_REQUEST_MODEL, model_name)
222
+ self._set_attribute(SpanAttributes.LLM_REQUEST_TEMPERATURE, llm.get("temperature", ""))
223
+ self._set_attribute(SpanAttributes.LLM_REQUEST_MAX_TOKENS, llm.get("max_tokens", ""))
224
+ self._set_attribute(SpanAttributes.LLM_REQUEST_TOP_P, llm.get("top_p", ""))
225
+
226
+ if "frequency_penalty" in llm:
227
+ self._set_attribute(SpanAttributes.LLM_REQUEST_FREQUENCY_PENALTY, llm.get("frequency_penalty", ""))
228
+ if "presence_penalty" in llm:
229
+ self._set_attribute(SpanAttributes.LLM_REQUEST_PRESENCE_PENALTY, llm.get("presence_penalty", ""))
230
+ if "streaming" in llm:
231
+ self._set_attribute(SpanAttributes.LLM_REQUEST_STREAMING, llm.get("streaming", ""))
232
+
233
+ if "api_key" in llm:
234
+ self._set_attribute("gen_ai.request.api_key_present", "true")
235
+
236
+ if "base_url" in llm:
237
+ self._set_attribute(SpanAttributes.LLM_OPENAI_API_BASE, llm.get("base_url", ""))
238
+
239
+ if "api_version" in llm:
240
+ self._set_attribute(SpanAttributes.LLM_OPENAI_API_VERSION, llm.get("api_version", ""))
241
+
242
+ def _parse_agents(self, agents):
243
+ """Parse agents into a list of dictionaries."""
244
+ if not agents:
245
+ logger.debug("CrewAI: No agents to parse")
246
+ return
247
+
248
+ agent_count = len(agents)
249
+ logger.debug(f"CrewAI: Parsing {agent_count} agents")
250
+
251
+ # Pre-process all agents to collect their data first
252
+ agent_data_list = []
253
+
254
+ for idx, agent in enumerate(agents):
255
+ if agent is None:
256
+ logger.debug(f"CrewAI: Agent at index {idx} is None, skipping")
257
+ agent_data_list.append(None)
258
+ continue
259
+
260
+ logger.debug(f"CrewAI: Processing agent at index {idx}")
261
+ try:
262
+ agent_data = self._extract_agent_data(agent)
263
+ agent_data_list.append(agent_data)
264
+ except Exception as e:
265
+ logger.error(f"CrewAI: Error extracting data for agent at index {idx}: {str(e)}")
266
+ agent_data_list.append(None)
267
+
268
+ # Now set all attributes at once for each agent
269
+ for idx, agent_data in enumerate(agent_data_list):
270
+ if agent_data is None:
271
+ continue
272
+
273
+ for key, value in agent_data.items():
274
+ if key == "tools" and isinstance(value, list):
275
+ for tool_idx, tool in enumerate(value):
276
+ for tool_key, tool_value in tool.items():
277
+ self._set_attribute(f"crewai.agents.{idx}.tools.{tool_idx}.{tool_key}", str(tool_value))
278
+ else:
279
+ self._set_attribute(f"crewai.agents.{idx}.{key}", value)
280
+
281
+ def _parse_llms(self, llms):
282
+ """Parse LLMs into a list of dictionaries."""
283
+ for idx, llm in enumerate(llms):
284
+ if llm is not None:
285
+ model_name = getattr(llm, "model", None) or getattr(llm, "model_name", None) or ""
286
+ llm_data = {
287
+ "model": model_name,
288
+ "temperature": llm.temperature,
289
+ "max_tokens": llm.max_tokens,
290
+ "max_completion_tokens": llm.max_completion_tokens,
291
+ "top_p": llm.top_p,
292
+ "n": llm.n,
293
+ "seed": llm.seed,
294
+ "base_url": llm.base_url,
295
+ "api_version": llm.api_version,
296
+ }
297
+
298
+ self._set_attribute(f"{SpanAttributes.LLM_REQUEST_MODEL}.{idx}", model_name)
299
+ if hasattr(llm, "temperature"):
300
+ self._set_attribute(f"{SpanAttributes.LLM_REQUEST_TEMPERATURE}.{idx}", str(llm.temperature))
301
+ if hasattr(llm, "max_tokens"):
302
+ self._set_attribute(f"{SpanAttributes.LLM_REQUEST_MAX_TOKENS}.{idx}", str(llm.max_tokens))
303
+ if hasattr(llm, "top_p"):
304
+ self._set_attribute(f"{SpanAttributes.LLM_REQUEST_TOP_P}.{idx}", str(llm.top_p))
305
+
306
+ for key, value in llm_data.items():
307
+ if value is not None:
308
+ self._set_attribute(f"crewai.llms.{idx}.{key}", str(value))
309
+
310
+ def _extract_agent_data(self, agent):
311
+ """Extract data from an agent."""
312
+ model = getattr(agent.llm, "model", None) or getattr(agent.llm, "model_name", None) or ""
313
+
314
+ tools_list = []
315
+ if hasattr(agent, "tools") and agent.tools:
316
+ tools_list = _parse_tools(agent.tools)
317
+
318
+ return {
319
+ "id": str(agent.id),
320
+ "role": agent.role,
321
+ "goal": agent.goal,
322
+ "backstory": agent.backstory,
323
+ "cache": agent.cache,
324
+ "config": agent.config,
325
+ "verbose": agent.verbose,
326
+ "allow_delegation": agent.allow_delegation,
327
+ "tools": tools_list,
328
+ "max_iter": agent.max_iter,
329
+ "llm": str(model),
330
+ }
331
+
332
+ def _set_attribute(self, key, value):
333
+ """Set an attribute on the span."""
334
+ if value is not None and value != "":
335
+ set_span_attribute(self.span, key, value)