* Resolve live episode correlation attributes directly from runtime context. * * Prefer the canonical lineage fields propagated in aw_context: episode_id for * the full automation session, hop_id for the current workflow invocation, and * parent_hop_id for the immediate caller. Legacy workflow_c
(awInfo, runId, runAttempt)
| 232 | * @returns {Array<{key: string, value: object}>} |
| 233 | */ |
| 234 | function buildEpisodeAttributesFromContext(awInfo, runId, runAttempt) { |
| 235 | const currentHopId = buildCurrentWorkflowCallId(runId, runAttempt); |
| 236 | const inheritedHopId = readContextString(awInfo.context?.hop_id) || readContextString(awInfo.context?.workflow_call_id); |
| 237 | const episodeId = readContextString(awInfo.context?.episode_id) || inheritedHopId || currentHopId; |
| 238 | const parentHopId = readContextString(awInfo.context?.parent_hop_id) || (inheritedHopId && inheritedHopId !== currentHopId ? inheritedHopId : ""); |
| 239 | const originEvent = readContextString(awInfo.context?.origin_event) || readContextString(awInfo.context?.event_type); |
| 240 | const rootRepo = readContextString(awInfo.context?.root_repo) || readContextString(awInfo.context?.repo); |
| 241 | const rootWorkflowId = readContextString(awInfo.context?.root_workflow_id) || readContextString(awInfo.context?.workflow_id); |
| 242 | |
| 243 | if (!episodeId) { |
| 244 | return []; |
| 245 | } |
| 246 | |
| 247 | const attributes = [buildAttr("gh-aw.episode.id", episodeId), buildAttr("gh-aw.episode.kind", parentHopId ? "workflow_call" : "run")]; |
| 248 | |
| 249 | if (currentHopId) { |
| 250 | attributes.push(buildAttr("gh-aw.hop.id", currentHopId)); |
| 251 | attributes.push(buildAttr("gh-aw.workflow_call.id", currentHopId)); |
| 252 | } |
| 253 | if (parentHopId) { |
| 254 | attributes.push(buildAttr("gh-aw.hop.parent_id", parentHopId)); |
| 255 | attributes.push(buildAttr("gh-aw.workflow_call.parent_id", parentHopId)); |
| 256 | } |
| 257 | if (originEvent) { |
| 258 | attributes.push(buildAttr("gh-aw.origin.event", originEvent)); |
| 259 | } |
| 260 | if (rootRepo) { |
| 261 | attributes.push(buildAttr("gh-aw.root.repo", rootRepo)); |
| 262 | } |
| 263 | if (rootWorkflowId) { |
| 264 | attributes.push(buildAttr("gh-aw.root.workflow_id", rootWorkflowId)); |
| 265 | } |
| 266 | |
| 267 | return attributes; |
| 268 | } |
| 269 | |
| 270 | // --------------------------------------------------------------------------- |
| 271 | // OTLP SpanKind constants |
no test coverage detected