Skip to content

Commit 24ff099

Browse files
authored
Handle identify status in hooks. (#60)
## Summary Context data from identify should only be set when the identify completed successfully. <!-- Ideally, there is an attached GitHub issue that will describe the "why". If relevant, use this section to call out any additional information you'd like to _highlight_ to the reviewer. --> ## How did you test this change? <!-- Frontend - Leave a screencast or a screenshot to visually describe the changes. --> ## Are there any deployment considerations? <!-- Backend - Do we need to consider migrations or backfilling data? --> ## Does this work require review from our design team? <!-- Request review from julian-highlight / our design team -->
1 parent 70a6018 commit 24ff099

File tree

4 files changed

+40
-26
lines changed

4 files changed

+40
-26
lines changed

.changeset/purple-needles-sing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'highlight.run': patch
3+
---
4+
5+
Only add context data for successful identify operations.

sdk/highlight-run/src/integrations/launchdarkly/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export const LD_METRIC_EVENT = '$ld:telemetry:metric'
4141

4242
export const LD_METRIC_NAME_DOCUMENT_LOAD = 'document_load'
4343

44+
export const LD_IDENTIFY_RESULT_STATUS = 'result.status'
45+
4446
function encodeKey(key: string): string {
4547
if (key.includes('%') || key.includes(':')) {
4648
return key.replace(/%/g, '%25').replace(/:/g, '%3A')
@@ -94,20 +96,23 @@ export function setupLaunchDarklyIntegration(
9496
name: 'highlight.run',
9597
}
9698
},
97-
afterIdentify: (hookContext, data, _result) => {
99+
afterIdentify: (hookContext, data, result) => {
98100
hClient.log('LD.identify', 'INFO', {
99101
key: getCanonicalKey(hookContext.context),
100102
context: JSON.stringify(getCanonicalObj(hookContext.context)),
101103
timeout: hookContext.timeout,
104+
[LD_IDENTIFY_RESULT_STATUS]: result.status,
102105
})
103-
hClient.identify(
104-
getCanonicalKey(hookContext.context),
105-
{
106-
key: getCanonicalKey(hookContext.context),
107-
timeout: hookContext.timeout,
108-
},
109-
'LaunchDarkly',
110-
)
106+
if (result.status === 'completed') {
107+
hClient.identify(
108+
getCanonicalKey(hookContext.context),
109+
{
110+
key: getCanonicalKey(hookContext.context),
111+
timeout: hookContext.timeout,
112+
},
113+
'LaunchDarkly',
114+
)
115+
}
111116
return data
112117
},
113118
afterEvaluation: (hookContext, data, detail) => {

sdk/highlight-run/src/plugins/observe.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
getCanonicalKey,
1616
getCanonicalObj,
1717
Hook,
18+
LD_IDENTIFY_RESULT_STATUS,
1819
LDClient,
1920
} from '../integrations/launchdarkly'
2021
import { Observe as ObserveAPI } from '../api/observe'
@@ -115,10 +116,10 @@ export class Observe extends Plugin<ObserveOptions> implements LDPlugin {
115116
name: '@launchdarkly/observability/hooks',
116117
}
117118
},
118-
afterIdentify: (hookContext, data, _result) => {
119+
afterIdentify: (hookContext, data, result) => {
119120
for (const hook of this.observe?.getHooks?.(metadata) ??
120121
[]) {
121-
hook.afterIdentify?.(hookContext, data, _result)
122+
hook.afterIdentify?.(hookContext, data, result)
122123
}
123124

124125
this.observe?.recordLog('LD.identify', 'info', {
@@ -128,6 +129,7 @@ export class Observe extends Plugin<ObserveOptions> implements LDPlugin {
128129
getCanonicalObj(hookContext.context),
129130
),
130131
timeout: hookContext.timeout,
132+
[LD_IDENTIFY_RESULT_STATUS]: result.status,
131133
})
132134
return data
133135
},

sdk/highlight-run/src/plugins/record.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,26 @@ export class Record extends Plugin<RecordOptions> implements LDPlugin {
102102
name: '@launchdarkly/session-replay/hooks',
103103
}
104104
},
105-
afterIdentify: (hookContext, data, _result) => {
105+
afterIdentify: (hookContext, data, result) => {
106106
for (const hook of this.record?.getHooks?.(metadata) ??
107107
[]) {
108-
hook.afterIdentify?.(hookContext, data, _result)
108+
hook.afterIdentify?.(hookContext, data, result)
109+
}
110+
if (result.status === 'completed') {
111+
const key = getCanonicalKey(hookContext.context)
112+
const obj = getCanonicalObj(hookContext.context)
113+
this.record?.identify(
114+
typeof obj === 'string'
115+
? obj
116+
: (obj['user']?.toString() ?? key),
117+
{
118+
key,
119+
...(typeof obj === 'object' ? obj : {}),
120+
timeout: hookContext.timeout,
121+
},
122+
'LaunchDarkly',
123+
)
109124
}
110-
const key = getCanonicalKey(hookContext.context)
111-
const obj = getCanonicalObj(hookContext.context)
112-
this.record?.identify(
113-
typeof obj === 'string'
114-
? obj
115-
: (obj['user']?.toString() ?? key),
116-
{
117-
key,
118-
...(typeof obj === 'object' ? obj : {}),
119-
timeout: hookContext.timeout,
120-
},
121-
'LaunchDarkly',
122-
)
123125
return data
124126
},
125127
afterEvaluation: (hookContext, data, detail) => {

0 commit comments

Comments
 (0)