Skip to content

Commit 86c20ba

Browse files
author
Andrei Bratu
committed
switch to copycontext
1 parent b9668d2 commit 86c20ba

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/humanloop/otel/exporter.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
1515

1616
from humanloop.core import ApiError as HumanloopApiError
17-
from humanloop.eval_utils.context import EvaluationContext
17+
from humanloop.eval_utils.context import EVALUATION_CONTEXT_VARIABLE_NAME, EvaluationContext
1818
from humanloop.otel import TRACE_FLOW_CONTEXT, FlowContext
1919
from humanloop.otel.constants import (
2020
HUMANLOOP_FILE_KEY,
@@ -94,16 +94,20 @@ def is_evaluated_file(
9494
if is_humanloop_span(span):
9595
# We pass the EvaluationContext from the eval_run utility thread to
9696
# the export thread so the .log action works as expected
97+
evaluation_context_copy = None
98+
for context_var, context_var_value in contextvars.copy_context().items():
99+
if context_var.name == EVALUATION_CONTEXT_VARIABLE_NAME:
100+
evaluation_context_copy = context_var_value
97101
self._upload_queue.put(
98102
(
99103
span,
100-
copy.deepcopy(evaluation_context),
104+
evaluation_context_copy,
101105
),
102106
)
103107
logger.debug(
104108
"Span %s with EvaluationContext %s added to upload queue",
105109
span.attributes,
106-
copy.deepcopy(evaluation_context),
110+
evaluation_context_copy,
107111
)
108112
# Reset the EvaluationContext so run eval does not
109113
# create a duplicate Log

0 commit comments

Comments
 (0)