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
4 changes: 3 additions & 1 deletion src/gentrace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def __getattr__(self, name: str) -> _t.Any:
ATTR_GENTRACE_PIPELINE_ID,
ATTR_GENTRACE_TEST_CASE_ID,
ATTR_GENTRACE_EXPERIMENT_ID,
ATTR_GENTRACE_IN_EXPERIMENT,
ATTR_GENTRACE_TEST_CASE_NAME,
ATTR_GENTRACE_FN_ARGS_EVENT_NAME,
ATTR_GENTRACE_FN_OUTPUT_EVENT_NAME,
Expand Down Expand Up @@ -160,7 +161,6 @@ def __getattr__(self, name: str) -> _t.Any:
"DefaultHttpxClient",
"DefaultAsyncHttpxClient",
"DefaultAioHttpClient",

# Start custom Gentrace exports
"init",
"setup",
Expand All @@ -170,6 +170,8 @@ def __getattr__(self, name: str) -> _t.Any:
"eval",
"eval_dataset",
"TestInput",
"ATTR_GENTRACE_SAMPLE_KEY",
"ATTR_GENTRACE_IN_EXPERIMENT",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appears to be a duplicate export of ATTR_GENTRACE_IN_EXPERIMENT in the __init__.py file. It's being exported once on line 173 and again on line 177 (after the changes). To maintain clean and consistent exports, please remove one of these duplicate entries.

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

"ATTR_GENTRACE_PIPELINE_ID",
"ATTR_GENTRACE_TEST_CASE_ID",
"ATTR_GENTRACE_EXPERIMENT_ID",
Expand Down
2 changes: 2 additions & 0 deletions src/gentrace/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ATTR_GENTRACE_TEST_CASE_ID = "gentrace.test_case_id"

ATTR_GENTRACE_SAMPLE_KEY = "gentrace.sample"
ATTR_GENTRACE_IN_EXPERIMENT = "gentrace.in_experiment"

# Maximum allowed concurrency for eval_dataset
MAX_EVAL_DATASET_CONCURRENCY = 100
Expand All @@ -25,5 +26,6 @@
"ATTR_GENTRACE_TEST_CASE_ID",
"ATTR_GENTRACE_PIPELINE_ID",
"ATTR_GENTRACE_SAMPLE_KEY",
"ATTR_GENTRACE_IN_EXPERIMENT",
"MAX_EVAL_DATASET_CONCURRENCY",
]
4 changes: 4 additions & 0 deletions src/gentrace/lib/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ANONYMOUS_SPAN_NAME,
ATTR_GENTRACE_SAMPLE_KEY,
ATTR_GENTRACE_EXPERIMENT_ID,
ATTR_GENTRACE_IN_EXPERIMENT,
ATTR_GENTRACE_TEST_CASE_NAME,
ATTR_GENTRACE_FN_ARGS_EVENT_NAME,
ATTR_GENTRACE_FN_OUTPUT_EVENT_NAME,
Expand Down Expand Up @@ -90,6 +91,9 @@ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
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)
try:
Expand Down
4 changes: 4 additions & 0 deletions src/gentrace/lib/eval_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
ATTR_GENTRACE_SAMPLE_KEY,
ATTR_GENTRACE_TEST_CASE_ID,
ATTR_GENTRACE_EXPERIMENT_ID,
ATTR_GENTRACE_IN_EXPERIMENT,
ATTR_GENTRACE_TEST_CASE_NAME,
MAX_EVAL_DATASET_CONCURRENCY,
ATTR_GENTRACE_FN_ARGS_EVENT_NAME,
Expand Down Expand Up @@ -215,6 +216,9 @@ async def _run_single_test_case_for_dataset(
# 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)
try:
Expand Down
7 changes: 6 additions & 1 deletion src/gentrace/lib/span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from opentelemetry.context import Context
from opentelemetry.sdk.trace import ReadableSpan, SpanProcessor

from gentrace.lib.constants import ATTR_GENTRACE_SAMPLE_KEY
from gentrace.lib.constants import ATTR_GENTRACE_SAMPLE_KEY, ATTR_GENTRACE_IN_EXPERIMENT


class GentraceSpanProcessor(SpanProcessor):
Expand Down Expand Up @@ -35,6 +35,11 @@ def on_start(self, span: Span, parent_context: Optional[Context] = None) -> 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)

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