Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/apm-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ jobs:
api_key: ${{ secrets.DD_API_KEY }}
service: dd-trace-js-tests

cookie-parser:
runs-on: ubuntu-latest
env:
PLUGINS: cookie-parser
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
- uses: ./.github/actions/plugins/test
with:
dd_api_key: ${{ secrets.DD_API_KEY }}

couchbase:
strategy:
matrix:
Expand Down
2 changes: 2 additions & 0 deletions packages/datadog-instrumentations/src/cookie-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ addHook({
name: 'cookie-parser',
versions: ['>=1.0.0']
}, cookieParser => {
// This prevents the non default export from entering the wrapping process
if (cookieParser.default) return cookieParser
return shimmer.wrapFunction(cookieParser, cookieParser => function () {
const cookieMiddleware = cookieParser.apply(this, arguments)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'

const {
createSandbox, varySandbox, curl,
FakeAgent, spawnPluginIntegrationTestProc
} = require('../../../../integration-tests/helpers')
const { assert } = require('chai')
const { withVersions } = require('../../../dd-trace/test/setup/mocha')

withVersions('cookie-parser', 'cookie-parser', version => {
describe('ESM', () => {
let sandbox, variants, proc, agent

before(async function () {
this.timeout(50000)
sandbox = await createSandbox([`'cookie-parser@${version}'`, 'express'], false,
['./packages/datadog-plugin-cookie-parser/test/integration-test/*'])
variants = varySandbox(sandbox, 'server.mjs', 'cookie-parser', 'cookieParser')
})

after(async function () {
this.timeout(50000)
await sandbox.remove()
})

beforeEach(async () => {
agent = await new FakeAgent().start()
})

afterEach(async () => {
proc?.kill()
await agent.stop()
})

for (const variant of varySandbox.VARIANTS) {
it(`is instrumented loaded with ${variant}`, async () => {
proc = await spawnPluginIntegrationTestProc(sandbox.folder, variants[variant], agent.port)
const response = await curl(proc)
assert.equal(response.headers['x-counter'], '1')
})
}
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'dd-trace/init.js'
import express from 'express'
import cookieParser from 'cookie-parser'
import dc from 'dc-polyfill'
const cookieParserReadCh = dc.channel('datadog:cookie-parser:read:finish')
let counter = 0
cookieParserReadCh.subscribe(() => {
counter += 1
})
const app = express()

app.use(cookieParser())
app.use((req, res) => {
res.setHeader('X-Counter', counter)
res.end('hello, world\n')
})

const server = app.listen(0, () => {
const port = server.address().port
process.send({ port })
})
3 changes: 2 additions & 1 deletion packages/dd-trace/test/plugins/plugin-structure.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const abstractPlugins = [
const missingPlugins = [
'datadog-plugin-axios', // we test axios to ensure our functionality works with axios, see: https://github.com/DataDog/dd-trace-js/pull/1469
'datadog-plugin-limitd-client', // limitd-client instrumentation handles trace context propagation, no tracing is done
'datadog-plugin-mongoose' // mongoose tracing is done through mongodb-core instrumentation
'datadog-plugin-mongoose', // mongoose tracing is done through mongodb-core instrumentation
'datadog-plugin-cookie-parser' // cookie-parser does not produce spans
]

// instrumentations that do not have a hook, but are still instrumented
Expand Down