MCPcopy Index your code
hub / github.com/simstudioai/sim / createOTelSpansForWorkflowExecution

Function createOTelSpansForWorkflowExecution

apps/sim/lib/core/telemetry.ts:328–388  ·  view source on GitHub ↗
(params: {
  workflowId: string
  workflowName?: string
  executionId: string
  traceSpans: TraceSpan[]
  trigger: string
  startTime: string
  endTime: string
  totalDurationMs: number
  status: 'success' | 'error'
  error?: string
})

Source from the content-addressed store, hash-verified

326 * This is called from LoggingSession.complete() with the final trace spans
327 */
328export function createOTelSpansForWorkflowExecution(params: {
329 workflowId: string
330 workflowName?: string
331 executionId: string
332 traceSpans: TraceSpan[]
333 trigger: string
334 startTime: string
335 endTime: string
336 totalDurationMs: number
337 status: 'success' | 'error'
338 error?: string
339}): void {
340 try {
341 const tracer = getTracer()
342
343 const rootSpan = tracer.startSpan(
344 'gen_ai.workflow.execute',
345 {
346 attributes: {
347 [GenAIAttributes.WORKFLOW_ID]: params.workflowId,
348 [GenAIAttributes.WORKFLOW_NAME]: params.workflowName || params.workflowId,
349 [GenAIAttributes.WORKFLOW_EXECUTION_ID]: params.executionId,
350 [TraceAttr.WorkflowTrigger]: params.trigger,
351 [TraceAttr.WorkflowDurationMs]: params.totalDurationMs,
352 },
353 startTime: new Date(params.startTime),
354 },
355 context.active()
356 )
357
358 if (params.status === 'error') {
359 rootSpan.setStatus({
360 code: SpanStatusCode.ERROR,
361 message: params.error || 'Workflow execution failed',
362 })
363 if (params.error) {
364 rootSpan.recordException(new Error(params.error))
365 }
366 } else {
367 rootSpan.setStatus({ code: SpanStatusCode.OK })
368 }
369
370 for (const traceSpan of params.traceSpans) {
371 createOTelSpanFromTraceSpan(traceSpan, rootSpan)
372 }
373
374 rootSpan.end(new Date(params.endTime))
375
376 logger.debug('Created OTel spans for workflow execution', {
377 workflowId: params.workflowId,
378 executionId: params.executionId,
379 spanCount: params.traceSpans.length,
380 })
381 } catch (error) {
382 logger.error('Failed to create OTel spans for workflow execution', {
383 error,
384 workflowId: params.workflowId,
385 executionId: params.executionId,

Callers

nothing calls this directly

Calls 5

startSpanMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80
getTracerFunction · 0.70

Tested by

no test coverage detected