Skip to content

Commit 81650e1

Browse files
chore: Removed unnecessary superagent context propagation (#3798)
1 parent 1d6fe52 commit 81650e1

File tree

7 files changed

+26
-221
lines changed

7 files changed

+26
-221
lines changed

lib/instrumentation/superagent.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

lib/instrumentations.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module.exports = function instrumentations() {
2727
q: { type: null },
2828
redis: { type: InstrumentationDescriptor.TYPE_DATASTORE },
2929
restify: { type: InstrumentationDescriptor.TYPE_WEB_FRAMEWORK },
30-
superagent: { type: InstrumentationDescriptor.TYPE_GENERIC },
3130
when: { module: './instrumentation/when' },
3231
winston: { type: InstrumentationDescriptor.TYPE_GENERIC }
3332
}

test/unit/instrumentation/superagent/newrelic.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/unit/instrumentation/superagent/superagent.test.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

test/versioned/superagent/async-await.test.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/versioned/superagent/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
}
1515
},
1616
"files": [
17-
"async-await.test.js",
1817
"superagent.test.js"
1918
]
2019
}]

test/versioned/superagent/superagent.test.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const test = require('node:test')
99
const assert = require('node:assert')
1010

1111
const { removeModules } = require('../../lib/cache-buster')
12-
const { assertPackageMetrics, match } = require('../../lib/custom-assertions')
12+
const { match } = require('../../lib/custom-assertions')
1313
const helper = require('../../lib/agent_helper')
1414
const testServer = require('./test-server')
1515

@@ -33,11 +33,9 @@ test.afterEach(async (ctx) => {
3333
await ctx.nr.stopServer()
3434
})
3535

36-
test('should log tracking metrics', function(t) {
37-
const { agent } = t.nr
38-
const { version } = require('superagent/package.json')
39-
assertPackageMetrics({ agent, pkg: 'superagent', version })
40-
})
36+
// We no longer instrument `superagent`, but the tests
37+
// are still here to make sure our new context manager
38+
// is propagating correctly.
4139

4240
test('should maintain transaction context with callbacks', (t, end) => {
4341
const { address, agent, request } = t.nr
@@ -49,12 +47,6 @@ test('should maintain transaction context with callbacks', (t, end) => {
4947
const [mainSegment] = tx.trace.getChildren(tx.trace.root.id)
5048
assert.ok(mainSegment)
5149
match(mainSegment.name, EXTERNAL_NAME, 'has segment matching request')
52-
const mainChildren = tx.trace.getChildren(mainSegment.id)
53-
assert.equal(
54-
mainChildren.filter((c) => c.name === 'Callback: testCallback').length,
55-
1,
56-
'has segment matching callback'
57-
)
5850

5951
end()
6052
})
@@ -78,12 +70,6 @@ test('should maintain transaction context with promises', (t, end) => {
7870
const [mainSegment] = tx.trace.getChildren(tx.trace.root.id)
7971
assert.ok(mainSegment)
8072
match(mainSegment.name, EXTERNAL_NAME, 'has segment matching request')
81-
const mainChildren = tx.trace.getChildren(mainSegment.id)
82-
assert.equal(
83-
mainChildren.filter((c) => c.name === 'Callback: <anonymous>').length,
84-
1,
85-
'has segment matching callback'
86-
)
8773

8874
end()
8975
})
@@ -97,3 +83,25 @@ test('should not create segment for a promise if not in a transaction', (t, end)
9783
end()
9884
})
9985
})
86+
87+
test('should maintain transaction context with promises, async-await', (t, end) => {
88+
const { address, agent } = t.nr
89+
helper.runInTransaction(agent, async function (tx) {
90+
assert.ok(tx)
91+
92+
const { request } = t.nr
93+
await request.get(address)
94+
95+
const [mainSegment] = tx.trace.getChildren(tx.trace.root.id)
96+
assert.ok(mainSegment)
97+
match(mainSegment.name, EXTERNAL_NAME, 'has segment matching request')
98+
99+
end()
100+
})
101+
})
102+
103+
test('should not create segment if not in a transaction, async-await', async (t) => {
104+
const { address, agent, request } = t.nr
105+
await request.get(address)
106+
assert.equal(agent.getTransaction(), undefined, 'should not have a transaction')
107+
})

0 commit comments

Comments
 (0)