Skip to content

Commit a0b757a

Browse files
authored
Lorenze/traces mark as failed (#3586)
* marking trace batch as failed if its failed * fix test
1 parent 1dbe8aa commit a0b757a

File tree

4 files changed

+367
-5
lines changed

4 files changed

+367
-5
lines changed

src/crewai/cli/plus_api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,13 @@ def finalize_ephemeral_trace_batch(
166166
json=payload,
167167
timeout=30,
168168
)
169+
170+
def mark_trace_batch_as_failed(
171+
self, trace_batch_id: str, error_message: str
172+
) -> requests.Response:
173+
return self._make_request(
174+
"PATCH",
175+
f"{self.TRACING_RESOURCE}/batches/{trace_batch_id}",
176+
json={"status": "failed", "failure_reason": error_message},
177+
timeout=30,
178+
)

src/crewai/events/listeners/tracing/trace_batch_manager.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ def finalize_batch(self) -> TraceBatch | None:
200200
if self.event_buffer:
201201
events_sent_to_backend_status = self._send_events_to_backend()
202202
if events_sent_to_backend_status == 500:
203+
self.plus_api.mark_trace_batch_as_failed(
204+
self.trace_batch_id, "Error sending events to backend"
205+
)
203206
return None
204207
self._finalize_backend_batch()
205208

@@ -273,10 +276,13 @@ def _finalize_backend_batch(self):
273276
logger.error(
274277
f"❌ Failed to finalize trace batch: {response.status_code} - {response.text}"
275278
)
279+
self.plus_api.mark_trace_batch_as_failed(
280+
self.trace_batch_id, response.text
281+
)
276282

277283
except Exception as e:
278284
logger.error(f"❌ Error finalizing trace batch: {e}")
279-
# TODO: send error to app marking as failed
285+
self.plus_api.mark_trace_batch_as_failed(self.trace_batch_id, str(e))
280286

281287
def _cleanup_batch_data(self):
282288
"""Clean up batch data after successful finalization to free memory"""
Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
interactions:
2+
- request:
3+
body: '{"messages": [{"role": "system", "content": "You are Test Agent. Test backstory\nYour
4+
personal goal is: Test goal\nTo give my best complete final answer to the task
5+
respond using the exact following format:\n\nThought: I now can give a great
6+
answer\nFinal Answer: Your final answer must be the great and the most complete
7+
as possible, it must be outcome described.\n\nI MUST use these formats, my job
8+
depends on it!"}, {"role": "user", "content": "\nCurrent Task: Say hello to
9+
the world\n\nThis is the expected criteria for your final answer: hello world\nyou
10+
MUST return the actual complete content as the final answer, not a summary.\n\nBegin!
11+
This is VERY important to you, use the tools available and give your best Final
12+
Answer, your job depends on it!\n\nThought:"}], "model": "gpt-4o-mini", "stop":
13+
["\nObservation:"]}'
14+
headers:
15+
accept:
16+
- application/json
17+
accept-encoding:
18+
- gzip, deflate
19+
connection:
20+
- keep-alive
21+
content-length:
22+
- '825'
23+
content-type:
24+
- application/json
25+
host:
26+
- api.openai.com
27+
user-agent:
28+
- OpenAI/Python 1.93.0
29+
x-stainless-arch:
30+
- arm64
31+
x-stainless-async:
32+
- 'false'
33+
x-stainless-lang:
34+
- python
35+
x-stainless-os:
36+
- MacOS
37+
x-stainless-package-version:
38+
- 1.93.0
39+
x-stainless-raw-response:
40+
- 'true'
41+
x-stainless-read-timeout:
42+
- '600.0'
43+
x-stainless-retry-count:
44+
- '0'
45+
x-stainless-runtime:
46+
- CPython
47+
x-stainless-runtime-version:
48+
- 3.12.9
49+
method: POST
50+
uri: https://api.openai.com/v1/chat/completions
51+
response:
52+
body:
53+
string: !!binary |
54+
H4sIAAAAAAAAAwAAAP//jFJNj9MwEL3nV4x8blC/0nRzA8QKuCBxQFrBKnLtSeLF8Vi2s11Y9b8j
55+
O90m5UPiEinz5j2/NzPPGQBTklXARMeD6K3O33588/nm/d27T5sv6wdp1OGu/9l1T9tbWzQlW0QG
56+
HR5QhBfWK0G91RgUmREWDnnAqLoqi/1uv19vVgnoSaKOtNaGfEt5r4zK18v1Nl+W+Wp/ZnekBHpW
57+
wdcMAOA5faNPI/GJVbBcvFR69J63yKpLEwBzpGOFce+VD9wEtphAQSagSdY/gKEjCG6gVY8IHNpo
58+
G7jxR3QA38ytMlzD6/RfQYdaExzJaTkXdNgMnsdQZtB6BnBjKPA4lBTl/oycLuY1tdbRwf9GZY0y
59+
yne1Q+7JRKM+kGUJPWUA92lIw1VuZh31NtSBvmN6blWUox6bdjNDN2cwUOB6Vi/Po73WqyUGrrSf
60+
jZkJLjqUE3XaCR+kohmQzVL/6eZv2mNyZdr/kZ8AIdAGlLV1KJW4Tjy1OYyn+6+2y5STYebRPSqB
61+
dVDo4iYkNnzQ40Ex/8MH7OtGmRaddWq8qsbWxW7Jmx0WxQ3LTtkvAAAA//8DAIkIBqtjAwAA
62+
headers:
63+
CF-RAY:
64+
- 983f8c061b6ec487-SJC
65+
Connection:
66+
- keep-alive
67+
Content-Encoding:
68+
- gzip
69+
Content-Type:
70+
- application/json
71+
Date:
72+
- Wed, 24 Sep 2025 04:30:32 GMT
73+
Server:
74+
- cloudflare
75+
Set-Cookie:
76+
- __cf_bm=JDjpnzx5y8PJaJDQcCeX6MeBt8BOGuL79pd.ca5mqvE-1758688232-1.0.1.1-5VN5hj5LzEZFfkotBaZ_dbUITo_YB7RLsFOlQc.0MdSZOsz7WhNkH.s7H700L12Yi8nHGW44BgIwCF3uWx1w4PRBqrb1IVH3FkeV.QwCTaA;
77+
path=/; expires=Wed, 24-Sep-25 05:00:32 GMT; domain=.api.openai.com; HttpOnly;
78+
Secure; SameSite=None
79+
- _cfuvid=b5n8BZZDRtHA4TrxQ1RDeEdtQBzhstjP6u21LYM8L94-1758688232142-0.0.1.1-604800000;
80+
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
81+
Strict-Transport-Security:
82+
- max-age=31536000; includeSubDomains; preload
83+
Transfer-Encoding:
84+
- chunked
85+
X-Content-Type-Options:
86+
- nosniff
87+
access-control-expose-headers:
88+
- X-Request-ID
89+
alt-svc:
90+
- h3=":443"; ma=86400
91+
cf-cache-status:
92+
- DYNAMIC
93+
openai-organization:
94+
- crewai-iuxna1
95+
openai-processing-ms:
96+
- '535'
97+
openai-project:
98+
- proj_xitITlrFeen7zjNSzML82h9x
99+
openai-version:
100+
- '2020-10-01'
101+
x-envoy-upstream-service-time:
102+
- '562'
103+
x-openai-proxy-wasm:
104+
- v0.1
105+
x-ratelimit-limit-project-tokens:
106+
- '150000000'
107+
x-ratelimit-limit-requests:
108+
- '30000'
109+
x-ratelimit-limit-tokens:
110+
- '150000000'
111+
x-ratelimit-remaining-project-tokens:
112+
- '149999827'
113+
x-ratelimit-remaining-requests:
114+
- '29999'
115+
x-ratelimit-remaining-tokens:
116+
- '149999830'
117+
x-ratelimit-reset-project-tokens:
118+
- 0s
119+
x-ratelimit-reset-requests:
120+
- 2ms
121+
x-ratelimit-reset-tokens:
122+
- 0s
123+
x-request-id:
124+
- req_af61ab9d53bf400baf30c5bc5a7e2102
125+
status:
126+
code: 200
127+
message: OK
128+
- request:
129+
body: null
130+
headers:
131+
Connection:
132+
- close
133+
Host:
134+
- api.scarf.sh
135+
User-Agent:
136+
- CrewAI-Python/0.193.2
137+
method: GET
138+
uri: https://api.scarf.sh/v2/packages/CrewAI/crewai/docs/00f2dad1-8334-4a39-934e-003b2e1146db
139+
response:
140+
body:
141+
string: ''
142+
headers:
143+
Connection:
144+
- close
145+
Date:
146+
- Wed, 24 Sep 2025 04:47:59 GMT
147+
Strict-Transport-Security:
148+
- max-age=15724800; includeSubDomains
149+
Transfer-Encoding:
150+
- chunked
151+
x-scarf-request-id:
152+
- 4158376f-cb1c-46fe-a14c-dee366b955e2
153+
status:
154+
code: 401
155+
message: Unauthorized
156+
- request:
157+
body: '{"trace_id": "06e1250e-6d88-4c64-abe5-deabde573ae1", "execution_type":
158+
"crew", "user_identifier": null, "execution_context": {"crew_fingerprint": null,
159+
"crew_name": "crew", "flow_name": null, "crewai_version": "0.193.2", "privacy_level":
160+
"standard"}, "execution_metadata": {"expected_duration_estimate": 300, "agent_count":
161+
0, "task_count": 0, "flow_method_count": 0, "execution_started_at": "2025-09-24T04:50:23.219835+00:00"}}'
162+
headers:
163+
Accept:
164+
- '*/*'
165+
Accept-Encoding:
166+
- gzip, deflate
167+
Connection:
168+
- keep-alive
169+
Content-Length:
170+
- '428'
171+
Content-Type:
172+
- application/json
173+
User-Agent:
174+
- CrewAI-CLI/0.193.2
175+
X-Crewai-Organization-Id:
176+
- d3a3d10c-35db-423f-a7a4-c026030ba64d
177+
X-Crewai-Version:
178+
- 0.193.2
179+
method: POST
180+
uri: http://localhost:3000/crewai_plus/api/v1/tracing/batches
181+
response:
182+
body:
183+
string: '{"error":"bad_credentials","message":"Bad credentials"}'
184+
headers:
185+
Content-Length:
186+
- '55'
187+
cache-control:
188+
- no-cache
189+
content-security-policy:
190+
- 'default-src ''self'' *.crewai.com crewai.com; script-src ''self'' ''unsafe-inline''
191+
*.crewai.com crewai.com https://cdn.jsdelivr.net/npm/apexcharts https://www.gstatic.com
192+
https://run.pstmn.io https://share.descript.com/; style-src ''self'' ''unsafe-inline''
193+
*.crewai.com crewai.com https://cdn.jsdelivr.net/npm/apexcharts; img-src ''self''
194+
data: *.crewai.com crewai.com https://zeus.tools.crewai.com https://dashboard.tools.crewai.com
195+
https://cdn.jsdelivr.net; font-src ''self'' data: *.crewai.com crewai.com;
196+
connect-src ''self'' *.crewai.com crewai.com https://zeus.tools.crewai.com
197+
https://connect.useparagon.com/ https://zeus.useparagon.com/* https://*.useparagon.com/*
198+
https://run.pstmn.io https://connect.tools.crewai.com/ ws://localhost:3036
199+
wss://localhost:3036; frame-src ''self'' *.crewai.com crewai.com https://connect.useparagon.com/
200+
https://zeus.tools.crewai.com https://zeus.useparagon.com/* https://connect.tools.crewai.com/
201+
https://www.youtube.com https://share.descript.com'
202+
content-type:
203+
- application/json; charset=utf-8
204+
permissions-policy:
205+
- camera=(), microphone=(self), geolocation=()
206+
referrer-policy:
207+
- strict-origin-when-cross-origin
208+
server-timing:
209+
- cache_read.active_support;dur=0.37, sql.active_record;dur=30.81, cache_generate.active_support;dur=29.14,
210+
cache_write.active_support;dur=0.14, cache_read_multi.active_support;dur=0.19,
211+
start_processing.action_controller;dur=0.00, process_action.action_controller;dur=2.74
212+
vary:
213+
- Accept
214+
x-content-type-options:
215+
- nosniff
216+
x-frame-options:
217+
- SAMEORIGIN
218+
x-permitted-cross-domain-policies:
219+
- none
220+
x-request-id:
221+
- 2420790e-9669-4235-851c-468185b6ef40
222+
x-runtime:
223+
- '0.102516'
224+
x-xss-protection:
225+
- 1; mode=block
226+
status:
227+
code: 401
228+
message: Unauthorized
229+
- request:
230+
body: '{"status": "failed", "failure_reason": "Error sending events to backend"}'
231+
headers:
232+
Accept:
233+
- '*/*'
234+
Accept-Encoding:
235+
- gzip, deflate
236+
Connection:
237+
- keep-alive
238+
Content-Length:
239+
- '73'
240+
Content-Type:
241+
- application/json
242+
User-Agent:
243+
- CrewAI-CLI/0.193.2
244+
X-Crewai-Organization-Id:
245+
- d3a3d10c-35db-423f-a7a4-c026030ba64d
246+
X-Crewai-Version:
247+
- 0.193.2
248+
method: PATCH
249+
uri: http://localhost:3000/crewai_plus/api/v1/tracing/batches/None
250+
response:
251+
body:
252+
string: '{"error":"bad_credentials","message":"Bad credentials"}'
253+
headers:
254+
Content-Length:
255+
- '55'
256+
cache-control:
257+
- no-cache
258+
content-security-policy:
259+
- 'default-src ''self'' *.crewai.com crewai.com; script-src ''self'' ''unsafe-inline''
260+
*.crewai.com crewai.com https://cdn.jsdelivr.net/npm/apexcharts https://www.gstatic.com
261+
https://run.pstmn.io https://share.descript.com/; style-src ''self'' ''unsafe-inline''
262+
*.crewai.com crewai.com https://cdn.jsdelivr.net/npm/apexcharts; img-src ''self''
263+
data: *.crewai.com crewai.com https://zeus.tools.crewai.com https://dashboard.tools.crewai.com
264+
https://cdn.jsdelivr.net; font-src ''self'' data: *.crewai.com crewai.com;
265+
connect-src ''self'' *.crewai.com crewai.com https://zeus.tools.crewai.com
266+
https://connect.useparagon.com/ https://zeus.useparagon.com/* https://*.useparagon.com/*
267+
https://run.pstmn.io https://connect.tools.crewai.com/ ws://localhost:3036
268+
wss://localhost:3036; frame-src ''self'' *.crewai.com crewai.com https://connect.useparagon.com/
269+
https://zeus.tools.crewai.com https://zeus.useparagon.com/* https://connect.tools.crewai.com/
270+
https://www.youtube.com https://share.descript.com'
271+
content-type:
272+
- application/json; charset=utf-8
273+
permissions-policy:
274+
- camera=(), microphone=(self), geolocation=()
275+
referrer-policy:
276+
- strict-origin-when-cross-origin
277+
server-timing:
278+
- cache_read.active_support;dur=0.06, sql.active_record;dur=3.86, cache_generate.active_support;dur=4.28,
279+
cache_write.active_support;dur=0.15, cache_read_multi.active_support;dur=0.12,
280+
start_processing.action_controller;dur=0.00, process_action.action_controller;dur=1.70
281+
vary:
282+
- Accept
283+
x-content-type-options:
284+
- nosniff
285+
x-frame-options:
286+
- SAMEORIGIN
287+
x-permitted-cross-domain-policies:
288+
- none
289+
x-request-id:
290+
- 1750d141-c48f-47f1-b8b4-130195437d22
291+
x-runtime:
292+
- '0.043849'
293+
x-xss-protection:
294+
- 1; mode=block
295+
status:
296+
code: 401
297+
message: Unauthorized
298+
version: 1

0 commit comments

Comments
 (0)