Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
24 changes: 23 additions & 1 deletion sdk/highlight-run/src/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@
import HighlightClientWorker from './workers/highlight-client-worker?worker&inline'
import { MessageType, PropertyType } from './workers/types'
import { parseError } from './utils/errors'
import { Counter, Gauge, Histogram, UpDownCounter } from '@opentelemetry/api'
import {
Attributes,
Counter,
Gauge,
Histogram,
UpDownCounter,
} from '@opentelemetry/api'
import { IntegrationClient } from '../integrations'
import { LaunchDarklyIntegration } from '../integrations/launchdarkly'
import { LDClientMin } from '../integrations/launchdarkly/types/LDClient'
Expand Down Expand Up @@ -476,6 +482,22 @@
}
}

log(message: any, level: string, metadata?: Attributes) {
//TODO(vkorolik)
this._firstLoadListeners.messages.push({
type: level,
trace: trace.slice(1),
value: message,
attributes: stringify(
data
.filter((d) => typeof d === 'object')
.reduce((a, b) => ({ ...a, ...b }), {}),
logOptions.stringifyOptions,
),
time: Date.now(),
})
}

pushCustomError(message: string, payload?: string) {
return this.consumeCustomError(new Error(message), undefined, payload)
}
Expand Down
50 changes: 28 additions & 22 deletions sdk/highlight-run/src/client/listeners/console-listener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,38 @@ export function ConsoleListener(
// @ts-expect-error
original.apply(this, data)
try {
const trace = parseError(new Error())
const message = logOptions.serializeConsoleAttributes
? data.map((o) =>
typeof o === 'object'
? stringify(o, logOptions.stringifyOptions)
: o,
)
: data
.filter((o) => typeof o !== 'object')
.map((o) => `${o}`)
callback({
type: level,
trace: trace.slice(1),
value: message,
attributes: stringify(
data
.filter((d) => typeof d === 'object')
.reduce((a, b) => ({ ...a, ...b }), {}),
logOptions.stringifyOptions,
),
time: Date.now(),
})
callback(createLog(level, logOptions, data))
} catch (error) {
original('highlight logger error:', error, ...data)
}
}
})
}
}

export function createLog(
level: string,
logOptions: LogRecordOptions,
...data: Array<any>
) {
const trace = parseError(new Error())
const message = logOptions.serializeConsoleAttributes
? data.map((o) =>
typeof o === 'object'
? stringify(o, logOptions.stringifyOptions)
: o,
)
: data.filter((o) => typeof o !== 'object').map((o) => `${o}`)
return {
type: level,
trace: trace.slice(1),
value: message,
attributes: stringify(
data
.filter((d) => typeof d === 'object')
.reduce((a, b) => ({ ...a, ...b }), {}),
logOptions.stringifyOptions,
),
time: Date.now(),
}
}
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
5 changes: 4 additions & 1 deletion sdk/highlight-run/src/client/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Context, Span, SpanOptions } from '@opentelemetry/api'
import { Attributes, Context, Span, SpanOptions } from '@opentelemetry/api'
import {
ConsoleMethods,
DebugOptions,
Expand Down Expand Up @@ -288,6 +288,7 @@
* @param metadata Additional details you want to associate to the event.
*/
track: (event: string, metadata?: Metadata) => void
log: (message: any, level: string, metadata?: Attributes) => void
/**
* @deprecated with replacement by `consumeError` for an in-app stacktrace.
*/
Expand Down Expand Up @@ -379,6 +380,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
17 changes: 16 additions & 1 deletion sdk/highlight-run/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ import {
loadCookieSessionData,
} from './client/utils/sessionStorage/highlightSession.js'
import { setCookieWriteEnabled } from './client/utils/storage'
import { Context, Span, SpanOptions, Tracer } from '@opentelemetry/api'
import {
Attributes,
Context,
Span,
SpanOptions,
Tracer,
} from '@opentelemetry/api'
import firstloadVersion from './__generated/version.js'
import { listenToChromeExtensionMessage } from './browserExtension/extensionListener.js'
import configureElectronHighlight from './environments/electron.js'
Expand Down Expand Up @@ -295,6 +301,15 @@ const H: HighlightPublicInterface = {
HighlightWarning('track', e)
}
},
log: (message: any, level: string, metadata?: Attributes) => {
try {
H.onHighlightReady(() =>
highlight_obj.log(message, level, metadata ?? {}),
)
} catch (e) {
HighlightWarning('log', e)
}
},
start: (options) => {
if (highlight_obj?.state === 'Recording' && !options?.forceNew) {
if (!options?.silent) {
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