Skip to content

Commit 9cedbe7

Browse files
committed
turn on dogfooding of ld client integration (#10137)
Enable client integration. local deploy ![image](https://github.com/user-attachments/assets/6e21a477-2833-4c75-9174-6f3965f01f29) no no
1 parent 7466f86 commit 9cedbe7

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

.changeset/flat-feet-unite.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+
improve LD sdk integration to report context

sdk/highlight-run/src/client/types/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ErrorMessageType, Source } from './shared-types'
1212
import { LDClientMin } from '../../integrations/launchdarkly/types/LDClient'
1313

1414
export declare interface Metadata {
15-
[key: string]: string | boolean | number
15+
[key: string]: any
1616
}
1717

1818
export declare interface Metric {

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

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ import {
77
IdentifySeriesResult,
88
} from './types/Hooks'
99
import { trace } from '@opentelemetry/api'
10-
import type { HighlightPublicInterface } from '../../client/types/types'
10+
import { type HighlightPublicInterface, MetricCategory } from '../../client'
1111
import type { ErrorMessage, Source } from '../../client/types/shared-types'
12-
import { IntegrationClient } from '../index'
13-
import { LDClientMin } from './types/LDClient'
12+
import type { IntegrationClient } from '../index'
13+
import type { LDClientMin } from './types/LDClient'
14+
import type { RecordMetric } from '../../client/types/types'
1415

1516
const FEATURE_FLAG_SCOPE = 'feature_flag'
17+
// TODO(vkorolik) reporting environment as `${FEATURE_FLAG_SCOPE}.set.id`
1618
const FEATURE_FLAG_KEY_ATTR = `${FEATURE_FLAG_SCOPE}.key`
17-
const FEATURE_FLAG_PROVIDER_ATTR = `${FEATURE_FLAG_SCOPE}.provider_name`
19+
const FEATURE_FLAG_PROVIDER_ATTR = `${FEATURE_FLAG_SCOPE}.provider.name`
1820
const FEATURE_FLAG_CONTEXT_KEY_ATTR = `${FEATURE_FLAG_SCOPE}.context.key`
19-
const FEATURE_FLAG_VARIANT_ATTR = `${FEATURE_FLAG_SCOPE}.variant`
21+
const FEATURE_FLAG_VARIANT_ATTR = `${FEATURE_FLAG_SCOPE}.result.variant`
2022
const FEATURE_FLAG_SPAN_NAME = 'evaluation'
2123

24+
const LD_INITIALIZE_EVENT = '$ld:telemetry:initialize'
2225
const LD_ERROR_EVENT = '$ld:telemetry:error'
2326
const LD_TRACK_EVENT = '$ld:telemetry:track'
27+
const LD_METRIC_EVENT = '$ld:telemetry:metric'
2428

2529
function encodeKey(key: string): string {
2630
if (key.includes('%') || key.includes(':')) {
@@ -64,7 +68,7 @@ export function setupLaunchDarklyIntegration(
6468
) => {
6569
hClient.identify(
6670
getCanonicalKey(hookContext.context),
67-
undefined,
71+
hookContext.context,
6872
'LaunchDarkly',
6973
)
7074
return data
@@ -107,6 +111,31 @@ export class LaunchDarklyIntegration implements IntegrationClient {
107111
this.client = client
108112
}
109113

114+
init(sessionSecureID: string) {
115+
this.client.track(LD_INITIALIZE_EVENT, {
116+
sessionSecureID,
117+
})
118+
}
119+
120+
recordMetric(sessionSecureID: string, metric: RecordMetric) {
121+
// only record web vitals
122+
if (metric.category !== MetricCategory.WebVital) {
123+
return
124+
}
125+
// ignore Jank metric, sent on interaction
126+
if (metric.name === 'Jank') {
127+
return
128+
}
129+
this.client.track(
130+
`${LD_METRIC_EVENT}:${metric.name.toLowerCase()}`,
131+
{
132+
...metric,
133+
sessionSecureID,
134+
},
135+
metric.value,
136+
)
137+
}
138+
110139
identify(
111140
_sessionSecureID: string,
112141
_user_identifier: string,
@@ -124,9 +153,17 @@ export class LaunchDarklyIntegration implements IntegrationClient {
124153
}
125154

126155
track(sessionSecureID: string, metadata: object) {
127-
this.client.track(LD_TRACK_EVENT, {
128-
...metadata,
129-
sessionSecureID,
130-
})
156+
const event = (metadata as unknown as { event?: string }).event
157+
// skip integration hClient.track() calls
158+
if (event === FEATURE_FLAG_SPAN_NAME) {
159+
return
160+
}
161+
this.client.track(
162+
event ? `${LD_TRACK_EVENT}:${event}` : LD_TRACK_EVENT,
163+
{
164+
...metadata,
165+
sessionSecureID,
166+
},
167+
)
131168
}
132169
}

0 commit comments

Comments
 (0)