|
9 | 9 | import type { Log } from '../../../src/types-hoist/log'; |
10 | 10 | import * as loggerModule from '../../../src/utils-hoist/logger'; |
11 | 11 | import { getDefaultTestClientOptions, TestClient } from '../../mocks/client'; |
| 12 | +import { Replay } from '../../../../replay-internal/src/integration'; |
12 | 13 |
|
13 | 14 | const PUBLIC_DSN = 'https://username@domain/123'; |
14 | 15 |
|
@@ -155,6 +156,50 @@ describe('_INTERNAL_captureLog', () => { |
155 | 156 | }); |
156 | 157 | }); |
157 | 158 |
|
| 159 | + it('includes replay id in log attributes when available', async () => { |
| 160 | + |
| 161 | + let _initialized = false; |
| 162 | + class TestReplayIntegration extends Replay { |
| 163 | + protected get _isInitialized(): boolean { |
| 164 | + return _initialized; |
| 165 | + } |
| 166 | + protected set _isInitialized(value: boolean) { |
| 167 | + _initialized = value; |
| 168 | + } |
| 169 | + |
| 170 | + public afterAllSetup(): void { |
| 171 | + // do nothing, we need to manually initialize this |
| 172 | + } |
| 173 | + } |
| 174 | + const replayIntegration = new TestReplayIntegration(); |
| 175 | + const options = getDefaultTestClientOptions({ |
| 176 | + dsn: PUBLIC_DSN, |
| 177 | + _experiments: { enableLogs: true }, |
| 178 | + integrations: [replayIntegration], |
| 179 | + }); |
| 180 | + |
| 181 | + const client = new TestClient(options); |
| 182 | + |
| 183 | + replayIntegration['_setup'](client as any); |
| 184 | + replayIntegration['_initialize'](client as any); |
| 185 | + |
| 186 | + const scope = new Scope(); |
| 187 | + scope.setPropagationContext({ |
| 188 | + traceId: '3d9355f71e9c444b81161599adac6e29', |
| 189 | + sampleRand: 1, |
| 190 | + }); |
| 191 | + |
| 192 | + _INTERNAL_captureLog({ level: 'info', message: 'test log with replay id' }, client, scope); |
| 193 | + |
| 194 | + const logAttributes = _INTERNAL_getLogBuffer(client)?.[0]?.attributes; |
| 195 | + expect(logAttributes).toEqual({ |
| 196 | + 'sentry.replay_id': { |
| 197 | + value: '123', |
| 198 | + type: 'string', |
| 199 | + }, |
| 200 | + }); |
| 201 | + }); |
| 202 | + |
158 | 203 | it('includes SDK metadata in log attributes when available', () => { |
159 | 204 | const options = getDefaultTestClientOptions({ |
160 | 205 | dsn: PUBLIC_DSN, |
|
0 commit comments