@@ -66,9 +66,10 @@ export class TriggerDevJobQueue implements JobQueueBackend {
6666 ? { ...payload , ...options . metadata }
6767 : payload
6868
69- const handle = await tasks . trigger ( taskId , enrichedPayload )
69+ const tags = buildTags ( type , options )
70+ const handle = await tasks . trigger ( taskId , enrichedPayload , tags . length > 0 ? { tags } : { } )
7071
71- logger . debug ( 'Enqueued job via trigger.dev' , { jobId : handle . id , type, taskId } )
72+ logger . debug ( 'Enqueued job via trigger.dev' , { jobId : handle . id , type, taskId, tags } )
7273 return handle . id
7374 }
7475
@@ -121,3 +122,33 @@ export class TriggerDevJobQueue implements JobQueueBackend {
121122
122123 async markJobFailed ( _jobId : string , _error : string ) : Promise < void > { }
123124}
125+
126+ /**
127+ * Derives trigger.dev tags from job type, metadata, and explicit tags.
128+ * Tags follow the `namespace:value` convention for consistent filtering.
129+ * Max 10 tags per run, each max 128 chars.
130+ */
131+ function buildTags ( type : JobType , options ?: EnqueueOptions ) : string [ ] {
132+ const tags : string [ ] = [ ]
133+ const meta = options ?. metadata
134+
135+ if ( meta ?. workspaceId ) tags . push ( `workspaceId:${ meta . workspaceId } ` )
136+ if ( meta ?. workflowId ) tags . push ( `workflowId:${ meta . workflowId } ` )
137+ if ( meta ?. userId ) tags . push ( `userId:${ meta . userId } ` )
138+
139+ if ( meta ?. correlation ) {
140+ const c = meta . correlation
141+ tags . push ( `source:${ c . source } ` )
142+ if ( c . webhookId ) tags . push ( `webhookId:${ c . webhookId } ` )
143+ if ( c . scheduleId ) tags . push ( `scheduleId:${ c . scheduleId } ` )
144+ if ( c . provider ) tags . push ( `provider:${ c . provider } ` )
145+ }
146+
147+ if ( options ?. tags ) {
148+ for ( const tag of options . tags ) {
149+ if ( ! tags . includes ( tag ) ) tags . push ( tag )
150+ }
151+ }
152+
153+ return tags . slice ( 0 , 10 )
154+ }
0 commit comments