11import {
2+ accessoryAttributes ,
23 apiClientManager ,
4+ SemanticInternalAttributes ,
35 type ApiRequestOptions ,
46 type CreatePromptOverrideRequestBody ,
57 type ListPromptsResponseBody ,
68 type ListPromptVersionsResponseBody ,
79 type PromptOkResponseBody ,
810 type PromptOverrideCreatedResponseBody ,
9- type ResolvePromptResponseBody ,
1011 type UpdatePromptOverrideRequestBody ,
1112} from "@trigger.dev/core/v3" ;
1213import type { ResolvedPrompt } from "./prompt.js" ;
14+ import { tracer } from "./tracer.js" ;
15+
16+ function promptSpanOptions ( name : string , slug : string ) {
17+ return {
18+ tracer,
19+ name,
20+ icon : "tabler-file-text-ai" ,
21+ attributes : {
22+ [ SemanticInternalAttributes . STYLE_ICON ] : "tabler-file-text-ai" ,
23+ ...accessoryAttributes ( {
24+ items : [ { text : slug , variant : "normal" as const } ] ,
25+ style : "codepath" ,
26+ } ) ,
27+ } ,
28+ } ;
29+ }
1330
1431function makeToAISDKTelemetry (
1532 slug : string ,
@@ -49,11 +66,36 @@ export async function resolvePrompt(
4966) : Promise < ResolvedPrompt > {
5067 const apiClient = apiClientManager . clientOrThrow ( ) ;
5168 const vars = variables ?? { } ;
52- const response = await apiClient . resolvePrompt ( slug , {
53- variables : vars ,
54- label : options ?. label ,
55- version : options ?. version ,
56- } ) ;
69+ const response = await apiClient . resolvePrompt (
70+ slug ,
71+ {
72+ variables : vars ,
73+ label : options ?. label ,
74+ version : options ?. version ,
75+ } ,
76+ {
77+ ...promptSpanOptions ( "prompts.resolve()" , slug ) ,
78+ attributes : {
79+ [ SemanticInternalAttributes . STYLE_ICON ] : "tabler-file-text-ai" ,
80+ [ SemanticInternalAttributes . ENTITY_TYPE ] : "prompt" ,
81+ [ SemanticInternalAttributes . ENTITY_ID ] : slug ,
82+ ...accessoryAttributes ( {
83+ items : [ { text : slug , variant : "normal" as const } ] ,
84+ style : "codepath" ,
85+ } ) ,
86+ } ,
87+ onResponseBody : ( body , span ) => {
88+ span . setAttribute ( "prompt.version" , body . data . version ) ;
89+ span . setAttribute ( "prompt.slug" , body . data . slug ) ;
90+ span . setAttribute ( "prompt.labels" , body . data . labels . join ( ", " ) ) ;
91+ if ( body . data . model ) span . setAttribute ( "prompt.model" , body . data . model ) ;
92+ if ( body . data . text ) span . setAttribute ( "prompt.text" , body . data . text ) ;
93+ if ( vars && Object . keys ( vars ) . length > 0 ) {
94+ span . setAttribute ( "prompt.input" , JSON . stringify ( vars ) ) ;
95+ }
96+ } ,
97+ }
98+ ) ;
5799
58100 const data = response . data ;
59101 const inputJson = Object . keys ( vars ) . length > 0 ? JSON . stringify ( vars ) : undefined ;
@@ -81,7 +123,12 @@ export function listPrompts(
81123 requestOptions ?: ApiRequestOptions
82124) : Promise < ListPromptsResponseBody > {
83125 const apiClient = apiClientManager . clientOrThrow ( ) ;
84- return apiClient . listPrompts ( requestOptions ) ;
126+ return apiClient . listPrompts ( {
127+ ...promptSpanOptions ( "prompts.list()" , "all" ) ,
128+ onResponseBody : ( body , span ) => {
129+ span . setAttribute ( "prompt.count" , body . data . length ) ;
130+ } ,
131+ } ) ;
85132}
86133
87134/** List all versions for a prompt. */
@@ -90,7 +137,13 @@ export function listPromptVersions(
90137 requestOptions ?: ApiRequestOptions
91138) : Promise < ListPromptVersionsResponseBody > {
92139 const apiClient = apiClientManager . clientOrThrow ( ) ;
93- return apiClient . listPromptVersions ( slug , requestOptions ) ;
140+ return apiClient . listPromptVersions ( slug , {
141+ ...promptSpanOptions ( "prompts.versions()" , slug ) ,
142+ onResponseBody : ( body , span ) => {
143+ span . setAttribute ( "prompt.slug" , slug ) ;
144+ span . setAttribute ( "prompt.versions.count" , body . data . length ) ;
145+ } ,
146+ } ) ;
94147}
95148
96149/** Promote a code-deployed version to be the current version. */
@@ -100,7 +153,14 @@ export async function promotePromptVersion(
100153 requestOptions ?: ApiRequestOptions
101154) : Promise < PromptOkResponseBody > {
102155 const apiClient = apiClientManager . clientOrThrow ( ) ;
103- return apiClient . promotePromptVersion ( slug , { version } , requestOptions ) ;
156+ return apiClient . promotePromptVersion ( slug , { version } , {
157+ ...promptSpanOptions ( "prompts.promote()" , slug ) ,
158+ attributes : {
159+ ...promptSpanOptions ( "prompts.promote()" , slug ) . attributes ,
160+ "prompt.slug" : slug ,
161+ "prompt.version" : version ,
162+ } ,
163+ } ) ;
104164}
105165
106166/** Create an override — a dashboard/API edit that takes priority over the deployed version. */
@@ -110,7 +170,17 @@ export async function createPromptOverride(
110170 requestOptions ?: ApiRequestOptions
111171) : Promise < PromptOverrideCreatedResponseBody > {
112172 const apiClient = apiClientManager . clientOrThrow ( ) ;
113- return apiClient . createPromptOverride ( slug , body , requestOptions ) ;
173+ return apiClient . createPromptOverride ( slug , body , {
174+ ...promptSpanOptions ( "prompts.createOverride()" , slug ) ,
175+ attributes : {
176+ ...promptSpanOptions ( "prompts.createOverride()" , slug ) . attributes ,
177+ "prompt.slug" : slug ,
178+ ...( body . model ? { "prompt.model" : body . model } : { } ) ,
179+ } ,
180+ onResponseBody : ( body , span ) => {
181+ span . setAttribute ( "prompt.override.version" , body . version ) ;
182+ } ,
183+ } ) ;
114184}
115185
116186/** Update the active override's content or model. */
@@ -120,7 +190,13 @@ export async function updatePromptOverride(
120190 requestOptions ?: ApiRequestOptions
121191) : Promise < PromptOkResponseBody > {
122192 const apiClient = apiClientManager . clientOrThrow ( ) ;
123- return apiClient . updatePromptOverride ( slug , body , requestOptions ) ;
193+ return apiClient . updatePromptOverride ( slug , body , {
194+ ...promptSpanOptions ( "prompts.updateOverride()" , slug ) ,
195+ attributes : {
196+ ...promptSpanOptions ( "prompts.updateOverride()" , slug ) . attributes ,
197+ "prompt.slug" : slug ,
198+ } ,
199+ } ) ;
124200}
125201
126202/** Remove the active override, reverting to the current deployed version. */
@@ -129,7 +205,13 @@ export async function removePromptOverride(
129205 requestOptions ?: ApiRequestOptions
130206) : Promise < PromptOkResponseBody > {
131207 const apiClient = apiClientManager . clientOrThrow ( ) ;
132- return apiClient . removePromptOverride ( slug , requestOptions ) ;
208+ return apiClient . removePromptOverride ( slug , {
209+ ...promptSpanOptions ( "prompts.removeOverride()" , slug ) ,
210+ attributes : {
211+ ...promptSpanOptions ( "prompts.removeOverride()" , slug ) . attributes ,
212+ "prompt.slug" : slug ,
213+ } ,
214+ } ) ;
133215}
134216
135217/** Reactivate a previously removed override version. */
@@ -139,5 +221,12 @@ export async function reactivatePromptOverride(
139221 requestOptions ?: ApiRequestOptions
140222) : Promise < PromptOkResponseBody > {
141223 const apiClient = apiClientManager . clientOrThrow ( ) ;
142- return apiClient . reactivatePromptOverride ( slug , { version } , requestOptions ) ;
224+ return apiClient . reactivatePromptOverride ( slug , { version } , {
225+ ...promptSpanOptions ( "prompts.reactivateOverride()" , slug ) ,
226+ attributes : {
227+ ...promptSpanOptions ( "prompts.reactivateOverride()" , slug ) . attributes ,
228+ "prompt.slug" : slug ,
229+ "prompt.version" : version ,
230+ } ,
231+ } ) ;
143232}
0 commit comments