Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/gentrace/lib/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,11 @@ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:

span_name = name

# Set up baggage context similar to @interaction()
current_context = otel_context.get_current()
context_with_modified_baggage = otel_baggage.set_baggage(
ATTR_GENTRACE_SAMPLE_KEY, "true", context=current_context
)
context_with_modified_baggage = otel_baggage.set_baggage(
ATTR_GENTRACE_IN_EXPERIMENT, "true", context=context_with_modified_baggage
)

token = otel_context.attach(context_with_modified_baggage)
context = otel_context.get_current()
context = otel_baggage.set_baggage(ATTR_GENTRACE_SAMPLE_KEY, "true", context=context)
context = otel_baggage.set_baggage(ATTR_GENTRACE_IN_EXPERIMENT, "true", context=context)
token = otel_context.attach(context)

try:
with _tracer.start_as_current_span(span_name) as span:
span.set_attribute(ATTR_GENTRACE_EXPERIMENT_ID, experiment_context["experiment_id"])
Expand Down
10 changes: 4 additions & 6 deletions src/gentrace/lib/eval_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,11 @@ async def _run_single_test_case_for_dataset(
result_value: Any = None # type: ignore

# Set up baggage context similar to @interaction()
current_context = otel_context.get_current()
context_with_modified_baggage = otel_baggage.set_baggage(ATTR_GENTRACE_SAMPLE_KEY, "true", context=current_context)
context_with_modified_baggage = otel_baggage.set_baggage(
ATTR_GENTRACE_IN_EXPERIMENT, "true", context=context_with_modified_baggage
)
context = otel_context.get_current()
context = otel_baggage.set_baggage(ATTR_GENTRACE_SAMPLE_KEY, "true", context=context)
context = otel_baggage.set_baggage(ATTR_GENTRACE_IN_EXPERIMENT, "true", context=context)
token = otel_context.attach(context)

token = otel_context.attach(context_with_modified_baggage)
try:
with _tracer.start_as_current_span(span_name) as span:
span.set_attribute(ATTR_GENTRACE_EXPERIMENT_ID, experiment_context["experiment_id"])
Expand Down
13 changes: 4 additions & 9 deletions src/gentrace/lib/span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ def on_start(self, span: Span, parent_context: Optional[Context] = None) -> None
Called when a Span is started, if the span.is_recording()
returns true.
"""
sample_value = baggage.get_baggage(ATTR_GENTRACE_SAMPLE_KEY, context=parent_context)
if sample_value is not None:
if isinstance(sample_value, str):
span.set_attribute(ATTR_GENTRACE_SAMPLE_KEY, sample_value)

in_experiment_value = baggage.get_baggage(ATTR_GENTRACE_IN_EXPERIMENT, context=parent_context)
if in_experiment_value is not None:
if isinstance(in_experiment_value, str):
span.set_attribute(ATTR_GENTRACE_IN_EXPERIMENT, in_experiment_value)
for key in [ATTR_GENTRACE_SAMPLE_KEY, ATTR_GENTRACE_IN_EXPERIMENT]:
value = baggage.get_baggage(key, context=parent_context)
if isinstance(value, str):
span.set_attribute(key, value)

@override
def on_end(self, span: ReadableSpan) -> None:
Expand Down
Loading