Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence trace debug messages #22988

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions packages/next/telemetry/trace/autoparent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { trace, Span } from './trace'
import { debugLog } from './shared'

const stacks = new WeakMap<any, Array<Span>>()
const stoppedSpansSets = new WeakMap<any, Set<Span>>()
Expand Down Expand Up @@ -27,7 +28,7 @@ export function stackPush(keyObj: any, spanName: string, attrs?: any): Span {
export function stackPop(keyObj: any, span: any): void {
let stack = stacks.get(keyObj)
if (!stack) {
console.info(
debugLog(
'Attempted to pop from non-existent stack. Key reference must be bad.'
)
return
Expand All @@ -39,7 +40,7 @@ export function stackPop(keyObj: any, span: any): void {
stoppedSpansSets.set(keyObj, stoppedSpans)
}
if (stoppedSpans.has(span)) {
console.info(
debugLog(
`Attempted to terminate tracing span that was already stopped for ${span.name}`
)
return
Expand All @@ -56,12 +57,12 @@ export function stackPop(keyObj: any, span: any): void {
} else if (poppedSpan === undefined || stack.indexOf(span) === -1) {
// We've either reached the top of the stack or the stack doesn't contain
// the span for another reason.
console.info(`Tracing span was not found in stack for: ${span.name}`)
debugLog(`Tracing span was not found in stack for: ${span.name}`)
stoppedSpans.add(span)
span.stop()
break
} else if (stack.indexOf(span) !== -1) {
console.info(
debugLog(
`Attempted to pop span that was not at top of stack for: ${span.name}`
)
stoppedSpans.add(poppedSpan)
Expand Down
4 changes: 4 additions & 0 deletions packages/next/telemetry/trace/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ export const traceGlobals: Map<any, any> = new Map()
export const setGlobal = (key: any, val: any) => {
traceGlobals.set(key, val)
}

export const debugLog = !!process.env.TRACE_DEBUG
? console.info
: function noop() {}