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
f584722f
Unverified
Commit
f584722f
authored
Nov 22, 2021
by
Tim Neutkens
Committed by
GitHub
Nov 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove trace_target env var in favor of .next/trace (#31697)
parent
7f58a2e4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
252 deletions
+46
-252
index.ts
packages/next/trace/report/index.ts
+2
-28
to-console.ts
packages/next/trace/report/to-console.ts
+0
-32
to-jaeger.ts
packages/next/trace/report/to-jaeger.ts
+0
-83
to-json.ts
packages/next/trace/report/to-json.ts
+44
-1
to-zipkin.ts
packages/next/trace/report/to-zipkin.ts
+0
-101
shared.ts
packages/next/trace/shared.ts
+0
-7
No files found.
packages/next/trace/report/index.ts
View file @
f584722f
import
{
TARGET
,
SpanId
}
from
'../shared'
import
{
SpanId
}
from
'../shared'
import
reportToConsole
from
'./to-console'
import
reportToZipkin
from
'./to-zipkin'
import
reportToJaeger
from
'./to-jaeger'
import
reportToTelemetry
from
'./to-telemetry'
import
reportToTelemetry
from
'./to-telemetry'
import
reportToJson
from
'./to-json'
import
reportToJson
from
'./to-json'
...
@@ -42,28 +39,5 @@ class MultiReporter implements Reporter {
...
@@ -42,28 +39,5 @@ class MultiReporter implements Reporter {
}
}
}
}
const
target
=
process
.
env
.
TRACE_TARGET
&&
process
.
env
.
TRACE_TARGET
in
TARGET
?
TARGET
[
process
.
env
.
TRACE_TARGET
as
TARGET
]
:
TARGET
.
TELEMETRY
if
(
process
.
env
.
TRACE_TARGET
&&
!
target
)
{
console
.
info
(
'For TRACE_TARGET, please specify one of: CONSOLE, ZIPKIN, TELEMETRY'
)
}
let
traceTargetReporter
:
Reporter
if
(
target
===
TARGET
.
CONSOLE
)
{
traceTargetReporter
=
reportToConsole
}
else
if
(
target
===
TARGET
.
ZIPKIN
)
{
traceTargetReporter
=
reportToZipkin
}
else
if
(
target
===
TARGET
.
JAEGER
)
{
traceTargetReporter
=
reportToJaeger
}
else
{
traceTargetReporter
=
reportToTelemetry
}
// JSON is always reported to allow for diagnostics
// JSON is always reported to allow for diagnostics
export
const
reporter
=
new
MultiReporter
([
reportToJson
,
traceTargetReporter
])
export
const
reporter
=
new
MultiReporter
([
reportToJson
,
reportToTelemetry
])
packages/next/trace/report/to-console.ts
deleted
100644 → 0
View file @
7f58a2e4
import
*
as
Log
from
'../../build/output/log'
const
idToName
=
new
Map
<
string
,
string
>
()
const
reportToConsole
=
(
spanName
:
string
,
duration
:
number
,
_timestamp
:
number
,
id
:
string
,
parentId
?:
string
,
attrs
?:
Object
)
=>
{
idToName
.
set
(
id
,
spanName
)
const
parentStr
=
parentId
&&
idToName
.
has
(
parentId
)
?
`, parent:
${
idToName
.
get
(
parentId
)}
`
:
''
const
attrsStr
=
attrs
?
`,
${
Object
.
entries
(
attrs
)
.
map
(([
key
,
val
])
=>
`
${
key
}
:
${
val
}
`
)
.
join
(
', '
)}
`
:
''
Log
.
trace
(
`
${
spanName
}
took
${
Number
(
duration
)
/
1000
}
ms
${
parentStr
}${
attrsStr
}
`
)
}
export
default
{
flushAll
:
()
=>
{},
report
:
reportToConsole
,
}
packages/next/trace/report/to-jaeger.ts
deleted
100644 → 0
View file @
7f58a2e4
import
retry
from
'next/dist/compiled/async-retry'
import
{
randomBytes
}
from
'crypto'
import
fetch
from
'node-fetch'
import
*
as
Log
from
'../../build/output/log'
// Jaeger uses Zipkin's reporting
import
{
batcher
}
from
'./to-zipkin'
let
traceId
:
string
let
batch
:
ReturnType
<
typeof
batcher
>
|
undefined
const
localEndpoint
=
{
serviceName
:
'nextjs'
,
ipv4
:
'127.0.0.1'
,
port
:
9411
,
}
// Jaeger supports Zipkin's reporting API
const
zipkinUrl
=
`http://
${
localEndpoint
.
ipv4
}
:
${
localEndpoint
.
port
}
`
const
jaegerWebUiUrl
=
`http://
${
localEndpoint
.
ipv4
}
:16686`
const
zipkinAPI
=
`
${
zipkinUrl
}
/api/v2/spans`
function
logWebUrl
()
{
Log
.
info
(
`Jaeger trace will be available on
${
jaegerWebUiUrl
}
/trace/
${
traceId
}
`
)
}
const
reportToLocalHost
=
(
name
:
string
,
duration
:
number
,
timestamp
:
number
,
id
:
string
,
parentId
?:
string
,
attrs
?:
Object
)
=>
{
if
(
!
traceId
)
{
traceId
=
process
.
env
.
TRACE_ID
||
randomBytes
(
8
).
toString
(
'hex'
)
logWebUrl
()
}
if
(
!
batch
)
{
batch
=
batcher
((
events
)
=>
{
const
eventsJson
=
JSON
.
stringify
(
events
)
// Ensure ECONNRESET error is retried 3 times before erroring out
return
retry
(
()
=>
// Send events to jaeger's zipkin endpoint
fetch
(
zipkinAPI
,
{
method
:
'POST'
,
headers
:
{
'Content-Type'
:
'application/json'
},
body
:
eventsJson
,
}),
{
minTimeout
:
500
,
retries
:
3
,
factor
:
1
}
)
.
then
(
async
(
res
:
any
)
=>
{
if
(
res
.
status
!==
202
)
{
console
.
log
({
status
:
res
.
status
,
body
:
await
res
.
text
(),
events
:
eventsJson
,
})
}
})
.
catch
(
console
.
log
)
})
}
batch
.
report
({
traceId
,
parentId
,
name
,
id
,
timestamp
,
duration
,
localEndpoint
,
tags
:
attrs
,
})
}
export
default
{
flushAll
:
()
=>
batch
?
batch
.
flushAll
().
then
(()
=>
logWebUrl
())
:
undefined
,
report
:
reportToLocalHost
,
}
packages/next/trace/report/to-json.ts
View file @
f584722f
import
{
randomBytes
}
from
'crypto'
import
{
randomBytes
}
from
'crypto'
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'
import
{
PHASE_DEVELOPMENT_SERVER
}
from
'../../shared/lib/constants'
const
localEndpoint
=
{
serviceName
:
'nextjs'
,
ipv4
:
'127.0.0.1'
,
port
:
9411
,
}
type
Event
=
{
traceId
:
string
parentId
?:
string
name
:
string
id
:
string
timestamp
:
number
duration
:
number
localEndpoint
?:
typeof
localEndpoint
tags
?:
Object
}
// Batch events as zipkin allows for multiple events to be sent in one go
export
function
batcher
(
reportEvents
:
(
evts
:
Event
[])
=>
Promise
<
void
>
)
{
const
events
:
Event
[]
=
[]
// Promise queue to ensure events are always sent on flushAll
const
queue
=
new
Set
()
return
{
flushAll
:
async
()
=>
{
await
Promise
.
all
(
queue
)
if
(
events
.
length
>
0
)
{
await
reportEvents
(
events
)
events
.
length
=
0
}
},
report
:
(
event
:
Event
)
=>
{
events
.
push
(
event
)
if
(
events
.
length
>
100
)
{
const
evts
=
events
.
slice
()
events
.
length
=
0
const
report
=
reportEvents
(
evts
)
queue
.
add
(
report
)
report
.
then
(()
=>
queue
.
delete
(
report
))
}
},
}
}
let
writeStream
:
RotatingWriteStream
let
writeStream
:
RotatingWriteStream
let
traceId
:
string
let
traceId
:
string
let
batch
:
ReturnType
<
typeof
batcher
>
|
undefined
let
batch
:
ReturnType
<
typeof
batcher
>
|
undefined
...
...
packages/next/trace/report/to-zipkin.ts
deleted
100644 → 0
View file @
7f58a2e4
import
retry
from
'next/dist/compiled/async-retry'
import
{
randomBytes
}
from
'crypto'
import
fetch
from
'node-fetch'
import
*
as
Log
from
'../../build/output/log'
let
traceId
:
string
let
batch
:
ReturnType
<
typeof
batcher
>
|
undefined
const
localEndpoint
=
{
serviceName
:
'nextjs'
,
ipv4
:
'127.0.0.1'
,
port
:
9411
,
}
const
zipkinUrl
=
`http://
${
localEndpoint
.
ipv4
}
:
${
localEndpoint
.
port
}
`
const
zipkinAPI
=
`
${
zipkinUrl
}
/api/v2/spans`
type
Event
=
{
traceId
:
string
parentId
?:
string
name
:
string
id
:
string
timestamp
:
number
duration
:
number
localEndpoint
?:
typeof
localEndpoint
tags
?:
Object
}
// Batch events as zipkin allows for multiple events to be sent in one go
export
function
batcher
(
reportEvents
:
(
evts
:
Event
[])
=>
Promise
<
void
>
)
{
const
events
:
Event
[]
=
[]
// Promise queue to ensure events are always sent on flushAll
const
queue
=
new
Set
()
return
{
flushAll
:
async
()
=>
{
await
Promise
.
all
(
queue
)
if
(
events
.
length
>
0
)
{
await
reportEvents
(
events
)
events
.
length
=
0
}
},
report
:
(
event
:
Event
)
=>
{
events
.
push
(
event
)
if
(
events
.
length
>
100
)
{
const
evts
=
events
.
slice
()
events
.
length
=
0
const
report
=
reportEvents
(
evts
)
queue
.
add
(
report
)
report
.
then
(()
=>
queue
.
delete
(
report
))
}
},
}
}
const
reportToLocalHost
=
(
name
:
string
,
duration
:
number
,
timestamp
:
number
,
id
:
string
,
parentId
?:
string
,
attrs
?:
Object
)
=>
{
if
(
!
traceId
)
{
traceId
=
process
.
env
.
TRACE_ID
||
randomBytes
(
8
).
toString
(
'hex'
)
Log
.
info
(
`Zipkin trace will be available on
${
zipkinUrl
}
/zipkin/traces/
${
traceId
}
`
)
}
if
(
!
batch
)
{
batch
=
batcher
((
events
)
=>
{
// Ensure ECONNRESET error is retried 3 times before erroring out
return
retry
(
()
=>
// Send events to zipkin
fetch
(
zipkinAPI
,
{
method
:
'POST'
,
headers
:
{
'Content-Type'
:
'application/json'
},
body
:
JSON
.
stringify
(
events
),
}),
{
minTimeout
:
500
,
retries
:
3
,
factor
:
1
}
).
catch
(
console
.
log
)
})
}
batch
.
report
({
traceId
,
parentId
,
name
,
id
,
timestamp
,
duration
,
localEndpoint
,
tags
:
attrs
,
})
}
export
default
{
flushAll
:
()
=>
(
batch
?
batch
.
flushAll
()
:
undefined
),
report
:
reportToLocalHost
,
}
packages/next/trace/shared.ts
View file @
f584722f
// eslint typescript has a bug with TS enums
// eslint typescript has a bug with TS enums
/* eslint-disable no-shadow */
export
enum
TARGET
{
CONSOLE
=
'CONSOLE'
,
ZIPKIN
=
'ZIPKIN'
,
JAEGER
=
'JAEGER'
,
TELEMETRY
=
'TELEMETRY'
,
}
export
type
SpanId
=
string
export
type
SpanId
=
string
...
...
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