Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/highlight-run/src/client/otel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
]
if (documentLoadConfig !== false) {
instrumentations.push(
// TODO(vkorolik) hooks for this to LD integration
new DocumentLoadInstrumentation({
applyCustomAttributesOnSpan: {
documentLoad: assignDocumentDurations,
Expand Down
2 changes: 2 additions & 0 deletions sdk/highlight-run/src/client/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@
fn: F,
): ReturnType<F>
}
// TODO(vkorolik) log fn, H.track should log,
// TODO(vkorolik) secure session id propagatiion on logs
/**
* Starts a new span for tracing in Highlight. The span will be ended when the
* `end()` is called on the span. It returns whatever is returned from the
Expand Down
104 changes: 0 additions & 104 deletions sdk/highlight-run/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,110 +512,6 @@ const H: HighlightPublicInterface = {
)
}
},
getSessionURL: () => {
return new Promise((resolve, reject) => {
H.onHighlightReady(() => {
const secureID = highlight_obj.sessionData.sessionSecureID
const data = getPreviousSessionData(secureID)

if (data) {
resolve(
`https://${HIGHLIGHT_URL}/${data.projectID}/sessions/${secureID}`,
)
} else {
reject(new Error(`Unable to get session URL: ${secureID}`))
}
})
})
},
getSessionDetails: () => {
return new Promise((resolve, reject) => {
H.onHighlightReady(async () => {
try {
const baseUrl = await H.getSessionURL()
if (!baseUrl) {
throw new Error('Could not get session URL')
}

const secureID = highlight_obj.sessionData.sessionSecureID
const sessionData = getPreviousSessionData(secureID)
const currentSessionTimestamp =
sessionData?.sessionStartTime
if (!currentSessionTimestamp) {
throw new Error('Could not get session start timestamp')
}

const now = new Date().getTime()
const url = new URL(baseUrl)
const urlWithTimestamp = new URL(baseUrl)
urlWithTimestamp.searchParams.set(
'ts',
((now - currentSessionTimestamp) / 1000).toString(),
)

resolve({
url: url.toString(),
urlWithTimestamp: urlWithTimestamp.toString(),
sessionSecureID: secureID,
} as SessionDetails)
} catch (error) {
reject(error)
}
})
})
},
getRecordingState: () => {
return highlight_obj?.state ?? 'NotRecording'
},
onHighlightReady: (func, options) => {
// Run the callback immediately if Highlight is already ready
if (highlight_obj && highlight_obj.ready) {
func()
return
}

onHighlightReadyQueue.push({ options, func })

if (onHighlightReadyTimeout !== undefined) {
return
}

const processQueue = () => {
const newQueue = onHighlightReadyQueue.filter((item) => {
if (
!highlight_obj ||
(item.options?.waitForReady !== false &&
!highlight_obj.ready)
) {
return true
}

item.func()
return false
})

onHighlightReadyQueue = newQueue
onHighlightReadyTimeout = undefined

if (onHighlightReadyQueue.length > 0) {
onHighlightReadyTimeout = setTimeout(
processQueue,
READY_WAIT_LOOP_MS,
)
}
}

processQueue()
},
registerLD(client) {
// TODO(vkorolik): consolidate once firstload/client are merged
// client integration necessary to track events from ErrorListener
H.onHighlightReady(() => {
highlight_obj.registerLD(client)
})
// firstload integration necessary to immediately capture ld.identify
setupLaunchDarklyIntegration(this, client)
},
}

if (typeof window !== 'undefined') {
Expand Down
23 changes: 6 additions & 17 deletions sdk/highlight-run/src/integrations/launchdarkly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
IdentifySeriesData,
IdentifySeriesResult,
} from './types/Hooks'
import { trace } from '@opentelemetry/api'
import { type HighlightPublicInterface, MetricCategory } from '../../client'
import type { ErrorMessage, Source } from '../../client/types/shared-types'
import type { IntegrationClient } from '../index'
Expand Down Expand Up @@ -66,6 +65,7 @@ export function setupLaunchDarklyIntegration(
data: IdentifySeriesData,
_result: IdentifySeriesResult,
) => {
hClient.log()
hClient.identify(
getCanonicalKey(hookContext.context),
hookContext.context,
Expand All @@ -87,18 +87,11 @@ export function setupLaunchDarklyIntegration(
getCanonicalKey(hookContext.context)
}

let span = trace.getActiveSpan()
if (span) {
span.addEvent(FEATURE_FLAG_SCOPE, eventAttributes)
} else {
hClient.startSpan(FEATURE_FLAG_SPAN_NAME, (s) => {
if (s) {
s.addEvent(FEATURE_FLAG_SCOPE, eventAttributes)
}
})
}

hClient.track(FEATURE_FLAG_SPAN_NAME, eventAttributes)
hClient.startSpan(FEATURE_FLAG_SPAN_NAME, (s) => {
if (s) {
s.addEvent(FEATURE_FLAG_SCOPE, eventAttributes)
}
})

return data
},
Expand Down Expand Up @@ -154,10 +147,6 @@ export class LaunchDarklyIntegration implements IntegrationClient {

track(sessionSecureID: string, metadata: object) {
const event = (metadata as unknown as { event?: string }).event
// skip integration hClient.track() calls
if (event === FEATURE_FLAG_SPAN_NAME) {
return
}
this.client.track(
event ? `${LD_TRACK_EVENT}:${event}` : LD_TRACK_EVENT,
{
Expand Down
Loading