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
f74ee78c
Unverified
Commit
f74ee78c
authored
Oct 05, 2021
by
Tim Neutkens
Committed by
GitHub
Oct 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add trace file for "next dev" (#29633)
Co-authored-by:
Tobias Koppers
<
tobias.koppers@googlemail.com
>
parent
7af61f69
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
12 deletions
+70
-12
index.ts
packages/next/build/index.ts
+1
-0
next-dev-server.ts
packages/next/server/dev/next-dev-server.ts
+2
-0
to-json.ts
packages/next/trace/report/to-json.ts
+67
-12
No files found.
packages/next/build/index.ts
View file @
f74ee78c
...
@@ -132,6 +132,7 @@ export default async function build(
...
@@ -132,6 +132,7 @@ export default async function build(
.
traceChild
(
'load-next-config'
)
.
traceChild
(
'load-next-config'
)
.
traceAsyncFn
(()
=>
loadConfig
(
PHASE_PRODUCTION_BUILD
,
dir
,
conf
))
.
traceAsyncFn
(()
=>
loadConfig
(
PHASE_PRODUCTION_BUILD
,
dir
,
conf
))
const
distDir
=
path
.
join
(
dir
,
config
.
distDir
)
const
distDir
=
path
.
join
(
dir
,
config
.
distDir
)
setGlobal
(
'phase'
,
PHASE_PRODUCTION_BUILD
)
setGlobal
(
'distDir'
,
distDir
)
setGlobal
(
'distDir'
,
distDir
)
const
{
target
}
=
config
const
{
target
}
=
config
...
...
packages/next/server/dev/next-dev-server.ts
View file @
f74ee78c
...
@@ -286,6 +286,8 @@ export default class DevServer extends Server {
...
@@ -286,6 +286,8 @@ export default class DevServer extends Server {
}
}
async
prepare
():
Promise
<
void
>
{
async
prepare
():
Promise
<
void
>
{
setGlobal
(
'distDir'
,
this
.
distDir
)
setGlobal
(
'phase'
,
PHASE_DEVELOPMENT_SERVER
)
await
verifyTypeScriptSetup
(
await
verifyTypeScriptSetup
(
this
.
dir
,
this
.
dir
,
this
.
pagesDir
!
,
this
.
pagesDir
!
,
...
...
packages/next/trace/report/to-json.ts
View file @
f74ee78c
...
@@ -3,11 +3,64 @@ import { batcher } from './to-zipkin'
...
@@ -3,11 +3,64 @@ import { batcher } from './to-zipkin'
import
{
traceGlobals
}
from
'../shared'
import
{
traceGlobals
}
from
'../shared'
import
fs
from
'fs'
import
fs
from
'fs'
import
path
from
'path'
import
path
from
'path'
import
{
PHASE_DEVELOPMENT_SERVER
}
from
'../../shared/lib/constants'
let
writeStream
:
fs
.
WriteStream
let
writeStream
:
Rotating
WriteStream
let
traceId
:
string
let
traceId
:
string
let
batch
:
ReturnType
<
typeof
batcher
>
|
undefined
let
batch
:
ReturnType
<
typeof
batcher
>
|
undefined
const
writeStreamOptions
=
{
flags
:
'a'
,
encoding
:
'utf8'
,
}
class
RotatingWriteStream
{
file
:
string
writeStream
!
:
fs
.
WriteStream
size
:
number
sizeLimit
:
number
isRotating
:
Promise
<
void
>
|
undefined
constructor
(
file
:
string
,
sizeLimit
:
number
)
{
this
.
file
=
file
this
.
size
=
0
this
.
sizeLimit
=
sizeLimit
this
.
createWriteStream
()
}
private
createWriteStream
()
{
this
.
writeStream
=
fs
.
createWriteStream
(
this
.
file
,
writeStreamOptions
)
}
// Recreate the file
private
rotate
():
void
{
this
.
end
()
try
{
fs
.
unlinkSync
(
this
.
file
)
}
catch
(
err
:
any
)
{
// It's fine if the file does not exist yet
if
(
err
.
code
!==
'ENOENT'
)
{
throw
err
}
}
this
.
size
=
0
this
.
createWriteStream
()
}
async
write
(
data
:
string
):
Promise
<
void
>
{
this
.
size
+=
data
.
length
if
(
this
.
size
>
this
.
sizeLimit
)
{
this
.
rotate
()
}
if
(
!
this
.
writeStream
.
write
(
data
,
'utf8'
))
{
await
new
Promise
<
void
>
((
resolve
,
_reject
)
=>
{
this
.
writeStream
.
once
(
'drain'
,
resolve
)
})
}
}
end
():
void
{
this
.
writeStream
.
end
(
''
,
'utf8'
)
}
}
const
reportToLocalHost
=
(
const
reportToLocalHost
=
(
name
:
string
,
name
:
string
,
duration
:
number
,
duration
:
number
,
...
@@ -17,7 +70,8 @@ const reportToLocalHost = (
...
@@ -17,7 +70,8 @@ const reportToLocalHost = (
attrs
?:
Object
attrs
?:
Object
)
=>
{
)
=>
{
const
distDir
=
traceGlobals
.
get
(
'distDir'
)
const
distDir
=
traceGlobals
.
get
(
'distDir'
)
if
(
!
distDir
)
{
const
phase
=
traceGlobals
.
get
(
'phase'
)
if
(
!
distDir
||
!
phase
)
{
return
return
}
}
...
@@ -30,18 +84,15 @@ const reportToLocalHost = (
...
@@ -30,18 +84,15 @@ const reportToLocalHost = (
if
(
!
writeStream
)
{
if
(
!
writeStream
)
{
await
fs
.
promises
.
mkdir
(
distDir
,
{
recursive
:
true
})
await
fs
.
promises
.
mkdir
(
distDir
,
{
recursive
:
true
})
const
file
=
path
.
join
(
distDir
,
'trace'
)
const
file
=
path
.
join
(
distDir
,
'trace'
)
writeStream
=
fs
.
createWriteStream
(
file
,
{
writeStream
=
new
RotatingWriteStream
(
flags
:
'a'
,
file
,
encoding
:
'utf8'
,
// Development is limited to 50MB, production is unlimited
})
phase
===
PHASE_DEVELOPMENT_SERVER
?
52428800
:
Infinity
)
}
}
const
eventsJson
=
JSON
.
stringify
(
events
)
const
eventsJson
=
JSON
.
stringify
(
events
)
try
{
try
{
await
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
await
writeStream
.
write
(
eventsJson
+
'
\
n'
)
writeStream
.
write
(
eventsJson
+
'
\
n'
,
'utf8'
,
(
err
)
=>
{
err
?
reject
(
err
)
:
resolve
()
})
})
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
)
console
.
log
(
err
)
}
}
...
@@ -63,7 +114,11 @@ export default {
...
@@ -63,7 +114,11 @@ export default {
flushAll
:
()
=>
flushAll
:
()
=>
batch
batch
?
batch
.
flushAll
().
then
(()
=>
{
?
batch
.
flushAll
().
then
(()
=>
{
writeStream
.
end
(
''
,
'utf8'
)
const
phase
=
traceGlobals
.
get
(
'phase'
)
// Only end writeStream when manually flushing in production
if
(
phase
!==
PHASE_DEVELOPMENT_SERVER
)
{
writeStream
.
end
()
}
})
})
:
undefined
,
:
undefined
,
report
:
reportToLocalHost
,
report
:
reportToLocalHost
,
...
...
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