Skip to content

Commit 7c2ea5e

Browse files
author
Andrei Bratu
committed
Debug session Harry
1 parent 068b1b0 commit 7c2ea5e

File tree

1 file changed

+14
-39
lines changed

1 file changed

+14
-39
lines changed

src/humanloop/otel/exporter.py

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ def is_evaluated_file(
8585
try:
8686
evaluation_context = self._client.evaluation_context_variable.get()
8787
if len(spans) > 1:
88-
raise RuntimeError(
89-
"HumanloopSpanExporter expected a single span when running an evaluation"
90-
)
88+
raise RuntimeError("HumanloopSpanExporter expected a single span when running an evaluation")
9189
if not is_evaluated_file(spans[0], evaluation_context):
9290
evaluation_context = None
9391
except LookupError:
@@ -122,9 +120,7 @@ def is_evaluated_file(
122120
self._client.evaluation_context_variable.set(None)
123121
return SpanExportResult.SUCCESS
124122
else:
125-
logger.warning(
126-
"HumanloopSpanExporter is shutting down, not accepting new spans"
127-
)
123+
logger.warning("HumanloopSpanExporter is shutting down, not accepting new spans")
128124
return SpanExportResult.FAILURE
129125

130126
def shutdown(self) -> None:
@@ -172,9 +168,7 @@ def _do_work(self):
172168
self._client.evaluation_context_variable.set(evaluation_context)
173169
except EmptyQueue:
174170
continue
175-
trace_metadata = TRACE_FLOW_CONTEXT.get(
176-
span_to_export.get_span_context().span_id
177-
)
171+
trace_metadata = TRACE_FLOW_CONTEXT.get(span_to_export.get_span_context().span_id)
178172
if trace_metadata is None:
179173
# Span is not part of a Flow Log
180174
self._export_span_dispatch(span_to_export)
@@ -239,14 +233,8 @@ def _export_prompt(self, span: ReadableSpan) -> None:
239233
if "tools" not in file_object["prompt"]:
240234
file_object["prompt"]["tools"] = []
241235
trace_metadata = TRACE_FLOW_CONTEXT.get(span.get_span_context().span_id)
242-
if (
243-
trace_metadata
244-
and "trace_parent_id" in trace_metadata
245-
and trace_metadata["trace_parent_id"]
246-
):
247-
trace_parent_id = self._span_id_to_uploaded_log_id[
248-
trace_metadata["trace_parent_id"]
249-
]
236+
if trace_metadata and "trace_parent_id" in trace_metadata and trace_metadata["trace_parent_id"]:
237+
trace_parent_id = self._span_id_to_uploaded_log_id[trace_metadata["trace_parent_id"]]
250238
if trace_parent_id is None:
251239
# Parent Log in Trace upload failed
252240
file_path = read_from_opentelemetry_span(span, key=HUMANLOOP_PATH_KEY)
@@ -275,15 +263,9 @@ def _export_prompt(self, span: ReadableSpan) -> None:
275263
self._span_id_to_uploaded_log_id[span.context.span_id] = None
276264

277265
def _export_tool(self, span: ReadableSpan) -> None:
278-
file_object: dict[str, Any] = read_from_opentelemetry_span(
279-
span, key=HUMANLOOP_FILE_KEY
280-
)
281-
log_object: dict[str, Any] = read_from_opentelemetry_span(
282-
span, key=HUMANLOOP_LOG_KEY
283-
)
284-
trace_metadata: FlowContext = TRACE_FLOW_CONTEXT.get(
285-
span.get_span_context().span_id, {}
286-
)
266+
file_object: dict[str, Any] = read_from_opentelemetry_span(span, key=HUMANLOOP_FILE_KEY)
267+
log_object: dict[str, Any] = read_from_opentelemetry_span(span, key=HUMANLOOP_LOG_KEY)
268+
trace_metadata: FlowContext = TRACE_FLOW_CONTEXT.get(span.get_span_context().span_id, {})
287269
if "trace_parent_id" in trace_metadata and trace_metadata["trace_parent_id"]:
288270
trace_parent_id = self._span_id_to_uploaded_log_id.get(
289271
trace_metadata["trace_parent_id"],
@@ -301,6 +283,8 @@ def _export_tool(self, span: ReadableSpan) -> None:
301283
if not tool.get("setup_values"):
302284
tool["setup_values"] = {}
303285
path: str = file_object["path"]
286+
if "parameters" in tool["function"] and "properties" not in tool["function"]["parameters"]:
287+
tool["function"]["parameters"]["properties"] = {}
304288
if not isinstance(log_object["output"], str):
305289
# Output expected to be a string, if decorated function
306290
# does not return one, jsonify it
@@ -317,12 +301,8 @@ def _export_tool(self, span: ReadableSpan) -> None:
317301
self._span_id_to_uploaded_log_id[span.context.span_id] = None
318302

319303
def _export_flow(self, span: ReadableSpan) -> None:
320-
file_object: dict[str, Any] = read_from_opentelemetry_span(
321-
span, key=HUMANLOOP_FILE_KEY
322-
)
323-
log_object: dict[str, Any] = read_from_opentelemetry_span(
324-
span, key=HUMANLOOP_LOG_KEY
325-
)
304+
file_object: dict[str, Any] = read_from_opentelemetry_span(span, key=HUMANLOOP_FILE_KEY)
305+
log_object: dict[str, Any] = read_from_opentelemetry_span(span, key=HUMANLOOP_LOG_KEY)
326306
trace_metadata: FlowContext = TRACE_FLOW_CONTEXT.get(
327307
span.get_span_context().span_id,
328308
{},
@@ -331,10 +311,7 @@ def _export_flow(self, span: ReadableSpan) -> None:
331311
trace_parent_id = self._span_id_to_uploaded_log_id.get(
332312
trace_metadata["trace_parent_id"], # type: ignore
333313
)
334-
if (
335-
trace_parent_id is None
336-
and trace_metadata["trace_id"] != span.get_span_context().span_id
337-
):
314+
if trace_parent_id is None and trace_metadata["trace_id"] != span.get_span_context().span_id:
338315
# Parent Log in Trace upload failed
339316
# NOTE: Check if the trace_id metadata field points to the
340317
# span itself. This signifies the span is the head of the Trace
@@ -358,9 +335,7 @@ def _export_flow(self, span: ReadableSpan) -> None:
358335
**log_object,
359336
trace_parent_id=trace_parent_id,
360337
)
361-
self._span_id_to_uploaded_log_id[span.get_span_context().span_id] = (
362-
log_response.id
363-
)
338+
self._span_id_to_uploaded_log_id[span.get_span_context().span_id] = log_response.id
364339
except HumanloopApiError as e:
365340
logger.error(str(e))
366341
self._span_id_to_uploaded_log_id[span.context.span_id] = None

0 commit comments

Comments
 (0)