(
span: Span,
metadata?: {
numSuccess?: number
numBlocking?: number
numNonBlockingError?: number
numCancelled?: number
},
)
| 885 | * @param metadata The outcome metadata for the hook execution |
| 886 | */ |
| 887 | export function endHookSpan( |
| 888 | span: Span, |
| 889 | metadata?: { |
| 890 | numSuccess?: number |
| 891 | numBlocking?: number |
| 892 | numNonBlockingError?: number |
| 893 | numCancelled?: number |
| 894 | }, |
| 895 | ): void { |
| 896 | if (!isBetaTracingEnabled()) { |
| 897 | return |
| 898 | } |
| 899 | |
| 900 | const spanId = getSpanId(span) |
| 901 | const spanContext = activeSpans.get(spanId)?.deref() |
| 902 | |
| 903 | if (!spanContext) { |
| 904 | return |
| 905 | } |
| 906 | |
| 907 | const duration = Date.now() - spanContext.startTime |
| 908 | const endAttributes: Record<string, string | number | boolean> = { |
| 909 | duration_ms: duration, |
| 910 | } |
| 911 | |
| 912 | if (metadata) { |
| 913 | if (metadata.numSuccess !== undefined) |
| 914 | endAttributes['num_success'] = metadata.numSuccess |
| 915 | if (metadata.numBlocking !== undefined) |
| 916 | endAttributes['num_blocking'] = metadata.numBlocking |
| 917 | if (metadata.numNonBlockingError !== undefined) |
| 918 | endAttributes['num_non_blocking_error'] = metadata.numNonBlockingError |
| 919 | if (metadata.numCancelled !== undefined) |
| 920 | endAttributes['num_cancelled'] = metadata.numCancelled |
| 921 | } |
| 922 | |
| 923 | spanContext.span.setAttributes(endAttributes) |
| 924 | spanContext.span.end() |
| 925 | activeSpans.delete(spanId) |
| 926 | strongSpans.delete(spanId) |
| 927 | } |
| 928 |
no test coverage detected