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
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
"gen_ai.cost.total_tokens",
"gen_ai.operation.name",
"gen_ai.operation.type",
"gen_ai.memory.store.id",
"gen_ai.memory.query.text",
"gen_ai.memory.record.id",
"gen_ai.memory.record.count",
"gen_ai.input.messages",
"gen_ai.output.messages",
"gen_ai.system_instructions",
Expand Down
5 changes: 5 additions & 0 deletions src/sentry/search/eap/spans/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@
internal_name="gen_ai.cost.total_tokens",
search_type="currency",
),
ResolvedAttribute(
public_alias="gen_ai.memory.record.count",
internal_name="gen_ai.memory.record.count",
search_type="integer",
),
Comment on lines +304 to +308

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we not need to add the other attributes?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

agree, this shouldn't be needed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we needed it in the past for charts to return the right data type via the timeseries endpoint.
Is that not a thing anymore / utilizing conventions?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe I am wrong, but from what I saw non-string attributes still need this, and in fact it fails atm without it.
The related conventions are not released yet. Once they are I will follow-up on this.

ResolvedAttribute(
public_alias="gen_ai.request.reasoning.level",
internal_name="gen_ai.request.reasoning.level",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,40 @@ def test_conversation_not_found(self) -> None:
)
assert response.data["spans"] == []

def test_memory_span_attributes(self) -> None:
now = before_now(days=20).replace(microsecond=0)
conversation_id = uuid4().hex

self.store_ai_span(
conversation_id=conversation_id,
timestamp=now,
op="gen_ai.search_memory",
operation_name="search_memory",
operation_type="memory",
memory_store_id="user-prefs",
memory_query_text="dietary preferences",
memory_record_id="mem_123",
memory_record_count=3,
trace_id=uuid4().hex,
)

query = {
"project": [self.project.id],
"start": (now - timedelta(hours=1)).isoformat(),
"end": (now + timedelta(hours=1)).isoformat(),
}

response = self.do_request(conversation_id, query)
assert response.status_code == 200
assert len(response.data["spans"]) == 1

span = response.data["spans"][0]
assert span["gen_ai.operation.name"] == "search_memory"
assert span["gen_ai.memory.store.id"] == "user-prefs"
assert span["gen_ai.memory.query.text"] == "dietary preferences"
assert span["gen_ai.memory.record.id"] == "mem_123"
assert span["gen_ai.memory.record.count"] == 3

def test_single_trace_conversation(self) -> None:
now = before_now(days=20).replace(microsecond=0)
trace_id = uuid4().hex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def store_ai_span(
tool_result=None,
tool_output=None,
embeddings_input=None,
memory_store_id=None,
memory_query_text=None,
memory_record_id=None,
memory_record_count=None,
user_id=None,
user_email=None,
user_username=None,
Expand Down Expand Up @@ -144,6 +148,14 @@ def store_ai_span(
span_data["gen_ai.tool.output"] = tool_output
if embeddings_input is not None:
span_data["gen_ai.embeddings.input"] = embeddings_input
if memory_store_id is not None:
span_data["gen_ai.memory.store.id"] = memory_store_id
if memory_query_text is not None:
span_data["gen_ai.memory.query.text"] = memory_query_text
if memory_record_id is not None:
span_data["gen_ai.memory.record.id"] = memory_record_id
if memory_record_count is not None:
span_data["gen_ai.memory.record.count"] = memory_record_count
# New format attributes
if input_messages is not None:
span_data["gen_ai.input.messages"] = json.dumps(input_messages)
Expand Down
Loading