MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / _INTERNAL_captureLog

Function _INTERNAL_captureLog

packages/core/src/logs/internal.ts:76–178  ·  view source on GitHub ↗
(
  beforeLog: Log,
  currentScope = getCurrentScope(),
  captureSerializedLog: (client: Client, log: SerializedLog) => void = _INTERNAL_captureSerializedLog,
)

Source from the content-addressed store, hash-verified

74 * the stable Sentry SDK API and can be changed or removed without warning.
75 */
76export 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) {

Callers 8

client.test.tsFile · 0.90
internal.test.tsFile · 0.90
setupFunction · 0.90
captureLogFunction · 0.90
logFunction · 0.90
captureLogFunction · 0.90
onPinoStartFunction · 0.90
captureLogFunction · 0.90

Calls 15

getCurrentScopeFunction · 0.90
getClientFunction · 0.90
_getTraceInfoFromScopeFunction · 0.90
getCombinedScopeDataFunction · 0.90
getIsolationScopeFunction · 0.90
isParameterizedStringFunction · 0.90
_getSpanForScopeFunction · 0.90
consoleSandboxFunction · 0.90
timestampInSecondsFunction · 0.90
getSequenceAttributeFunction · 0.90
serializeAttributesFunction · 0.90
setLogAttributeFunction · 0.85

Tested by

no test coverage detected