Skip to content

Commit 068ac7e

Browse files
fix(highlight-run): buffer worker messages instead of dropping them before initialization
1 parent c380b7e commit 068ac7e

6 files changed

Lines changed: 656 additions & 25 deletions

File tree

e2e/react-router/src/ldclientLazy.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
import { initialize as init } from 'launchdarkly-js-client-sdk'
1+
import { initialize as init, type LDContext } from 'launchdarkly-js-client-sdk'
22
import Observability, { LDObserve } from '@launchdarkly/observability'
33
import SessionReplay, { LDRecord } from '@launchdarkly/session-replay'
44

5+
const getContextFriendlyName = (context: LDContext): string | undefined => {
6+
if (context && 'kind' in context && context.kind === 'multi') {
7+
const multiContext = context as {
8+
kind: 'multi'
9+
user?: { key?: string }
10+
}
11+
return multiContext.user?.key
12+
}
13+
return undefined
14+
}
15+
516
const observabilitySettings: ConstructorParameters<typeof Observability>[0] = {
617
networkRecording: {
718
enabled: true,
819
recordHeadersAndBody: true,
920
},
1021
serviceName: 'ryan-test',
1122
version: 'my-version',
12-
backendUrl: 'http://localhost:8082/public',
23+
backendUrl: 'https://pub.observability.ld-stg.launchdarkly.com/',
1324
otel: {
14-
otlpEndpoint: 'http://localhost:4318',
25+
otlpEndpoint: 'https://otel.observability.ld-stg.launchdarkly.com:4318',
1526
},
1627
manualStart: true,
28+
contextFriendlyName: getContextFriendlyName,
1729
}
1830
const sessionReplaySettings: ConstructorParameters<typeof SessionReplay>[0] = {
1931
debug: { clientInteractions: true, domRecording: true },
@@ -23,18 +35,19 @@ const sessionReplaySettings: ConstructorParameters<typeof SessionReplay>[0] = {
2335
privacySetting: 'none',
2436
serviceName: 'ryan-test',
2537
version: 'my-version',
26-
backendUrl: 'http://localhost:8082/public',
38+
backendUrl: 'https://pub.observability.ld-stg.launchdarkly.com/',
2739
manualStart: true,
2840
enableCanvasRecording: true,
2941
samplingStrategy: {
3042
canvas: 2, // 2 fps
3143
canvasMaxSnapshotDimension: 720, // 720p quality
3244
},
45+
contextFriendlyName: getContextFriendlyName,
3346
}
3447

3548
export const client = init(
3649
'548f6741c1efad40031b18ae',
37-
{ key: 'unknown' },
50+
{ kind: 'user', anonymous: true },
3851
{
3952
// Not including plugins at all would be equivalent to the current LaunchDarkly SDK.
4053
plugins: [

e2e/react-router/src/routes/root.tsx

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,58 @@ export default function Root() {
380380
</div>
381381
</div>
382382

383+
<div
384+
style={{
385+
padding: 12,
386+
border: '1px solid #ddd',
387+
borderRadius: 6,
388+
maxWidth: 720,
389+
}}
390+
>
391+
<h3 style={{ marginTop: 0 }}>Identify User</h3>
392+
<p>
393+
Identify the current user via <code>client.identify()</code>
394+
.
395+
</p>
396+
<textarea
397+
id="identify-textarea"
398+
style={{
399+
width: '100%',
400+
minHeight: 120,
401+
fontFamily: 'monospace',
402+
}}
403+
defaultValue={JSON.stringify(
404+
{
405+
kind: 'multi',
406+
user: {
407+
key: 'test-user@example.com',
408+
name: 'Test User',
409+
},
410+
organization: {
411+
key: 'org-123',
412+
name: 'Test Org',
413+
},
414+
},
415+
null,
416+
2,
417+
)}
418+
placeholder='{"kind":"user","key":"user-key"}'
419+
/>
420+
<div style={{ display: 'flex', gap: 8, marginTop: 8 }}>
421+
<button
422+
onClick={() => {
423+
const textarea = document.querySelector(
424+
'#identify-textarea',
425+
) as HTMLTextAreaElement
426+
const value = textarea?.value ?? ''
427+
client.identify(JSON.parse(value))
428+
}}
429+
>
430+
Identify user
431+
</button>
432+
</div>
433+
</div>
434+
383435
<div
384436
style={{
385437
marginTop: 8,
@@ -389,15 +441,16 @@ export default function Root() {
389441
maxWidth: 720,
390442
}}
391443
>
392-
<h3>Session Properties</h3>
444+
<h3 style={{ marginTop: 0 }}>Session Properties</h3>
393445
<p>
394446
Add custom session-level attributes via{' '}
395447
<code>LDRecord.addSessionProperties</code>.
396448
</p>
397449
<textarea
450+
id="session-props-textarea"
398451
style={{
399452
width: '100%',
400-
minHeight: 120,
453+
minHeight: 40,
401454
fontFamily: 'monospace',
402455
}}
403456
defaultValue='{"plan":"pro","favoriteColor":"seafoam"}'
@@ -406,8 +459,10 @@ export default function Root() {
406459
<div style={{ display: 'flex', gap: 8, marginTop: 8 }}>
407460
<button
408461
onClick={() => {
409-
const value =
410-
document.querySelector('textarea')?.value ?? ''
462+
const textarea = document.querySelector(
463+
'#session-props-textarea',
464+
) as HTMLTextAreaElement
465+
const value = textarea?.value ?? ''
411466

412467
LDRecord.addSessionProperties(JSON.parse(value))
413468
}}

0 commit comments

Comments
 (0)