Skip to content

Commit

Permalink
add some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yousif-bugsnag committed Dec 23, 2024
1 parent f7fc7f4 commit 493186a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/core/lib/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export function spanEndedToSpan (span: SpanEnded): Span {
}

export async function runSpanEndCallbacks (spanEnded: SpanEnded, logger: Logger, callbacks?: OnSpanEndCallbacks) {
if (!callbacks) return true
console.log(`[BugsnagPerformance] runSpanEndCallbacks for span: ${spanEnded.name}`)
if (!callbacks) {
console.log('[BugsnagPerformance] no callbacks to run')
return true
}

const span = spanEndedToSpan(spanEnded)
const callbackStartTime = performance.now()
Expand All @@ -103,6 +107,7 @@ export async function runSpanEndCallbacks (spanEnded: SpanEnded, logger: Logger,
result = await result
}

console.log('[BugsnagPerformance] callback result:', result)
if (result === false) {
shouldSample = false
break
Expand All @@ -115,6 +120,8 @@ export async function runSpanEndCallbacks (spanEnded: SpanEnded, logger: Logger,
const duration = millisecondsToNanoseconds(performance.now() - callbackStartTime)
span.setAttribute('bugsnag.span.callbacks_duration', duration)
}

console.log('[BugsnagPerformance] callbacks complete, shouldSample:', shouldSample)
return shouldSample
}

Expand Down
2 changes: 2 additions & 0 deletions packages/platforms/react-native/lib/span-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ export class ReactNativeSpanFactory extends SpanFactory<ReactNativeConfiguration

private async processNativeSpan (span: NativeSpanInternal, endTime: number) {
const spanEnded = span.end(endTime, this.sampler.spanProbability)
console.log(`[BugsnagPerformance] processing native span: ${spanEnded.name}`)
const shouldSend = await runSpanEndCallbacks(spanEnded, this.logger, this.onSpanEndCallbacks)

if (shouldSend) {
const unixEndTimeNanos = (this.clock as ReactNativeClock).toUnixNanoseconds(endTime)
const attributes = spanEnded.attributes.toObject()
delete attributes['bugsnag.sampling.p']
console.log(`[BugsnagPerformance] ending native span with attributes: ${JSON.stringify(attributes)}`)
NativeBugsnagPerformance?.endNativeSpan(spanEnded.id, spanEnded.traceId, unixEndTimeNanos, attributes)
} else {
NativeBugsnagPerformance?.discardNativeSpan(spanEnded.id, spanEnded.traceId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ export const initialise = async (config) => {

const onSpanEnd = [
async (span) => {
console.log('[BugsnagPerformance] NativeIntegrationScenario onSpanEnd')
if (span.name === 'JS parent span') {
console.log('[BugsnagPerformance] setting custom attribute on JS parent span')
span.setAttribute('custom.js.attribute', 'JS span attribute')
} else if (span.name === 'Native child span') {
console.log('[BugsnagPerformance] setting custom attribute on Native child span')
span.setAttribute('custom.native.attribute', 'Native span attribute')
}
return true
Expand Down

0 comments on commit 493186a

Please sign in to comment.