Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
83657b6b
Unverified
Commit
83657b6b
authored
Feb 12, 2021
by
Tim Neutkens
Committed by
GitHub
Feb 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if parentspan is provided in profiler (#22061)
Co-authored-by:
Dale Bustad
<
dale@divmain.com
>
parent
5c246702
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
15 deletions
+60
-15
launch.json
.vscode/launch.json
+11
-0
tracer.ts
packages/next/build/tracer.ts
+41
-13
profiling-plugin.ts
packages/next/build/webpack/plugins/profiling-plugin.ts
+8
-2
No files found.
.vscode/launch.json
View file @
83657b6b
...
...
@@ -25,6 +25,17 @@
"port"
:
9229
,
"outFiles"
:
[
"${workspaceFolder}/packages/next/dist/**/*"
]
},
{
"name"
:
"Launch app build trace"
,
"type"
:
"node"
,
"request"
:
"launch"
,
"cwd"
:
"${workspaceFolder}"
,
"runtimeExecutable"
:
"yarn"
,
"runtimeArgs"
:
[
"run"
,
"trace-debug"
,
"build"
,
"test/integration/basic"
],
"skipFiles"
:
[
"<node_internals>/**"
],
"port"
:
9229
,
"outFiles"
:
[
"${workspaceFolder}/packages/next/dist/**/*"
]
},
{
"name"
:
"Launch app production"
,
"type"
:
"node"
,
...
...
packages/next/build/tracer.ts
View file @
83657b6b
...
...
@@ -3,6 +3,7 @@ import api, { Span } from '@opentelemetry/api'
export
const
tracer
=
api
.
trace
.
getTracer
(
'next'
,
process
.
env
.
__NEXT_VERSION
)
const
compilerStacks
=
new
WeakMap
()
const
compilerStoppedSpans
=
new
WeakMap
()
export
function
stackPush
(
compiler
:
any
,
spanName
:
string
,
attrs
?:
any
):
any
{
let
stack
=
compilerStacks
.
get
(
compiler
)
...
...
@@ -13,18 +14,20 @@ export function stackPush(compiler: any, spanName: string, attrs?: any): any {
span
=
tracer
.
startSpan
(
spanName
,
attrs
?
attrs
()
:
undefined
)
}
else
{
const
parent
=
stack
[
stack
.
length
-
1
]
tracer
.
withSpan
(
parent
,
()
=>
{
if
(
parent
)
{
tracer
.
withSpan
(
parent
,
()
=>
{
span
=
tracer
.
startSpan
(
spanName
,
attrs
?
attrs
()
:
undefined
)
})
}
else
{
span
=
tracer
.
startSpan
(
spanName
,
attrs
?
attrs
()
:
undefined
)
}
)
}
}
stack
.
push
(
span
)
return
span
}
export
function
stackPop
(
compiler
:
any
,
span
:
any
)
{
span
.
end
()
export
function
stackPop
(
compiler
:
any
,
span
:
any
,
associatedName
?:
string
)
{
let
stack
=
compilerStacks
.
get
(
compiler
)
if
(
!
stack
)
{
console
.
warn
(
...
...
@@ -32,15 +35,40 @@ export function stackPop(compiler: any, span: any) {
)
return
}
const
poppedSpan
=
stack
.
pop
()
if
(
poppedSpan
!==
span
)
{
stack
.
push
(
poppedSpan
)
const
spanIdx
=
stack
.
indexOf
(
span
)
console
.
warn
(
'Attempted to pop span that was not at top of stack.'
)
if
(
spanIdx
!==
-
1
)
{
console
.
info
(
`Span was found at index
${
spanIdx
}
with stack size
${
stack
.
length
}
`
let
stoppedSpans
:
Set
<
Span
>
=
compilerStoppedSpans
.
get
(
compiler
)
if
(
!
stoppedSpans
)
{
stoppedSpans
=
new
Set
()
compilerStoppedSpans
.
set
(
compiler
,
stoppedSpans
)
}
if
(
stoppedSpans
.
has
(
span
))
{
console
.
warn
(
`Attempted to terminate tracing span that was already stopped for
${
associatedName
}
`
)
return
}
while
(
true
)
{
let
poppedSpan
=
stack
.
pop
()
if
(
poppedSpan
===
span
)
{
stoppedSpans
.
add
(
poppedSpan
)
span
.
end
()
stoppedSpans
.
add
(
span
)
break
}
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
.
warn
(
`Tracing span was not found in stack for:
${
associatedName
}
`
)
stoppedSpans
.
add
(
span
)
span
.
end
()
break
}
else
if
(
stack
.
indexOf
(
span
)
!==
-
1
)
{
console
.
warn
(
`Attempted to pop span that was not at top of stack for:
${
associatedName
}
`
)
stoppedSpans
.
add
(
poppedSpan
)
poppedSpan
.
end
()
}
}
}
...
...
packages/next/build/webpack/plugins/profiling-plugin.ts
View file @
83657b6b
...
...
@@ -54,7 +54,13 @@ export class ProfilingPlugin {
onSetSpan
?.(
span
)
})
stopHook
.
tap
(
pluginName
,
()
=>
{
stackPop
(
this
.
compiler
,
span
)
// `stopHook` may be triggered when `startHook` has not in cases
// where `stopHook` is used as the terminating event for more
// than one pair of hooks.
if
(
!
span
)
{
return
}
stackPop
(
this
.
compiler
,
span
,
spanName
)
})
}
...
...
@@ -66,7 +72,7 @@ export class ProfilingPlugin {
}
})
stopHook
.
tap
(
pluginName
,
()
=>
{
stackPop
(
this
.
compiler
,
span
)
stackPop
(
this
.
compiler
,
span
,
spanName
)
})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment