* Process the matching `beforeSendXXX` callback.
( client: Client, options: ClientOptions, event: Event, hint: EventHint, )
| 1644 | * Process the matching `beforeSendXXX` callback. |
| 1645 | */ |
| 1646 | function processBeforeSend( |
| 1647 | client: Client, |
| 1648 | options: ClientOptions, |
| 1649 | event: Event, |
| 1650 | hint: EventHint, |
| 1651 | ): PromiseLike<Event | null> | Event | null { |
| 1652 | const { beforeSend, beforeSendTransaction, ignoreSpans } = options; |
| 1653 | const beforeSendSpan = !isStreamedBeforeSendSpanCallback(options.beforeSendSpan) && options.beforeSendSpan; |
| 1654 | |
| 1655 | let processedEvent = event; |
| 1656 | |
| 1657 | if (isErrorEvent(processedEvent) && beforeSend) { |
| 1658 | return beforeSend(processedEvent, hint); |
| 1659 | } |
| 1660 | |
| 1661 | if (isTransactionEvent(processedEvent)) { |
| 1662 | // Avoid processing if we don't have to |
| 1663 | if (beforeSendSpan || ignoreSpans) { |
| 1664 | // 1. Process root span |
| 1665 | const rootSpanJson = convertTransactionEventToSpanJson(processedEvent); |
| 1666 | |
| 1667 | // 1.1 If the root span should be ignored, drop the whole transaction |
| 1668 | if ( |
| 1669 | ignoreSpans?.length && |
| 1670 | shouldIgnoreSpan( |
| 1671 | { description: rootSpanJson.description, op: rootSpanJson.op, attributes: rootSpanJson.data }, |
| 1672 | ignoreSpans, |
| 1673 | ) |
| 1674 | ) { |
| 1675 | // dropping the whole transaction! |
| 1676 | return null; |
| 1677 | } |
| 1678 | |
| 1679 | // 1.2 If a `beforeSendSpan` callback is defined, process the root span |
| 1680 | if (beforeSendSpan) { |
| 1681 | const processedRootSpanJson = beforeSendSpan(rootSpanJson); |
| 1682 | if (!processedRootSpanJson) { |
| 1683 | showSpanDropWarning(); |
| 1684 | } else { |
| 1685 | // update event with processed root span values |
| 1686 | processedEvent = merge(event, convertSpanJsonToTransactionEvent(processedRootSpanJson)); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | // 2. Process child spans |
| 1691 | if (processedEvent.spans) { |
| 1692 | const processedSpans: SpanJSON[] = []; |
| 1693 | |
| 1694 | const initialSpans = processedEvent.spans; |
| 1695 | |
| 1696 | for (const span of initialSpans) { |
| 1697 | // 2.a If the child span should be ignored, reparent it to the root span |
| 1698 | if ( |
| 1699 | ignoreSpans?.length && |
| 1700 | shouldIgnoreSpan({ description: span.description, op: span.op, attributes: span.data }, ignoreSpans) |
| 1701 | ) { |
| 1702 | reparentChildSpans(initialSpans, span); |
| 1703 | continue; |
no test coverage detected