Skip to content

Commit c1ccf23

Browse files
viniciusdsmellogustavocidornelas
authored andcommitted
Refactor tracing functions to replace update_current_span with update_current_step
1 parent ac849ab commit c1ccf23

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

examples/tracing/trace_metadata_updates.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
os.environ["OPENLAYER_API_KEY"] = "your-api-key-here"
1616
os.environ["OPENLAYER_INFERENCE_PIPELINE_ID"] = "your-pipeline-id-here"
1717

18-
from openlayer.lib import trace, trace_async, update_current_trace, update_current_span
18+
from openlayer.lib import trace, trace_async, update_current_trace, update_current_step
1919

2020

2121
class UserSession:
@@ -78,7 +78,7 @@ def preprocess_request(self, text: str, user_session: UserSession) -> str:
7878
"""Preprocess user request with step-level metadata."""
7979

8080
# Update current step with preprocessing context
81-
update_current_span(
81+
update_current_step(
8282
metadata={
8383
"preprocessing_type": "standard",
8484
"user_preferences_applied": True,
@@ -104,7 +104,7 @@ def generate_response(self, processed_text: str, user_session: UserSession) -> s
104104
# Set model-specific metadata
105105
model_version = "gpt-4" if user_session.preferences.get("tier") == "premium" else "gpt-3.5-turbo"
106106

107-
update_current_span(
107+
update_current_step(
108108
metadata={
109109
"model_used": model_version,
110110
"temperature": 0.7,
@@ -131,7 +131,7 @@ def generate_response(self, processed_text: str, user_session: UserSession) -> s
131131
def postprocess_response(self, response: str, user_session: UserSession) -> str:
132132
"""Postprocess response with personalization metadata."""
133133

134-
update_current_span(
134+
update_current_step(
135135
metadata={
136136
"personalization_applied": True,
137137
"content_filtering": user_session.preferences.get("content_filter", "moderate"),
@@ -230,7 +230,7 @@ def error_handling_example():
230230

231231
try:
232232
# Simulate some processing
233-
update_current_span(
233+
update_current_step(
234234
metadata={"processing_step": "initial_validation"}
235235
)
236236

@@ -265,7 +265,7 @@ async def async_example():
265265
# Simulate async processing steps
266266
import asyncio
267267

268-
update_current_span(
268+
update_current_step(
269269
metadata={"step": "async_sleep_simulation"}
270270
)
271271
await asyncio.sleep(0.1)

src/openlayer/lib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"trace_oci_genai",
1515
"trace_oci", # Alias for backward compatibility
1616
"update_current_trace",
17-
"update_current_span"
17+
"update_current_step"
1818
]
1919

2020
# ---------------------------------- Tracing --------------------------------- #
@@ -24,7 +24,7 @@
2424
trace = tracer.trace
2525
trace_async = tracer.trace_async
2626
update_current_trace = tracer.update_current_trace
27-
update_current_span = tracer.update_current_span
27+
update_current_step = tracer.update_current_step
2828

2929

3030
def trace_anthropic(client):

src/openlayer/lib/tracing/tracer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,11 @@ def update_current_trace(**kwargs) -> None:
560560
logger.debug("Updated current trace metadata")
561561

562562

563-
def update_current_span(
563+
def update_current_step(
564564
attributes: Optional[Dict[str, Any]] = None,
565565
metadata: Optional[Dict[str, Any]] = None
566566
) -> None:
567-
"""Updates the current step (span) with the provided attributes.
567+
"""Updates the current step with the provided attributes.
568568
569569
This function allows users to set step-level metadata dynamically
570570
during execution.
@@ -574,20 +574,20 @@ def update_current_span(
574574
metadata: Optional dictionary of metadata to merge with existing metadata
575575
576576
Example:
577-
>>> from openlayer.lib import trace, update_current_span
577+
>>> from openlayer.lib import trace, update_current_step
578578
>>>
579579
>>> @trace()
580580
>>> def my_function():
581581
>>> # Update current step with additional context
582-
>>> update_current_span(
582+
>>> update_current_step(
583583
>>> metadata={"model_version": "v1.2.3"}
584584
>>> )
585585
>>> return "result"
586586
"""
587587
current_step = get_current_step()
588588
if current_step is None:
589589
logger.warning(
590-
"update_current_span() called without an active step. "
590+
"update_current_step() called without an active step. "
591591
"Make sure to call this function within a traced context "
592592
"(e.g., inside a function decorated with @trace)."
593593
)
@@ -895,9 +895,9 @@ def post_process_trace(
895895
**root_step.metadata,
896896
}
897897

898-
# Include trace-level metadata if set
898+
# Include trace-level metadata if set - extract keys to row/record level
899899
if trace_obj.metadata is not None:
900-
# Merge trace-level metadata (higher precedence than root step metadata)
900+
# Add each trace metadata key directly to the row/record level
901901
trace_data.update(trace_obj.metadata)
902902

903903
if root_step.ground_truth:

0 commit comments

Comments
 (0)