|
5 | 5 | from sqlalchemy import delete, insert, select
|
6 | 6 | from starlette.requests import Request
|
7 | 7 | from strawberry import UNSET, Info
|
| 8 | +from strawberry.relay import GlobalID |
8 | 9 |
|
9 | 10 | from phoenix.db import models
|
10 | 11 | from phoenix.server.api.auth import IsLocked, IsNotReadOnly
|
@@ -62,16 +63,13 @@ async def create_span_annotations(
|
62 | 63 |
|
63 | 64 | async with info.context.db() as session:
|
64 | 65 | 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: |
67 | 70 | # 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}" |
75 | 73 | values = {
|
76 | 74 | "span_rowid": span_rowid,
|
77 | 75 | "name": annotation_input.name,
|
|
0 commit comments