( beforeLog: Log, currentScope = getCurrentScope(), captureSerializedLog: (client: Client, log: SerializedLog) => void = _INTERNAL_captureSerializedLog, )
| 74 | * the stable Sentry SDK API and can be changed or removed without warning. |
| 75 | */ |
| 76 | export function _INTERNAL_captureLog( |
| 77 | beforeLog: Log, |
| 78 | currentScope = getCurrentScope(), |
| 79 | captureSerializedLog: (client: Client, log: SerializedLog) => void = _INTERNAL_captureSerializedLog, |
| 80 | ): void { |
| 81 | const client = currentScope?.getClient() ?? getClient(); |
| 82 | if (!client) { |
| 83 | DEBUG_BUILD && debug.warn('No client available to capture log.'); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | const { release, environment, enableLogs = false, beforeSendLog } = client.getOptions(); |
| 88 | if (!enableLogs) { |
| 89 | DEBUG_BUILD && debug.warn('logging option not enabled, log will not be captured.'); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | const [, traceContext] = _getTraceInfoFromScope(client, currentScope); |
| 94 | |
| 95 | const processedLogAttributes = { |
| 96 | ...beforeLog.attributes, |
| 97 | }; |
| 98 | |
| 99 | const { |
| 100 | user: { id, email, username }, |
| 101 | attributes: scopeAttributes = {}, |
| 102 | } = getCombinedScopeData(getIsolationScope(), currentScope); |
| 103 | |
| 104 | setLogAttribute(processedLogAttributes, 'user.id', id, false); |
| 105 | setLogAttribute(processedLogAttributes, 'user.email', email, false); |
| 106 | setLogAttribute(processedLogAttributes, 'user.name', username, false); |
| 107 | |
| 108 | setLogAttribute(processedLogAttributes, 'sentry.release', release); |
| 109 | setLogAttribute(processedLogAttributes, 'sentry.environment', environment); |
| 110 | |
| 111 | const { name, version } = client.getSdkMetadata()?.sdk ?? {}; |
| 112 | setLogAttribute(processedLogAttributes, 'sentry.sdk.name', name); |
| 113 | setLogAttribute(processedLogAttributes, 'sentry.sdk.version', version); |
| 114 | |
| 115 | const replay = client.getIntegrationByName< |
| 116 | Integration & { |
| 117 | getReplayId: (onlyIfSampled?: boolean) => string; |
| 118 | getRecordingMode: () => 'session' | 'buffer' | undefined; |
| 119 | } |
| 120 | >('Replay'); |
| 121 | |
| 122 | const replayId = replay?.getReplayId(true); |
| 123 | setLogAttribute(processedLogAttributes, 'sentry.replay_id', replayId); |
| 124 | |
| 125 | if (replayId && replay?.getRecordingMode() === 'buffer') { |
| 126 | // We send this so we can identify cases where the replayId is attached but the replay itself might not have been sent to Sentry |
| 127 | setLogAttribute(processedLogAttributes, 'sentry._internal.replay_is_buffering', true); |
| 128 | } |
| 129 | |
| 130 | const beforeLogMessage = beforeLog.message; |
| 131 | if (isParameterizedString(beforeLogMessage)) { |
| 132 | const { __sentry_template_string__, __sentry_template_values__ = [] } = beforeLogMessage; |
| 133 | if (__sentry_template_values__?.length) { |
no test coverage detected