Skip to content

Commit a84379c

Browse files
committed
span annotation mutations
1 parent e9ead03 commit a84379c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/phoenix/server/api/mutations/span_annotations_mutations.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from sqlalchemy import delete, insert, select
66
from starlette.requests import Request
77
from strawberry import UNSET, Info
8+
from strawberry.relay import GlobalID
89

910
from phoenix.db import models
1011
from phoenix.server.api.auth import IsLocked, IsNotReadOnly
@@ -62,16 +63,13 @@ async def create_span_annotations(
6263

6364
async with info.context.db() as session:
6465
for idx, (span_rowid, annotation_input) in enumerate(zip(span_rowids, input)):
65-
resolved_identifier = annotation_input.identifier or ""
66-
if annotation_input.source == AnnotationSource.APP:
66+
resolved_identifier = ""
67+
if annotation_input.identifier:
68+
resolved_identifier = annotation_input.identifier
69+
elif annotation_input.source == AnnotationSource.APP and user_id is not None:
6770
# Ensure that the annotation has a per-user identifier if submitted via the UI
68-
if user_id is not None:
69-
username = await session.scalar(
70-
select(models.User.username).where(models.User.id == user_id)
71-
)
72-
resolved_identifier = f"px-app:{username}"
73-
else:
74-
resolved_identifier = "px-app"
71+
user_gid = str(GlobalID(type_name="User", node_id=str(user_id)))
72+
resolved_identifier = f"px-app:{user_gid}"
7573
values = {
7674
"span_rowid": span_rowid,
7775
"name": annotation_input.name,

0 commit comments

Comments
 (0)