( blockType: string, blockId: string, blockName: string, fn: (span: Span) => Promise<T> )
| 392 | * Can be called from block handlers during execution for real-time tracing |
| 393 | */ |
| 394 | export async function traceBlockExecution<T>( |
| 395 | blockType: string, |
| 396 | blockId: string, |
| 397 | blockName: string, |
| 398 | fn: (span: Span) => Promise<T> |
| 399 | ): Promise<T> { |
| 400 | const tracer = getTracer() |
| 401 | |
| 402 | const blockMapping = BLOCK_TYPE_MAPPING[blockType] || { |
| 403 | spanName: `block.${blockType}`, |
| 404 | spanKind: 'internal', |
| 405 | getAttributes: () => ({}), |
| 406 | } |
| 407 | |
| 408 | return tracer.startActiveSpan( |
| 409 | blockMapping.spanName, |
| 410 | { |
| 411 | attributes: { |
| 412 | [TraceAttr.BlockType]: blockType, |
| 413 | [TraceAttr.BlockId]: blockId, |
| 414 | [TraceAttr.BlockName]: blockName, |
| 415 | }, |
| 416 | }, |
| 417 | async (span) => { |
| 418 | try { |
| 419 | const result = await fn(span) |
| 420 | span.setStatus({ code: SpanStatusCode.OK }) |
| 421 | return result |
| 422 | } catch (error) { |
| 423 | span.setStatus({ |
| 424 | code: SpanStatusCode.ERROR, |
| 425 | message: getErrorMessage(error, 'Block execution failed'), |
| 426 | }) |
| 427 | span.recordException(toError(error)) |
| 428 | throw error |
| 429 | } finally { |
| 430 | span.end() |
| 431 | } |
| 432 | } |
| 433 | ) |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * Track platform events (workflow creation, knowledge base operations, etc.) |
nothing calls this directly
no test coverage detected