Skip to content

Commit 0c408a9

Browse files
committed
cleanup
1 parent 37cddfb commit 0c408a9

File tree

3 files changed

+6
-118
lines changed

3 files changed

+6
-118
lines changed

packages/datadog-instrumentations/src/next.js

+1-26
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,11 @@ function getPageFromPath (page, dynamicRoutes = []) {
117117
return getPagePath(page)
118118
}
119119

120-
// https://github.com/vercel/next.js/blob/09ab728499b7a502de36a8397ef85ff30f5e4f6e/packages/next/src/server/request-meta.ts#L161
121-
function getRequestMeta(req, key) {
120+
function getRequestMeta (req, key) {
122121
const meta = req[NEXT_REQUEST_META] || {}
123122
return typeof key === 'string' ? meta[key] : meta
124123
}
125124

126-
// instrument gets called twice (at least for static routes)
127-
// this is true in 14.2.6 and 14.2.7
128-
// however, in 14.2.6, the first time it's called the middleware check passes and second fails
129-
// in 14.2.7 the first and second times both think it is middleware
130125
function instrument (req, res, error, handler) {
131126
if (typeof error === 'function') {
132127
handler = error
@@ -137,40 +132,20 @@ function instrument (req, res, error, handler) {
137132
res = res.originalResponse || res
138133

139134
// TODO support middleware properly in the future?
140-
console.log('MIDDLEWARE HEADER', req.headers[MIDDLEWARE_HEADER])
141-
console.log('REQUEST META', getRequestMeta(req))
142-
console.log('MIDDLEWARE META SYMBOL', getRequestMeta(req, META_IS_MIDDLEWARE))
143-
144-
console.log('DO I HAZ ERROR', error)
145-
146-
// Alright the behavior between 14.2.6 and 14.2.7 changes. In the former the middleware header is
147-
// deleted before the second call. In the latter the middleware symbol is retained.
148-
// I think this is because they used were sticking a bunch of metadata into a request as headers
149-
// as a hack. Of course they didn't want those hacky headers leaking into userland so they would
150-
// delete them with stripInternalHeaders(). After they refactored the code it was no longer
151-
// necessary to strip those headers since they're essentially now private. That means we are now
152-
// depending on behavior that no longer applies.
153135
const isMiddleware = req.headers[MIDDLEWARE_HEADER] || getRequestMeta(req, META_IS_MIDDLEWARE)
154-
console.log('foo', isMiddleware, requests.has(req)) // good: a1, b1 ; bad: a1, b1
155136
if ((isMiddleware && !encounteredMiddleware.has(req)) || requests.has(req)) {
156137
encounteredMiddleware.add(req)
157-
console.log('bar') // good: a2 ; bad: a2, b2
158138
if (error) {
159-
console.log('baz')
160139
errorChannel.publish({ error })
161140
}
162-
console.log('bif') // good: a3 ; bad: a3, b3
163141
return handler()
164142
}
165143

166-
console.log('blop') // good: b2
167144
requests.add(req)
168145

169146
const ctx = { req, res }
170147

171-
console.log('about to run startChannel.runStores')
172148
return startChannel.runStores(ctx, () => {
173-
console.log('inside of startChannel.runStores')
174149
try {
175150
const promise = handler(ctx)
176151

packages/datadog-plugin-next/src/index.js

-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class NextPlugin extends ServerPlugin {
2020
}
2121

2222
bindStart ({ req, res }) {
23-
console.log('start', !!req, !!res)
2423
const store = storage.getStore()
2524
const childOf = store ? store.span : store
2625
const span = this.tracer.startSpan(this.operationName(), {
@@ -43,7 +42,6 @@ class NextPlugin extends ServerPlugin {
4342
}
4443

4544
error ({ span, error }) {
46-
console.log('error', span, error);
4745
if (!span) {
4846
const store = storage.getStore()
4947
if (!store) return
@@ -55,7 +53,6 @@ class NextPlugin extends ServerPlugin {
5553
}
5654

5755
finish ({ req, res, nextRequest = {} }) {
58-
console.log('finish', !!req, !!res, nextRequest)
5956
const store = storage.getStore()
6057

6158
if (!store) return
@@ -88,7 +85,6 @@ class NextPlugin extends ServerPlugin {
8885
}
8986

9087
pageLoad ({ page, isAppPath = false, isStatic = false }) {
91-
console.log('pageLoad', page, isAppPath, isStatic)
9288
const store = storage.getStore()
9389

9490
if (!store) return

packages/datadog-plugin-next/test/index.spec.js

+5-88
Original file line numberDiff line numberDiff line change
@@ -379,33 +379,12 @@ describe('Plugin', function () {
379379
})
380380

381381
describe('for static files', () => {
382-
it.only('should do automatic instrumentation for assets', done => {
382+
it('should do automatic instrumentation for assets', done => {
383383
agent
384384
.use(traces => {
385-
console.log('TRACES', traces)
386-
/*
387-
* TRACES [
388-
[
389-
{
390-
type: 'web',
391-
trace_id: [Int64],
392-
span_id: [Int64],
393-
parent_id: [Int64],
394-
name: 'web.request',
395-
resource: 'GET',
396-
service: 'test',
397-
error: 0,
398-
start: [Int64],
399-
duration: [Int64],
400-
meta: [Object],
401-
metrics: [Object]
402-
}
403-
]
404-
]
405-
*/
406385
const spans = traces[0]
407386

408-
expect(spans[1]).to.have.property('name', 'next.request') // TODO: Target null or undefined
387+
expect(spans[1]).to.have.property('name', 'next.request')
409388
expect(spans[1]).to.have.property('service', 'test')
410389
expect(spans[1]).to.have.property('type', 'web')
411390
expect(spans[1]).to.have.property('resource', 'GET /public/*')
@@ -428,30 +407,9 @@ describe('Plugin', function () {
428407

429408
agent
430409
.use(traces => {
431-
console.log('TRACES', traces)
432-
/*
433-
* TRACES [
434-
[
435-
{
436-
type: 'web',
437-
trace_id: [Int64],
438-
span_id: [Int64],
439-
parent_id: [Int64],
440-
name: 'web.request',
441-
resource: 'GET',
442-
service: 'test',
443-
error: 0,
444-
start: [Int64],
445-
duration: [Int64],
446-
meta: [Object],
447-
metrics: [Object]
448-
}
449-
]
450-
]
451-
*/
452410
const spans = traces[0]
453411

454-
expect(spans[1]).to.have.property('name', 'next.request') // TODO: Target null or undefined
412+
expect(spans[1]).to.have.property('name', 'next.request')
455413
expect(spans[1]).to.have.property('resource', 'GET /_next/static/*')
456414
expect(spans[1].meta).to.have.property('http.method', 'GET')
457415
expect(spans[1].meta).to.have.property('http.status_code', '200')
@@ -468,31 +426,10 @@ describe('Plugin', function () {
468426
it('should pass resource path to parent span', done => {
469427
agent
470428
.use(traces => {
471-
console.log('TRACES', traces)
472-
/*
473-
TRACES [
474-
[
475-
{
476-
type: 'web',
477-
trace_id: [Int64],
478-
span_id: [Int64],
479-
parent_id: [Int64],
480-
name: 'web.request',
481-
resource: 'GET',
482-
service: 'test',
483-
error: 0,
484-
start: [Int64],
485-
duration: [Int64],
486-
meta: [Object],
487-
metrics: [Object]
488-
}
489-
]
490-
]
491-
*/
492429
const spans = traces[0]
493430

494431
expect(spans[0]).to.have.property('name', 'web.request')
495-
expect(spans[0]).to.have.property('resource', 'GET /public/*') // TODO: only set to GET
432+
expect(spans[0]).to.have.property('resource', 'GET /public/*')
496433
})
497434
.then(done)
498435
.catch(done)
@@ -629,29 +566,9 @@ describe('Plugin', function () {
629566
it(`should do automatic instrumentation for ${test}`, done => {
630567
agent
631568
.use(traces => {
632-
console.log('TRACES', traces)
633-
/*
634-
TRACES [
635-
[
636-
{
637-
type: 'web',
638-
trace_id: [Int64],
639-
span_id: [Int64],
640-
parent_id: [Int64],
641-
name: 'web.request',
642-
resource: 'GET',
643-
service: 'test',
644-
error: 0,
645-
start: [Int64],
646-
duration: [Int64],
647-
meta: [Object],
648-
metrics: [Object]
649-
}
650-
]
651-
* */
652569
const spans = traces[0]
653570

654-
expect(spans[1]).to.have.property('name', 'next.request') // TODO: Target null or undefined
571+
expect(spans[1]).to.have.property('name', 'next.request')
655572
expect(spans[1]).to.have.property('service', 'test')
656573
expect(spans[1]).to.have.property('type', 'web')
657574
expect(spans[1]).to.have.property('resource', expectedResource)

0 commit comments

Comments
 (0)