Skip to content

Commit

Permalink
feat(session): preserve original event type in span attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
teocns committed Nov 27, 2024
1 parent 6b30e1f commit 20dffe9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions agentops/session/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ def to_span_attributes(obj: Any) -> Dict[str, AttributeValue]:
# Construct span attributes with proper prefixes and type conversion
span_attrs: Dict[str, AttributeValue] = {}

# Preserve original event type
if hasattr(obj, "event_type"):
span_attrs["event.type"] = obj.event_type

# Special handling for ActionEvent
if hasattr(obj, "event_type") and obj.event_type == EventType.ACTION.value:
span_attrs["event.type"] = "actions"
span_attrs["event.category"] = "actions"
# For ActionEvent, use action_type if available, otherwise use the first positional arg
if hasattr(obj, "action_type") and obj.action_type:
span_attrs["event.action_type"] = obj.action_type
Expand Down Expand Up @@ -121,13 +125,13 @@ def from_span_attributes(attrs: Union[Dict[str, AttributeValue], Mapping[str, At
# Build base event structure
event = {
"id": attrs_dict.get("event.id", str(uuid4())),
"event_type": attrs_dict.get("event.type", "actions"),
"event_type": attrs_dict.get("event.type", event_data.get("event_type", "unknown")),
"init_timestamp": init_timestamp,
"end_timestamp": end_timestamp,
}

# Format event data based on event type
if event["event_type"] == "actions":
# Format event data based on category
if attrs_dict.get("event.category") == "actions":
# For action events, try multiple sources for action_type
action_type = (
attrs_dict.get("event.action_type") # Try direct attribute first
Expand Down

0 comments on commit 20dffe9

Please sign in to comment.