( eventName: string, attributes: Record<string, string | number | boolean>, )
| 745 | * Truncates content if it exceeds MAX_CONTENT_SIZE. |
| 746 | */ |
| 747 | export function addToolContentEvent( |
| 748 | eventName: string, |
| 749 | attributes: Record<string, string | number | boolean>, |
| 750 | ): void { |
| 751 | if (!isAnyTracingEnabled() || !isToolContentLoggingEnabled()) { |
| 752 | return |
| 753 | } |
| 754 | |
| 755 | const currentSpanCtx = toolContext.getStore() |
| 756 | if (!currentSpanCtx) { |
| 757 | return |
| 758 | } |
| 759 | |
| 760 | // Truncate string attributes that might be large |
| 761 | const processedAttributes: Record<string, string | number | boolean> = {} |
| 762 | for (const [key, value] of Object.entries(attributes)) { |
| 763 | if (typeof value === 'string') { |
| 764 | const { content, truncated } = truncateContent(value) |
| 765 | processedAttributes[key] = content |
| 766 | if (truncated) { |
| 767 | processedAttributes[`${key}_truncated`] = true |
| 768 | processedAttributes[`${key}_original_length`] = value.length |
| 769 | } |
| 770 | } else { |
| 771 | processedAttributes[key] = value |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | currentSpanCtx.span.addEvent(eventName, processedAttributes) |
| 776 | } |
| 777 | |
| 778 | export function getCurrentSpan(): Span | null { |
| 779 | if (!isAnyTracingEnabled()) { |
no test coverage detected