From 53c06322ae568fe38e94a2cb2cde981d9783f209 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Wed, 18 Sep 2024 16:24:44 -0400 Subject: [PATCH 01/23] adds azure functions plugin --- index.d.ts | 7 ++ .../src/azure-functions.js | 48 +++++++++++ .../src/helpers/hooks.js | 1 + .../src/index.js | 84 +++++++++++++++++++ packages/dd-trace/src/plugins/index.js | 1 + packages/dd-trace/src/plugins/util/web.js | 6 +- .../src/service-naming/schemas/v0/index.js | 3 +- .../service-naming/schemas/v0/serverless.js | 12 +++ .../src/service-naming/schemas/v1/index.js | 3 +- .../service-naming/schemas/v1/serverless.js | 12 +++ 10 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 packages/datadog-instrumentations/src/azure-functions.js create mode 100644 packages/datadog-plugin-azure-functions/src/index.js create mode 100644 packages/dd-trace/src/service-naming/schemas/v0/serverless.js create mode 100644 packages/dd-trace/src/service-naming/schemas/v1/serverless.js diff --git a/index.d.ts b/index.d.ts index 1d0e2473d01..403d1fd0097 100644 --- a/index.d.ts +++ b/index.d.ts @@ -148,6 +148,7 @@ interface Plugins { "amqplib": tracer.plugins.amqplib; "apollo": tracer.plugins.apollo; "aws-sdk": tracer.plugins.aws_sdk; + "azure-functions": tracer.plugins.azure_functions; "bunyan": tracer.plugins.bunyan; "cassandra-driver": tracer.plugins.cassandra_driver; "child_process": tracer.plugins.child_process; @@ -1237,6 +1238,12 @@ declare namespace tracer { [key: string]: boolean | Object | undefined; } + /** + * This plugin automatically instruments the + * azure.functions module. + */ + interface azure_functions extends Instrumentation {} + /** * This plugin patches the [bunyan](https://github.com/trentm/node-bunyan) * to automatically inject trace identifiers in log records when the diff --git a/packages/datadog-instrumentations/src/azure-functions.js b/packages/datadog-instrumentations/src/azure-functions.js new file mode 100644 index 00000000000..2527d9afb3f --- /dev/null +++ b/packages/datadog-instrumentations/src/azure-functions.js @@ -0,0 +1,48 @@ +'use strict' + +const { + addHook +} = require('./helpers/instrument') +const shimmer = require('../../datadog-shimmer') +const dc = require('dc-polyfill') + +const azureFunctionsChannel = dc.tracingChannel('datadog:azure-functions:invoke') + +addHook({ name: '@azure/functions', versions: ['>=4'] }, azureFunction => { + const { app } = azureFunction + + shimmer.wrap(app, 'deleteRequest', wrapHandler) + shimmer.wrap(app, 'http', wrapHandler) + shimmer.wrap(app, 'get', wrapHandler) + shimmer.wrap(app, 'patch', wrapHandler) + shimmer.wrap(app, 'post', wrapHandler) + shimmer.wrap(app, 'put', wrapHandler) + + return azureFunction +}) + +// The http methods are overloaded so we need to check which type of argument was passed in order to wrap the handler +// The arguments are either an object with a handler property or the handler function itself +function wrapHandler (method) { + return function (name, arg) { + if (typeof arg === 'object' && arg.hasOwnProperty('handler')) { + const options = arg + shimmer.wrap(options, 'handler', handler => traceHandler(handler, name, method.name)) + } else if (typeof arg === 'function') { + const handler = arg + arguments[1] = shimmer.wrapFunction(handler, handler => traceHandler(handler, name, method.name)) + } + return method.apply(this, arguments) + } +} + +function traceHandler (handler, functionName, methodName) { + return function (...args) { + const httpRequest = args[0] + const invocationContext = args[1] + return azureFunctionsChannel.tracePromise( + handler, + { functionName, httpRequest, invocationContext, methodName }, + this, ...args) + } +} diff --git a/packages/datadog-instrumentations/src/helpers/hooks.js b/packages/datadog-instrumentations/src/helpers/hooks.js index 284e4ed5950..7db3a33d89f 100644 --- a/packages/datadog-instrumentations/src/helpers/hooks.js +++ b/packages/datadog-instrumentations/src/helpers/hooks.js @@ -5,6 +5,7 @@ module.exports = { '@apollo/gateway': () => require('../apollo'), 'apollo-server-core': () => require('../apollo-server-core'), '@aws-sdk/smithy-client': () => require('../aws-sdk'), + '@azure/functions': () => require('../azure-functions'), '@cucumber/cucumber': () => require('../cucumber'), '@playwright/test': () => require('../playwright'), '@elastic/elasticsearch': () => require('../elasticsearch'), diff --git a/packages/datadog-plugin-azure-functions/src/index.js b/packages/datadog-plugin-azure-functions/src/index.js new file mode 100644 index 00000000000..c74f9c382d4 --- /dev/null +++ b/packages/datadog-plugin-azure-functions/src/index.js @@ -0,0 +1,84 @@ +'use strict' + +const TracingPlugin = require('../../dd-trace/src/plugins/tracing') +const { storage } = require('../../datadog-core') +const web = require('../../dd-trace/src/plugins/util/web') + +const triggerMap = { + deleteRequest: 'Http', + http: 'Http', + get: 'Http', + patch: 'Http', + post: 'Http', + put: 'Http' +} + +class AzureFunctionsPlugin extends TracingPlugin { + static get id () { return 'azure-functions' } + static get operation () { return 'invoke' } + static get kind () { return 'server' } + static get type () { return 'serverless' } + + static get prefix () { return 'tracing:datadog:azure-functions:invoke' } + + bindStart (ctx) { + const { functionName, methodName } = ctx + const store = storage.getStore() + + const span = this.startSpan(this.operationName(), { + service: this.serviceName(), + type: 'serverless', + meta: { + 'aas.function.name': functionName, + 'aas.function.trigger': mapTriggerTag(methodName) + } + }, false) + + ctx.span = span + ctx.parentStore = store + ctx.currentStore = { ...store, span } + + return ctx.currentStore + } + + error (ctx) { + this.addError(ctx.error) + ctx.currentStore.span.setTag('error.message', ctx.error) + } + + asyncEnd (ctx) { + const { httpRequest, result = {} } = ctx + const path = extractPath(httpRequest.url) + const req = { + method: httpRequest.method, + headers: Object.fromEntries(httpRequest.headers.entries()), + url: path + } + + const context = web.patch(req) + context.span = ctx.currentStore.span + context.config = this.config + context.paths = [path] + + // Use status for status code if available. Otherwise if no status is provided assume an internal server error + context.res = { statusCode: result.hasOwnProperty('status') ? result.status : 500 } + + web.finishSpan(context) + } + + configure (config) { + return super.configure(web.normalizeConfig(config)) + } +} + +function extractPath (url) { + const regex = /https?:\/\/[^/]+(\/.*$)/ + const match = url.match(regex) + return match ? match[1] : '' +} + +function mapTriggerTag (methodName) { + return triggerMap[methodName] || 'Unknown' +} + +module.exports = AzureFunctionsPlugin diff --git a/packages/dd-trace/src/plugins/index.js b/packages/dd-trace/src/plugins/index.js index 06325724b71..48146416281 100644 --- a/packages/dd-trace/src/plugins/index.js +++ b/packages/dd-trace/src/plugins/index.js @@ -3,6 +3,7 @@ module.exports = { get '@apollo/gateway' () { return require('../../../datadog-plugin-apollo/src') }, get '@aws-sdk/smithy-client' () { return require('../../../datadog-plugin-aws-sdk/src') }, + get '@azure/functions' () { return require('../../../datadog-plugin-azure-functions/src') }, get '@cucumber/cucumber' () { return require('../../../datadog-plugin-cucumber/src') }, get '@playwright/test' () { return require('../../../datadog-plugin-playwright/src') }, get '@elastic/elasticsearch' () { return require('../../../datadog-plugin-elasticsearch/src') }, diff --git a/packages/dd-trace/src/plugins/util/web.js b/packages/dd-trace/src/plugins/util/web.js index c9cdf1990aa..98e525baad4 100644 --- a/packages/dd-trace/src/plugins/util/web.js +++ b/packages/dd-trace/src/plugins/util/web.js @@ -427,11 +427,13 @@ function addRequestTags (context) { const { req, span, config } = context const url = extractURL(req) + const tags = span.context()._tags + span.addTags({ [HTTP_URL]: web.obfuscateQs(config, url), [HTTP_METHOD]: req.method, - [SPAN_KIND]: SERVER, - [SPAN_TYPE]: WEB, + [SPAN_KIND]: tags[SPAN_TYPE] === 'serverless' ? null : SERVER, + [SPAN_TYPE]: tags[SPAN_TYPE] === 'serverless' ? 'serverless' : WEB, [HTTP_USERAGENT]: req.headers['user-agent'] }) diff --git a/packages/dd-trace/src/service-naming/schemas/v0/index.js b/packages/dd-trace/src/service-naming/schemas/v0/index.js index c2751a64bf0..1b0b746035d 100644 --- a/packages/dd-trace/src/service-naming/schemas/v0/index.js +++ b/packages/dd-trace/src/service-naming/schemas/v0/index.js @@ -3,5 +3,6 @@ const messaging = require('./messaging') const storage = require('./storage') const graphql = require('./graphql') const web = require('./web') +const serverless = require('./serverless') -module.exports = new SchemaDefinition({ messaging, storage, web, graphql }) +module.exports = new SchemaDefinition({ messaging, storage, web, graphql, serverless }) diff --git a/packages/dd-trace/src/service-naming/schemas/v0/serverless.js b/packages/dd-trace/src/service-naming/schemas/v0/serverless.js new file mode 100644 index 00000000000..fcccdcb465a --- /dev/null +++ b/packages/dd-trace/src/service-naming/schemas/v0/serverless.js @@ -0,0 +1,12 @@ +const { identityService } = require('../util') + +const serverless = { + server: { + 'azure-functions': { + opName: () => 'azure-functions.invoke', + serviceName: identityService + } + } +} + +module.exports = serverless diff --git a/packages/dd-trace/src/service-naming/schemas/v1/index.js b/packages/dd-trace/src/service-naming/schemas/v1/index.js index c2751a64bf0..1b0b746035d 100644 --- a/packages/dd-trace/src/service-naming/schemas/v1/index.js +++ b/packages/dd-trace/src/service-naming/schemas/v1/index.js @@ -3,5 +3,6 @@ const messaging = require('./messaging') const storage = require('./storage') const graphql = require('./graphql') const web = require('./web') +const serverless = require('./serverless') -module.exports = new SchemaDefinition({ messaging, storage, web, graphql }) +module.exports = new SchemaDefinition({ messaging, storage, web, graphql, serverless }) diff --git a/packages/dd-trace/src/service-naming/schemas/v1/serverless.js b/packages/dd-trace/src/service-naming/schemas/v1/serverless.js new file mode 100644 index 00000000000..fcccdcb465a --- /dev/null +++ b/packages/dd-trace/src/service-naming/schemas/v1/serverless.js @@ -0,0 +1,12 @@ +const { identityService } = require('../util') + +const serverless = { + server: { + 'azure-functions': { + opName: () => 'azure-functions.invoke', + serviceName: identityService + } + } +} + +module.exports = serverless From a82c48225e00deb7c93e93df0940ac0c797f6eb1 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Mon, 23 Sep 2024 09:11:38 -0400 Subject: [PATCH 02/23] adds azure_functions plugin to API documentation --- docs/API.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/API.md b/docs/API.md index 68cdc3747cb..13bddc2054b 100644 --- a/docs/API.md +++ b/docs/API.md @@ -27,6 +27,7 @@ tracer.use('pg', {
+
@@ -102,6 +103,7 @@ tracer.use('pg', { * [amqp10](./interfaces/export_.plugins.amqp10.html) * [amqplib](./interfaces/export_.plugins.amqplib.html) * [aws-sdk](./interfaces/export_.plugins.aws_sdk.html) +* [azure-functions](./interfaces/export_.plugins.azure_functions.html) * [bluebird](./interfaces/export_.plugins.bluebird.html) * [couchbase](./interfaces/export_.plugins.couchbase.html) * [cucumber](./interfaces/export_.plugins.cucumber.html) From 45db12c2a7d40a04156a6f3e855cbffcecfb12f4 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Tue, 24 Sep 2024 10:19:46 -0400 Subject: [PATCH 03/23] add typescript test for azure functions plugin --- docs/test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/test.ts b/docs/test.ts index 07b96a01673..9d96864f5d1 100644 --- a/docs/test.ts +++ b/docs/test.ts @@ -283,6 +283,7 @@ tracer.use('amqp10'); tracer.use('amqplib'); tracer.use('aws-sdk'); tracer.use('aws-sdk', awsSdkOptions); +tracer.use('azure-functions'); tracer.use('bunyan'); tracer.use('couchbase'); tracer.use('cassandra-driver'); From 6bd7123ba5f6fdac03fdd0a24738188383893189 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Fri, 27 Sep 2024 16:03:50 -0400 Subject: [PATCH 04/23] adds integration test for azure-functions plugin --- .gitignore | 1 + integration-tests/helpers/index.js | 1 + package.json | 4 +- .../test/integration-test/client.spec.js | 81 ++++++ .../test/integration-test/fixtures/host.json | 15 + .../fixtures/local.settings.json | 8 + .../integration-test/fixtures/package.json | 15 + .../fixtures/src/functions/server.mjs | 15 + .../test/integration-test/fixtures/yarn.lock | 269 ++++++++++++++++++ yarn.lock | 91 ++++++ 10 files changed, 499 insertions(+), 1 deletion(-) create mode 100644 packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js create mode 100644 packages/datadog-plugin-azure-functions/test/integration-test/fixtures/host.json create mode 100644 packages/datadog-plugin-azure-functions/test/integration-test/fixtures/local.settings.json create mode 100644 packages/datadog-plugin-azure-functions/test/integration-test/fixtures/package.json create mode 100644 packages/datadog-plugin-azure-functions/test/integration-test/fixtures/src/functions/server.mjs create mode 100644 packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock diff --git a/.gitignore b/.gitignore index ff2cfaa8e23..a8dcafe063b 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,4 @@ packages/dd-trace/test/appsec/next/*/package.json packages/dd-trace/test/appsec/next/*/node_modules packages/dd-trace/test/appsec/next/*/yarn.lock !packages/dd-trace/**/telemetry/logs +packages/datadog-plugin-azure-functions/test/integration-test/fixtures/node_modules diff --git a/integration-tests/helpers/index.js b/integration-tests/helpers/index.js index 98074ba89b4..09cc6c5bee4 100644 --- a/integration-tests/helpers/index.js +++ b/integration-tests/helpers/index.js @@ -358,6 +358,7 @@ function assertUUID (actual, msg = 'not a valid UUID') { module.exports = { FakeAgent, + hookFile, assertObjectContains, assertUUID, spawnProc, diff --git a/package.json b/package.json index 67d4c132a19..6781bfb743b 100644 --- a/package.json +++ b/package.json @@ -128,6 +128,7 @@ "eslint-plugin-n": "^16.6.2", "eslint-plugin-promise": "^6.4.0", "express": "^4.18.2", + "find-process": "^1.4.7", "get-port": "^3.2.0", "glob": "^7.1.6", "graphql": "0.13.2", @@ -143,6 +144,7 @@ "sinon": "^15.2.0", "sinon-chai": "^3.7.0", "tap": "^16.3.7", - "tiktoken": "^1.0.15" + "tiktoken": "^1.0.15", + "wait-on": "^8.0.1" } } diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js new file mode 100644 index 00000000000..5eae7154b51 --- /dev/null +++ b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js @@ -0,0 +1,81 @@ +'use strict' + +const { + FakeAgent, + hookFile, + createSandbox, + curlAndAssertMessage +} = require('../../../../integration-tests/helpers') +const { spawn } = require('child_process') +const { assert } = require('chai') +const findProcess = require('find-process') +const waitOn = require('wait-on') + +describe('esm', () => { + let agent + let command + let proc + let sandbox + + withVersions('azure-functions', '@azure/functions', version => { + before(async function () { + this.timeout(50000) + sandbox = await createSandbox([`@azure/functions@${version}`, 'azure-functions-core-tools@4'], false, + ['./packages/datadog-plugin-azure-functions/test/integration-test/fixtures/*']) + command = `${sandbox.folder}/node_modules/.bin/func` + }) + + after(async function () { + this.timeout(50000) + await sandbox.remove() + }) + + beforeEach(async () => { + agent = await new FakeAgent().start() + }) + + afterEach(async () => { + const azureFuncProc = await findProcess('name', 'func', true) + const azureFuncProcPid = azureFuncProc[0]?.pid ?? null + azureFuncProcPid !== null && process.kill(azureFuncProcPid, 'SIGKILL') + + proc && proc.kill() + await agent.stop() + }) + + it('is instrumented', async () => { + proc = await spawnPluginIntegrationTestProc(sandbox.folder, command, ['start'], agent.port) + + return curlAndAssertMessage(agent, 'http://127.0.0.1:7071/api/httpexample', ({ headers, payload }) => { + assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) + assert.isArray(payload) + assert.strictEqual(payload.length, 1) + assert.isArray(payload[0]) + assert.strictEqual(payload[0].length, 1) + assert.propertyVal(payload[0][0], 'name', 'azure-functions.invoke') + }) + }).timeout(50000) + }) +}) + +async function spawnPluginIntegrationTestProc (cwd, command, args, agentPort) { + const env = { + NODE_OPTIONS: `--loader=${hookFile}`, + DD_TRACE_AGENT_PORT: agentPort, + PATH: `${process.execPath}:${process.env.PATH}` // Pass node path to child process + } + + return await spawnProc(command, args, { + cwd, + env + }) +} + +async function spawnProc (command, args, options = {}) { + const proc = spawn(command, args, { ...options, stdio: 'inherit' }) + await waitOn({ + resources: ['http-get://127.0.0.1:7071'], + timeout: 5000 + }) + return proc +} diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/host.json b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/host.json new file mode 100644 index 00000000000..06d01bdaa95 --- /dev/null +++ b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/host.json @@ -0,0 +1,15 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[4.*, 5.0.0)" + } +} diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/local.settings.json b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/local.settings.json new file mode 100644 index 00000000000..6beb0236ad6 --- /dev/null +++ b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/local.settings.json @@ -0,0 +1,8 @@ +{ + "IsEncrypted": false, + "Values": { + "FUNCTIONS_WORKER_RUNTIME": "node", + "AzureWebJobsFeatureFlags": "EnableWorkerIndexing", + "AzureWebJobsStorage": "" + } +} diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/package.json b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/package.json new file mode 100644 index 00000000000..07b0ac311ee --- /dev/null +++ b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/package.json @@ -0,0 +1,15 @@ +{ + "name": "azure-function-node-integration-test", + "version": "1.0.0", + "description": "", + "main": "src/functions/server.mjs", + "scripts": { + "start": "func start" + }, + "dependencies": { + "@azure/functions": "^4.0.0" + }, + "devDependencies": { + "azure-functions-core-tools": "^4.x" + } +} diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/src/functions/server.mjs b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/src/functions/server.mjs new file mode 100644 index 00000000000..c2d640974a5 --- /dev/null +++ b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/src/functions/server.mjs @@ -0,0 +1,15 @@ +import 'dd-trace/init.js' +import { app } from '@azure/functions' + +async function handlerFunction (request, context) { + return { + status: 200, + body: 'Hello Datadog!' + } +} + +app.http('httpexample', { + methods: ['GET'], + authLevel: 'anonymous', + handler: handlerFunction +}) diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock new file mode 100644 index 00000000000..98c420c8953 --- /dev/null +++ b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock @@ -0,0 +1,269 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@azure/functions@^4.0.0": + version "4.5.1" + resolved "https://registry.yarnpkg.com/@azure/functions/-/functions-4.5.1.tgz#70d1a99d335af87579a55d3c149ef1ae77da0a66" + integrity sha512-ikiw1IrM2W9NlQM3XazcX+4Sq3XAjZi4eeG22B5InKC2x5i7MatGF2S/Gn1ACZ+fEInwu+Ru9J8DlnBv1/hIvg== + dependencies: + cookie "^0.6.0" + long "^4.0.0" + undici "^5.13.0" + +"@fastify/busboy@^2.0.0": + version "2.1.1" + resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" + integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== + +"@types/node@*": + version "22.7.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.7.4.tgz#e35d6f48dca3255ce44256ddc05dee1c23353fcc" + integrity sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg== + dependencies: + undici-types "~6.19.2" + +"@types/yauzl@^2.9.1": + version "2.10.3" + resolved "https://registry.yarnpkg.com/@types/yauzl/-/yauzl-2.10.3.tgz#e9b2808b4f109504a03cda958259876f61017999" + integrity sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q== + dependencies: + "@types/node" "*" + +agent-base@6: + version "6.0.2" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" + integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ== + dependencies: + debug "4" + +ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== + dependencies: + color-convert "^2.0.1" + +azure-functions-core-tools@^4.x: + version "4.0.6280" + resolved "https://registry.yarnpkg.com/azure-functions-core-tools/-/azure-functions-core-tools-4.0.6280.tgz#59b4d9402846760aef3ad292355c3eeb4e5f21ad" + integrity sha512-DVSgYNnT4POLbj/YV3FKtNdo9KT/M5Dl//slWEmVwZo1y4aJEsUApn6DtkZswut76I3S9eKGC5IaC84j5OGNaA== + dependencies: + chalk "3.0.0" + extract-zip "^2.0.1" + https-proxy-agent "5.0.0" + progress "2.0.3" + rimraf "4.4.1" + +balanced-match@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== + +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + +buffer-crc32@~0.2.3: + version "0.2.13" + resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242" + integrity sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ== + +chalk@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4" + integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + +cookie@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051" + integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw== + +debug@4, debug@^4.1.1: + version "4.3.7" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52" + integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ== + dependencies: + ms "^2.1.3" + +end-of-stream@^1.1.0: + version "1.4.4" + resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0" + integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q== + dependencies: + once "^1.4.0" + +extract-zip@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/extract-zip/-/extract-zip-2.0.1.tgz#663dca56fe46df890d5f131ef4a06d22bb8ba13a" + integrity sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg== + dependencies: + debug "^4.1.1" + get-stream "^5.1.0" + yauzl "^2.10.0" + optionalDependencies: + "@types/yauzl" "^2.9.1" + +fd-slicer@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.1.0.tgz#25c7c89cb1f9077f8891bbe61d8f390eae256f1e" + integrity sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g== + dependencies: + pend "~1.2.0" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== + +get-stream@^5.1.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.2.0.tgz#4966a1795ee5ace65e706c4b7beb71257d6e22d3" + integrity sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA== + dependencies: + pump "^3.0.0" + +glob@^9.2.0: + version "9.3.5" + resolved "https://registry.yarnpkg.com/glob/-/glob-9.3.5.tgz#ca2ed8ca452781a3009685607fdf025a899dfe21" + integrity sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q== + dependencies: + fs.realpath "^1.0.0" + minimatch "^8.0.2" + minipass "^4.2.4" + path-scurry "^1.6.1" + +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + +https-proxy-agent@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2" + integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA== + dependencies: + agent-base "6" + debug "4" + +long@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" + integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== + +lru-cache@^10.2.0: + version "10.4.3" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119" + integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ== + +minimatch@^8.0.2: + version "8.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-8.0.4.tgz#847c1b25c014d4e9a7f68aaf63dedd668a626229" + integrity sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA== + dependencies: + brace-expansion "^2.0.1" + +minipass@^4.2.4: + version "4.2.8" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-4.2.8.tgz#f0010f64393ecfc1d1ccb5f582bcaf45f48e1a3a" + integrity sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ== + +"minipass@^5.0.0 || ^6.0.2 || ^7.0.0": + version "7.1.2" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.1.2.tgz#93a9626ce5e5e66bd4db86849e7515e92340a707" + integrity sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw== + +ms@^2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + +once@^1.3.1, once@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w== + dependencies: + wrappy "1" + +path-scurry@^1.6.1: + version "1.11.1" + resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-1.11.1.tgz#7960a668888594a0720b12a911d1a742ab9f11d2" + integrity sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA== + dependencies: + lru-cache "^10.2.0" + minipass "^5.0.0 || ^6.0.2 || ^7.0.0" + +pend@~1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50" + integrity sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg== + +progress@2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" + integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== + +pump@^3.0.0: + version "3.0.2" + resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.2.tgz#836f3edd6bc2ee599256c924ffe0d88573ddcbf8" + integrity sha512-tUPXtzlGM8FE3P0ZL6DVs/3P58k9nk8/jZeQCurTJylQA8qFYzHFfhBJkuqyE0FifOsQ0uKWekiZ5g8wtr28cw== + dependencies: + end-of-stream "^1.1.0" + once "^1.3.1" + +rimraf@4.4.1: + version "4.4.1" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-4.4.1.tgz#bd33364f67021c5b79e93d7f4fa0568c7c21b755" + integrity sha512-Gk8NlF062+T9CqNGn6h4tls3k6T1+/nXdOcSZVikNVtlRdYpA7wRJJMoXmuvOnLW844rPjdQ7JgXCYM6PPC/og== + dependencies: + glob "^9.2.0" + +supports-color@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== + dependencies: + has-flag "^4.0.0" + +undici-types@~6.19.2: + version "6.19.8" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02" + integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== + +undici@^5.13.0: + version "5.28.4" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" + integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== + dependencies: + "@fastify/busboy" "^2.0.0" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== + +yauzl@^2.10.0: + version "2.10.0" + resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9" + integrity sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g== + dependencies: + buffer-crc32 "~0.2.3" + fd-slicer "~1.1.0" diff --git a/yarn.lock b/yarn.lock index 7557a5e4ea4..0f05459b48f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -444,6 +444,18 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== +"@hapi/hoek@^9.0.0", "@hapi/hoek@^9.3.0": + version "9.3.0" + resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb" + integrity sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ== + +"@hapi/topo@^5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.1.0.tgz#dc448e332c6c6e37a4dc02fd84ba8d44b9afb012" + integrity sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg== + dependencies: + "@hapi/hoek" "^9.0.0" + "@humanwhocodes/config-array@^0.11.14": version "0.11.14" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b" @@ -635,6 +647,23 @@ resolved "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz" integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw== +"@sideway/address@^4.1.5": + version "4.1.5" + resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.5.tgz#4bc149a0076623ced99ca8208ba780d65a99b9d5" + integrity sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q== + dependencies: + "@hapi/hoek" "^9.0.0" + +"@sideway/formula@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@sideway/formula/-/formula-3.0.1.tgz#80fcbcbaf7ce031e0ef2dd29b1bfc7c3f583611f" + integrity sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg== + +"@sideway/pinpoint@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@sideway/pinpoint/-/pinpoint-2.0.0.tgz#cff8ffadc372ad29fd3f78277aeb29e632cc70df" + integrity sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ== + "@sinonjs/commons@^2.0.0": version "2.0.0" resolved "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz" @@ -993,6 +1022,15 @@ axios@^1.7.4: form-data "^4.0.0" proxy-from-env "^1.1.0" +axios@^1.7.7: + version "1.7.7" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f" + integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q== + dependencies: + follow-redirects "^1.15.6" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz" @@ -1370,6 +1408,11 @@ combined-stream@^1.0.6, combined-stream@^1.0.8: dependencies: delayed-stream "~1.0.0" +commander@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae" + integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg== + commander@^9.1.0: version "9.5.0" resolved "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz" @@ -2136,6 +2179,15 @@ find-cache-dir@^3.2.0: make-dir "^3.0.2" pkg-dir "^4.1.0" +find-process@^1.4.7: + version "1.4.7" + resolved "https://registry.yarnpkg.com/find-process/-/find-process-1.4.7.tgz#8c76962259216c381ef1099371465b5b439ea121" + integrity sha512-/U4CYp1214Xrp3u3Fqr9yNynUrr5Le4y0SsJh2lMDDSbpwYSz3M2SMWQC+wqcx79cN8PQtHQIL8KnuY9M66fdg== + dependencies: + chalk "^4.0.0" + commander "^5.1.0" + debug "^4.1.1" + find-up@5.0.0, find-up@^5.0.0: version "5.0.0" resolved "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz" @@ -2947,6 +2999,17 @@ jmespath@0.16.0: resolved "https://registry.npmjs.org/jmespath/-/jmespath-0.16.0.tgz" integrity "sha1-sVsKhd/U2TDUPmntYFlDyAJ4UHY= sha512-9FzQjJ7MATs1tSpnco1K6ayiYE3figslrXA72G2HQ/n76RzvYlofyi5QM+iX4YRs/pu3yzxlVQSST23+dMDknw==" +joi@^17.13.3: + version "17.13.3" + resolved "https://registry.yarnpkg.com/joi/-/joi-17.13.3.tgz#0f5cc1169c999b30d344366d384b12d92558bcec" + integrity sha512-otDA4ldcIx+ZXsKHWmp0YizCweVRZG96J10b0FevjfuncLO1oX59THoAmHkNubYJ+9gWsYsp5k8v4ib6oDv1fA== + dependencies: + "@hapi/hoek" "^9.3.0" + "@hapi/topo" "^5.1.0" + "@sideway/address" "^4.1.5" + "@sideway/formula" "^3.0.1" + "@sideway/pinpoint" "^2.0.0" + "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz" @@ -3238,6 +3301,11 @@ minimist@^1.2.0, minimist@^1.2.6: resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz" integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g== +minimist@^1.2.8: + version "1.2.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" + integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== + minipass@^3.1.5, minipass@^3.1.6, minipass@^3.3.4: version "3.3.6" resolved "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz" @@ -4006,6 +4074,13 @@ run-parallel@^1.1.9: dependencies: queue-microtask "^1.2.2" +rxjs@^7.8.1: + version "7.8.1" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.1.tgz#6f6f3d99ea8044291efd92e7c7fcf562c4057543" + integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg== + dependencies: + tslib "^2.1.0" + safe-array-concat@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/safe-array-concat/-/safe-array-concat-1.1.2.tgz#81d77ee0c4e8b863635227c721278dd524c20edb" @@ -4511,6 +4586,11 @@ tsconfig-paths@^3.15.0: minimist "^1.2.6" strip-bom "^3.0.0" +tslib@^2.1.0: + version "2.7.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01" + integrity sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA== + type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz" @@ -4698,6 +4778,17 @@ vary@~1.1.2: resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz" integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg== +wait-on@^8.0.1: + version "8.0.1" + resolved "https://registry.yarnpkg.com/wait-on/-/wait-on-8.0.1.tgz#13c8ec77115517f8fbc2d670521a444201f03f53" + integrity sha512-1wWQOyR2LVVtaqrcIL2+OM+x7bkpmzVROa0Nf6FryXkS+er5Sa1kzFGjzZRqLnHa3n1rACFLeTwUqE1ETL9Mig== + dependencies: + axios "^1.7.7" + joi "^17.13.3" + lodash "^4.17.21" + minimist "^1.2.8" + rxjs "^7.8.1" + which-boxed-primitive@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz" From f9749c7562081a6219943baff9520e6d222519bd Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Fri, 27 Sep 2024 16:12:13 -0400 Subject: [PATCH 05/23] add licenses for added dev packages --- LICENSE-3rdparty.csv | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 45f88f66cb4..37e1d700639 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -49,6 +49,7 @@ dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck dev,eslint-plugin-n,MIT,Copyright 2015 Toru Nagashima dev,eslint-plugin-promise,ISC,jden and other contributors dev,express,MIT,Copyright 2009-2014 TJ Holowaychuk 2013-2014 Roman Shtylman 2014-2015 Douglas Christopher Wilson +dev,find-process,MIT,Copyright (c) 2016 Zoujie dev,get-port,MIT,Copyright Sindre Sorhus dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors dev,graphql,MIT,Copyright 2015 Facebook Inc. @@ -65,6 +66,7 @@ dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen dev,sinon-chai,WTFPL and BSD-2-Clause,Copyright 2004 Sam Hocevar 2012–2017 Domenic Denicola dev,tap,ISC,Copyright 2011-2022 Isaac Z. Schlueter and Contributors dev,tiktoken,MIT,Copyright (c) 2022 OpenAI, Shantanu Jain +dev,wait-on,MIT,Copyright (c) 2015 Jeff Barczewski file,aws-lambda-nodejs-runtime-interface-client,Apache 2.0,Copyright 2019 Amazon.com Inc. or its affiliates. All Rights Reserved. file,profile.proto,Apache license 2.0,Copyright 2016 Google Inc. file,is-git-url,MIT,Copyright (c) 2017 Jon Schlinkert. From b8b231699dcbc72ba676197062ca5594e5531148 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Fri, 27 Sep 2024 16:14:31 -0400 Subject: [PATCH 06/23] add azure-functions plugin to github workflow --- .github/workflows/plugins.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/plugins.yml b/.github/workflows/plugins.yml index 203584d8523..a8846505fb3 100644 --- a/.github/workflows/plugins.yml +++ b/.github/workflows/plugins.yml @@ -196,6 +196,14 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/plugins/upstream + azure-functions: + runs-on: ubuntu-latest + env: + PLUGINS: azure-functions + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/plugins/test + bluebird: runs-on: ubuntu-latest env: From 1aa235fcc51e32a2e6e6364ede44229e739ce906 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Fri, 27 Sep 2024 16:20:56 -0400 Subject: [PATCH 07/23] use pipe for azure-functions integration test child process --- .../test/integration-test/client.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js index 5eae7154b51..1ca50e949e9 100644 --- a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js @@ -72,7 +72,7 @@ async function spawnPluginIntegrationTestProc (cwd, command, args, agentPort) { } async function spawnProc (command, args, options = {}) { - const proc = spawn(command, args, { ...options, stdio: 'inherit' }) + const proc = spawn(command, args, { ...options, stdio: 'pipe' }) await waitOn({ resources: ['http-get://127.0.0.1:7071'], timeout: 5000 From 500103cb7772239692b354757584e9283acba531 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Fri, 27 Sep 2024 16:31:22 -0400 Subject: [PATCH 08/23] update azure-functions integration test api route --- .../test/integration-test/client.spec.js | 2 +- .../test/integration-test/fixtures/src/functions/server.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js index 1ca50e949e9..05f78718d77 100644 --- a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js @@ -46,7 +46,7 @@ describe('esm', () => { it('is instrumented', async () => { proc = await spawnPluginIntegrationTestProc(sandbox.folder, command, ['start'], agent.port) - return curlAndAssertMessage(agent, 'http://127.0.0.1:7071/api/httpexample', ({ headers, payload }) => { + return curlAndAssertMessage(agent, 'http://127.0.0.1:7071/api/httptest', ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) assert.isArray(payload) assert.strictEqual(payload.length, 1) diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/src/functions/server.mjs b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/src/functions/server.mjs index c2d640974a5..2efdd200732 100644 --- a/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/src/functions/server.mjs +++ b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/src/functions/server.mjs @@ -8,7 +8,7 @@ async function handlerFunction (request, context) { } } -app.http('httpexample', { +app.http('httptest', { methods: ['GET'], authLevel: 'anonymous', handler: handlerFunction From 195082ce7ee49559b7973edd91629bbbf11ac5db Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Fri, 27 Sep 2024 17:53:23 -0400 Subject: [PATCH 09/23] refactor azure-functions integration test --- .../test/integration-test/client.spec.js | 60 ++++++++++++++----- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js index 05f78718d77..262d41d1da6 100644 --- a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js @@ -13,7 +13,6 @@ const waitOn = require('wait-on') describe('esm', () => { let agent - let command let proc let sandbox @@ -22,7 +21,6 @@ describe('esm', () => { this.timeout(50000) sandbox = await createSandbox([`@azure/functions@${version}`, 'azure-functions-core-tools@4'], false, ['./packages/datadog-plugin-azure-functions/test/integration-test/fixtures/*']) - command = `${sandbox.folder}/node_modules/.bin/func` }) after(async function () { @@ -44,7 +42,10 @@ describe('esm', () => { }) it('is instrumented', async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, command, ['start'], agent.port) + const envArgs = { + PATH: process.env.PATH + } + proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'func', ['start'], agent.port, undefined, envArgs) return curlAndAssertMessage(agent, 'http://127.0.0.1:7071/api/httptest', ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) @@ -58,24 +59,53 @@ describe('esm', () => { }) }) -async function spawnPluginIntegrationTestProc (cwd, command, args, agentPort) { - const env = { +async function spawnPluginIntegrationTestProc (cwd, command, args, agentPort, stdioHandler, additionalEnvArgs = {}) { + let env = { NODE_OPTIONS: `--loader=${hookFile}`, - DD_TRACE_AGENT_PORT: agentPort, - PATH: `${process.execPath}:${process.env.PATH}` // Pass node path to child process + DD_TRACE_AGENT_PORT: agentPort } - - return await spawnProc(command, args, { + env = { ...env, ...additionalEnvArgs } + return spawnProc(command, args, { cwd, env - }) + }, stdioHandler) } -async function spawnProc (command, args, options = {}) { +function spawnProc (command, args, options = {}, stdioHandler, stderrHandler) { const proc = spawn(command, args, { ...options, stdio: 'pipe' }) - await waitOn({ - resources: ['http-get://127.0.0.1:7071'], - timeout: 5000 + return new Promise((resolve, reject) => { + waitOn({ + resources: ['http-get://127.0.0.1:7071'], + timeout: 5000 + }).then(() => { + resolve(proc) + }).catch(err => { + reject(new Error(`Error while waiting for process to start: ${err.message}`)) + }) + + proc + .on('error', reject) + .on('exit', code => { + if (code !== 0) { + reject(new Error(`Process exited with status code ${code}.`)) + } + resolve() + }) + + proc.stdout.on('data', data => { + if (stdioHandler) { + stdioHandler(data) + } + // eslint-disable-next-line no-console + if (!options.silent) console.log(data.toString()) + }) + + proc.stderr.on('data', data => { + if (stderrHandler) { + stderrHandler(data) + } + // eslint-disable-next-line no-console + if (!options.silent) console.error(data.toString()) + }) }) - return proc } From d5a3c8d675439832b79402a9ff15617d14a2bef9 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Fri, 27 Sep 2024 17:55:31 -0400 Subject: [PATCH 10/23] add azure func command to path --- .../test/integration-test/client.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js index 262d41d1da6..7c441e72060 100644 --- a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js @@ -43,7 +43,7 @@ describe('esm', () => { it('is instrumented', async () => { const envArgs = { - PATH: process.env.PATH + PATH: `${sandbox.folder}/node_modules/.bin:${process.env.PATH}` } proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'func', ['start'], agent.port, undefined, envArgs) From f1cf495dbd7096b6f8e9d2a4cdd6967576ef0978 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Fri, 27 Sep 2024 18:10:34 -0400 Subject: [PATCH 11/23] remove yarn.lock file from azure-functions integration test --- .../test/integration-test/fixtures/yarn.lock | 269 ------------------ 1 file changed, 269 deletions(-) delete mode 100644 packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock deleted file mode 100644 index 98c420c8953..00000000000 --- a/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock +++ /dev/null @@ -1,269 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -"@azure/functions@^4.0.0": - version "4.5.1" - resolved "https://registry.yarnpkg.com/@azure/functions/-/functions-4.5.1.tgz#70d1a99d335af87579a55d3c149ef1ae77da0a66" - integrity sha512-ikiw1IrM2W9NlQM3XazcX+4Sq3XAjZi4eeG22B5InKC2x5i7MatGF2S/Gn1ACZ+fEInwu+Ru9J8DlnBv1/hIvg== - dependencies: - cookie "^0.6.0" - long "^4.0.0" - undici "^5.13.0" - -"@fastify/busboy@^2.0.0": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" - integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== - -"@types/node@*": - version "22.7.4" - resolved "https://registry.yarnpkg.com/@types/node/-/node-22.7.4.tgz#e35d6f48dca3255ce44256ddc05dee1c23353fcc" - integrity sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg== - dependencies: - undici-types "~6.19.2" - -"@types/yauzl@^2.9.1": - version "2.10.3" - resolved "https://registry.yarnpkg.com/@types/yauzl/-/yauzl-2.10.3.tgz#e9b2808b4f109504a03cda958259876f61017999" - integrity sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q== - dependencies: - "@types/node" "*" - -agent-base@6: - version "6.0.2" - resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" - integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ== - dependencies: - debug "4" - -ansi-styles@^4.1.0: - version "4.3.0" - resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" - integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== - dependencies: - color-convert "^2.0.1" - -azure-functions-core-tools@^4.x: - version "4.0.6280" - resolved "https://registry.yarnpkg.com/azure-functions-core-tools/-/azure-functions-core-tools-4.0.6280.tgz#59b4d9402846760aef3ad292355c3eeb4e5f21ad" - integrity sha512-DVSgYNnT4POLbj/YV3FKtNdo9KT/M5Dl//slWEmVwZo1y4aJEsUApn6DtkZswut76I3S9eKGC5IaC84j5OGNaA== - dependencies: - chalk "3.0.0" - extract-zip "^2.0.1" - https-proxy-agent "5.0.0" - progress "2.0.3" - rimraf "4.4.1" - -balanced-match@^1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" - integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== - -brace-expansion@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" - integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== - dependencies: - balanced-match "^1.0.0" - -buffer-crc32@~0.2.3: - version "0.2.13" - resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242" - integrity sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ== - -chalk@3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4" - integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg== - dependencies: - ansi-styles "^4.1.0" - supports-color "^7.1.0" - -color-convert@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" - integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== - dependencies: - color-name "~1.1.4" - -color-name@~1.1.4: - version "1.1.4" - resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" - integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== - -cookie@^0.6.0: - version "0.6.0" - resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051" - integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw== - -debug@4, debug@^4.1.1: - version "4.3.7" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52" - integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ== - dependencies: - ms "^2.1.3" - -end-of-stream@^1.1.0: - version "1.4.4" - resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0" - integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q== - dependencies: - once "^1.4.0" - -extract-zip@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/extract-zip/-/extract-zip-2.0.1.tgz#663dca56fe46df890d5f131ef4a06d22bb8ba13a" - integrity sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg== - dependencies: - debug "^4.1.1" - get-stream "^5.1.0" - yauzl "^2.10.0" - optionalDependencies: - "@types/yauzl" "^2.9.1" - -fd-slicer@~1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.1.0.tgz#25c7c89cb1f9077f8891bbe61d8f390eae256f1e" - integrity sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g== - dependencies: - pend "~1.2.0" - -fs.realpath@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" - integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== - -get-stream@^5.1.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.2.0.tgz#4966a1795ee5ace65e706c4b7beb71257d6e22d3" - integrity sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA== - dependencies: - pump "^3.0.0" - -glob@^9.2.0: - version "9.3.5" - resolved "https://registry.yarnpkg.com/glob/-/glob-9.3.5.tgz#ca2ed8ca452781a3009685607fdf025a899dfe21" - integrity sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q== - dependencies: - fs.realpath "^1.0.0" - minimatch "^8.0.2" - minipass "^4.2.4" - path-scurry "^1.6.1" - -has-flag@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" - integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== - -https-proxy-agent@5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2" - integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA== - dependencies: - agent-base "6" - debug "4" - -long@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" - integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== - -lru-cache@^10.2.0: - version "10.4.3" - resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119" - integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ== - -minimatch@^8.0.2: - version "8.0.4" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-8.0.4.tgz#847c1b25c014d4e9a7f68aaf63dedd668a626229" - integrity sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA== - dependencies: - brace-expansion "^2.0.1" - -minipass@^4.2.4: - version "4.2.8" - resolved "https://registry.yarnpkg.com/minipass/-/minipass-4.2.8.tgz#f0010f64393ecfc1d1ccb5f582bcaf45f48e1a3a" - integrity sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ== - -"minipass@^5.0.0 || ^6.0.2 || ^7.0.0": - version "7.1.2" - resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.1.2.tgz#93a9626ce5e5e66bd4db86849e7515e92340a707" - integrity sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw== - -ms@^2.1.3: - version "2.1.3" - resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" - integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== - -once@^1.3.1, once@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" - integrity sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w== - dependencies: - wrappy "1" - -path-scurry@^1.6.1: - version "1.11.1" - resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-1.11.1.tgz#7960a668888594a0720b12a911d1a742ab9f11d2" - integrity sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA== - dependencies: - lru-cache "^10.2.0" - minipass "^5.0.0 || ^6.0.2 || ^7.0.0" - -pend@~1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50" - integrity sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg== - -progress@2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" - integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== - -pump@^3.0.0: - version "3.0.2" - resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.2.tgz#836f3edd6bc2ee599256c924ffe0d88573ddcbf8" - integrity sha512-tUPXtzlGM8FE3P0ZL6DVs/3P58k9nk8/jZeQCurTJylQA8qFYzHFfhBJkuqyE0FifOsQ0uKWekiZ5g8wtr28cw== - dependencies: - end-of-stream "^1.1.0" - once "^1.3.1" - -rimraf@4.4.1: - version "4.4.1" - resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-4.4.1.tgz#bd33364f67021c5b79e93d7f4fa0568c7c21b755" - integrity sha512-Gk8NlF062+T9CqNGn6h4tls3k6T1+/nXdOcSZVikNVtlRdYpA7wRJJMoXmuvOnLW844rPjdQ7JgXCYM6PPC/og== - dependencies: - glob "^9.2.0" - -supports-color@^7.1.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" - integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== - dependencies: - has-flag "^4.0.0" - -undici-types@~6.19.2: - version "6.19.8" - resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02" - integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== - -undici@^5.13.0: - version "5.28.4" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" - integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== - dependencies: - "@fastify/busboy" "^2.0.0" - -wrappy@1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" - integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== - -yauzl@^2.10.0: - version "2.10.0" - resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9" - integrity sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g== - dependencies: - buffer-crc32 "~0.2.3" - fd-slicer "~1.1.0" From 6b405c7754ba5f67fa7620fa89e6e6d40c18fbfc Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Tue, 1 Oct 2024 10:50:00 -0400 Subject: [PATCH 12/23] allow span kind to be server for azure functions --- packages/dd-trace/src/plugins/util/web.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dd-trace/src/plugins/util/web.js b/packages/dd-trace/src/plugins/util/web.js index 98e525baad4..821bf078445 100644 --- a/packages/dd-trace/src/plugins/util/web.js +++ b/packages/dd-trace/src/plugins/util/web.js @@ -432,7 +432,7 @@ function addRequestTags (context) { span.addTags({ [HTTP_URL]: web.obfuscateQs(config, url), [HTTP_METHOD]: req.method, - [SPAN_KIND]: tags[SPAN_TYPE] === 'serverless' ? null : SERVER, + [SPAN_KIND]: SERVER, [SPAN_TYPE]: tags[SPAN_TYPE] === 'serverless' ? 'serverless' : WEB, [HTTP_USERAGENT]: req.headers['user-agent'] }) From 201d9c0f142984eb92ff92669e823ebca49708b3 Mon Sep 17 00:00:00 2001 From: Duncan Harvey <35278470+duncanpharvey@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:46:50 -0400 Subject: [PATCH 13/23] Update index.d.ts Co-authored-by: Roch Devost --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index cf93d1ed3b0..fb1dbbb4155 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1232,7 +1232,7 @@ declare namespace tracer { /** * This plugin automatically instruments the - * azure.functions module. + * @azure/functions module. */ interface azure_functions extends Instrumentation {} From 766e740433310a983fae283ab91540832f4a8a9c Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Mon, 7 Oct 2024 10:28:23 -0400 Subject: [PATCH 14/23] add serverless util --- ext/types.d.ts | 1 + ext/types.js | 1 + .../src/index.js | 9 +- .../test/integration-test/fixtures/yarn.lock | 269 ++++++++++++++++++ .../dd-trace/src/plugins/util/serverless.js | 127 +++++++++ 5 files changed, 402 insertions(+), 5 deletions(-) create mode 100644 packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock create mode 100644 packages/dd-trace/src/plugins/util/serverless.js diff --git a/ext/types.d.ts b/ext/types.d.ts index 703d88f794b..549f4d58ec1 100644 --- a/ext/types.d.ts +++ b/ext/types.d.ts @@ -1,5 +1,6 @@ declare const types: { HTTP: 'http' + SERVERLESS: 'serverless' WEB: 'web' } diff --git a/ext/types.js b/ext/types.js index d8863f04bb2..884b6a495e5 100644 --- a/ext/types.js +++ b/ext/types.js @@ -2,5 +2,6 @@ module.exports = { HTTP: 'http', + SERVERLESS: 'serverless', WEB: 'web' } diff --git a/packages/datadog-plugin-azure-functions/src/index.js b/packages/datadog-plugin-azure-functions/src/index.js index c74f9c382d4..b787db5c2cf 100644 --- a/packages/datadog-plugin-azure-functions/src/index.js +++ b/packages/datadog-plugin-azure-functions/src/index.js @@ -2,6 +2,7 @@ const TracingPlugin = require('../../dd-trace/src/plugins/tracing') const { storage } = require('../../datadog-core') +const serverless = require('../../dd-trace/src/plugins/util/serverless') const web = require('../../dd-trace/src/plugins/util/web') const triggerMap = { @@ -56,14 +57,12 @@ class AzureFunctionsPlugin extends TracingPlugin { } const context = web.patch(req) - context.span = ctx.currentStore.span context.config = this.config context.paths = [path] + context.res = result + context.span = ctx.currentStore.span - // Use status for status code if available. Otherwise if no status is provided assume an internal server error - context.res = { statusCode: result.hasOwnProperty('status') ? result.status : 500 } - - web.finishSpan(context) + serverless.finishSpan(context) } configure (config) { diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock new file mode 100644 index 00000000000..98c420c8953 --- /dev/null +++ b/packages/datadog-plugin-azure-functions/test/integration-test/fixtures/yarn.lock @@ -0,0 +1,269 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@azure/functions@^4.0.0": + version "4.5.1" + resolved "https://registry.yarnpkg.com/@azure/functions/-/functions-4.5.1.tgz#70d1a99d335af87579a55d3c149ef1ae77da0a66" + integrity sha512-ikiw1IrM2W9NlQM3XazcX+4Sq3XAjZi4eeG22B5InKC2x5i7MatGF2S/Gn1ACZ+fEInwu+Ru9J8DlnBv1/hIvg== + dependencies: + cookie "^0.6.0" + long "^4.0.0" + undici "^5.13.0" + +"@fastify/busboy@^2.0.0": + version "2.1.1" + resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" + integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== + +"@types/node@*": + version "22.7.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.7.4.tgz#e35d6f48dca3255ce44256ddc05dee1c23353fcc" + integrity sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg== + dependencies: + undici-types "~6.19.2" + +"@types/yauzl@^2.9.1": + version "2.10.3" + resolved "https://registry.yarnpkg.com/@types/yauzl/-/yauzl-2.10.3.tgz#e9b2808b4f109504a03cda958259876f61017999" + integrity sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q== + dependencies: + "@types/node" "*" + +agent-base@6: + version "6.0.2" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" + integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ== + dependencies: + debug "4" + +ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== + dependencies: + color-convert "^2.0.1" + +azure-functions-core-tools@^4.x: + version "4.0.6280" + resolved "https://registry.yarnpkg.com/azure-functions-core-tools/-/azure-functions-core-tools-4.0.6280.tgz#59b4d9402846760aef3ad292355c3eeb4e5f21ad" + integrity sha512-DVSgYNnT4POLbj/YV3FKtNdo9KT/M5Dl//slWEmVwZo1y4aJEsUApn6DtkZswut76I3S9eKGC5IaC84j5OGNaA== + dependencies: + chalk "3.0.0" + extract-zip "^2.0.1" + https-proxy-agent "5.0.0" + progress "2.0.3" + rimraf "4.4.1" + +balanced-match@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== + +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + +buffer-crc32@~0.2.3: + version "0.2.13" + resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242" + integrity sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ== + +chalk@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4" + integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + +cookie@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051" + integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw== + +debug@4, debug@^4.1.1: + version "4.3.7" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52" + integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ== + dependencies: + ms "^2.1.3" + +end-of-stream@^1.1.0: + version "1.4.4" + resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0" + integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q== + dependencies: + once "^1.4.0" + +extract-zip@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/extract-zip/-/extract-zip-2.0.1.tgz#663dca56fe46df890d5f131ef4a06d22bb8ba13a" + integrity sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg== + dependencies: + debug "^4.1.1" + get-stream "^5.1.0" + yauzl "^2.10.0" + optionalDependencies: + "@types/yauzl" "^2.9.1" + +fd-slicer@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.1.0.tgz#25c7c89cb1f9077f8891bbe61d8f390eae256f1e" + integrity sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g== + dependencies: + pend "~1.2.0" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== + +get-stream@^5.1.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.2.0.tgz#4966a1795ee5ace65e706c4b7beb71257d6e22d3" + integrity sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA== + dependencies: + pump "^3.0.0" + +glob@^9.2.0: + version "9.3.5" + resolved "https://registry.yarnpkg.com/glob/-/glob-9.3.5.tgz#ca2ed8ca452781a3009685607fdf025a899dfe21" + integrity sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q== + dependencies: + fs.realpath "^1.0.0" + minimatch "^8.0.2" + minipass "^4.2.4" + path-scurry "^1.6.1" + +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + +https-proxy-agent@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2" + integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA== + dependencies: + agent-base "6" + debug "4" + +long@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" + integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== + +lru-cache@^10.2.0: + version "10.4.3" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119" + integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ== + +minimatch@^8.0.2: + version "8.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-8.0.4.tgz#847c1b25c014d4e9a7f68aaf63dedd668a626229" + integrity sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA== + dependencies: + brace-expansion "^2.0.1" + +minipass@^4.2.4: + version "4.2.8" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-4.2.8.tgz#f0010f64393ecfc1d1ccb5f582bcaf45f48e1a3a" + integrity sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ== + +"minipass@^5.0.0 || ^6.0.2 || ^7.0.0": + version "7.1.2" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.1.2.tgz#93a9626ce5e5e66bd4db86849e7515e92340a707" + integrity sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw== + +ms@^2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + +once@^1.3.1, once@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w== + dependencies: + wrappy "1" + +path-scurry@^1.6.1: + version "1.11.1" + resolved "https://registry.yarnpkg.com/path-scurry/-/path-scurry-1.11.1.tgz#7960a668888594a0720b12a911d1a742ab9f11d2" + integrity sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA== + dependencies: + lru-cache "^10.2.0" + minipass "^5.0.0 || ^6.0.2 || ^7.0.0" + +pend@~1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50" + integrity sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg== + +progress@2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" + integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== + +pump@^3.0.0: + version "3.0.2" + resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.2.tgz#836f3edd6bc2ee599256c924ffe0d88573ddcbf8" + integrity sha512-tUPXtzlGM8FE3P0ZL6DVs/3P58k9nk8/jZeQCurTJylQA8qFYzHFfhBJkuqyE0FifOsQ0uKWekiZ5g8wtr28cw== + dependencies: + end-of-stream "^1.1.0" + once "^1.3.1" + +rimraf@4.4.1: + version "4.4.1" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-4.4.1.tgz#bd33364f67021c5b79e93d7f4fa0568c7c21b755" + integrity sha512-Gk8NlF062+T9CqNGn6h4tls3k6T1+/nXdOcSZVikNVtlRdYpA7wRJJMoXmuvOnLW844rPjdQ7JgXCYM6PPC/og== + dependencies: + glob "^9.2.0" + +supports-color@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== + dependencies: + has-flag "^4.0.0" + +undici-types@~6.19.2: + version "6.19.8" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02" + integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== + +undici@^5.13.0: + version "5.28.4" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" + integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== + dependencies: + "@fastify/busboy" "^2.0.0" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== + +yauzl@^2.10.0: + version "2.10.0" + resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9" + integrity sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g== + dependencies: + buffer-crc32 "~0.2.3" + fd-slicer "~1.1.0" diff --git a/packages/dd-trace/src/plugins/util/serverless.js b/packages/dd-trace/src/plugins/util/serverless.js new file mode 100644 index 00000000000..a787a092c26 --- /dev/null +++ b/packages/dd-trace/src/plugins/util/serverless.js @@ -0,0 +1,127 @@ +const tags = require('../../../../../ext/tags') +const types = require('../../../../../ext/types') +const kinds = require('../../../../../ext/kinds') +const web = require('./web') + +const SERVERLESS = types.SERVERLESS +const SERVER = kinds.SERVER +const RESOURCE_NAME = tags.RESOURCE_NAME +const SPAN_TYPE = tags.SPAN_TYPE +const SPAN_KIND = tags.SPAN_KIND +const HTTP_METHOD = tags.HTTP_METHOD +const HTTP_STATUS_CODE = tags.HTTP_STATUS_CODE +const HTTP_ROUTE = tags.HTTP_ROUTE +const HTTP_REQUEST_HEADERS = tags.HTTP_REQUEST_HEADERS +const HTTP_RESPONSE_HEADERS = tags.HTTP_RESPONSE_HEADERS +const HTTP_URL = tags.HTTP_URL +const HTTP_USERAGENT = tags.HTTP_USERAGENT +const HTTP_CLIENT_IP = tags.HTTP_CLIENT_IP + +const HTTP2_HEADER_AUTHORITY = ':authority' +const HTTP2_HEADER_SCHEME = ':scheme' +const HTTP2_HEADER_PATH = ':path' + +const serverless = { + finishSpan (context) { + const { req, res } = context + + if (context.finished && !req.stream) return + + addRequestTags(context) + addResponseTags(context) + + context.config.hooks.request(context.span, req, res) + addResourceTag(context) + + context.span.finish() + context.finished = true + } +} + +function addRequestTags (context) { + const { req, span, config } = context + const url = extractURL(req) + + span.addTags({ + [HTTP_URL]: web.obfuscateQs(config, url), + [HTTP_METHOD]: req.method, + [SPAN_KIND]: SERVER, + [SPAN_TYPE]: SERVERLESS, + [HTTP_USERAGENT]: req.headers['user-agent'] + }) + + // if client ip has already been set by appsec, no need to run it again + if (config.clientIpEnabled && !span.context()._tags.hasOwnProperty(HTTP_CLIENT_IP)) { + const clientIp = web.extractIp(config, req) + + if (clientIp) { + span.setTag(HTTP_CLIENT_IP, clientIp) + } + } + + addHeaders(context) +} + +function addResponseTags (context) { + const { req, res, paths, span } = context + + if (paths.length > 0) { + span.setTag(HTTP_ROUTE, paths.join('')) + } + + span.addTags({ + [HTTP_STATUS_CODE]: res.status + }) + + web.addStatusError(req, res.status) +} + +function extractURL (req) { + const headers = req.headers + + if (req.stream) { + return `${headers[HTTP2_HEADER_SCHEME]}://${headers[HTTP2_HEADER_AUTHORITY]}${headers[HTTP2_HEADER_PATH]}` + } else { + const protocol = getProtocol(req) + return `${protocol}://${req.headers.host}${req.originalUrl || req.url}` + } +} + +function getProtocol (req) { + if (req.socket && req.socket.encrypted) return 'https' + if (req.connection && req.connection.encrypted) return 'https' + + return 'http' +} + +function addHeaders (context) { + const { req, res, config, span } = context + + config.headers.forEach(([key, tag]) => { + const reqHeader = req.headers[key] + const resHeader = res.getHeader(key) + + if (reqHeader) { + span.setTag(tag || `${HTTP_REQUEST_HEADERS}.${key}`, reqHeader) + } + + if (resHeader) { + span.setTag(tag || `${HTTP_RESPONSE_HEADERS}.${key}`, resHeader) + } + }) +} + +function addResourceTag (context) { + const { req, span } = context + const tags = span.context()._tags + + if (tags['resource.name']) return + + const resource = [req.method, tags[HTTP_ROUTE]] + .filter(val => val) + .join(' ') + + span.setTag(RESOURCE_NAME, resource) +} + +module.exports = serverless From bcd230e7ed58786c70df4d08d1f6700ed7f2eceb Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Mon, 7 Oct 2024 10:42:52 -0400 Subject: [PATCH 15/23] use built in url parser --- packages/datadog-plugin-azure-functions/src/index.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/datadog-plugin-azure-functions/src/index.js b/packages/datadog-plugin-azure-functions/src/index.js index b787db5c2cf..926d8352c16 100644 --- a/packages/datadog-plugin-azure-functions/src/index.js +++ b/packages/datadog-plugin-azure-functions/src/index.js @@ -49,7 +49,7 @@ class AzureFunctionsPlugin extends TracingPlugin { asyncEnd (ctx) { const { httpRequest, result = {} } = ctx - const path = extractPath(httpRequest.url) + const path = (new URL(httpRequest.url)).pathname const req = { method: httpRequest.method, headers: Object.fromEntries(httpRequest.headers.entries()), @@ -70,12 +70,6 @@ class AzureFunctionsPlugin extends TracingPlugin { } } -function extractPath (url) { - const regex = /https?:\/\/[^/]+(\/.*$)/ - const match = url.match(regex) - return match ? match[1] : '' -} - function mapTriggerTag (methodName) { return triggerMap[methodName] || 'Unknown' } From 119da9f038b2917039f1a575d4bd8e907c209b14 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Mon, 7 Oct 2024 10:54:23 -0400 Subject: [PATCH 16/23] remove serverless logic from web util --- packages/dd-trace/src/plugins/util/web.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/dd-trace/src/plugins/util/web.js b/packages/dd-trace/src/plugins/util/web.js index 821bf078445..c9cdf1990aa 100644 --- a/packages/dd-trace/src/plugins/util/web.js +++ b/packages/dd-trace/src/plugins/util/web.js @@ -427,13 +427,11 @@ function addRequestTags (context) { const { req, span, config } = context const url = extractURL(req) - const tags = span.context()._tags - span.addTags({ [HTTP_URL]: web.obfuscateQs(config, url), [HTTP_METHOD]: req.method, [SPAN_KIND]: SERVER, - [SPAN_TYPE]: tags[SPAN_TYPE] === 'serverless' ? 'serverless' : WEB, + [SPAN_TYPE]: WEB, [HTTP_USERAGENT]: req.headers['user-agent'] }) From 8a81f3ce5e4fd6c6f6f7a99084284d03b77f7c71 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Mon, 7 Oct 2024 15:47:41 -0400 Subject: [PATCH 17/23] remove wait-on dependency --- LICENSE-3rdparty.csv | 1 - package.json | 3 +- .../test/integration-test/client.spec.js | 14 +--- yarn.lock | 77 ------------------- 4 files changed, 5 insertions(+), 90 deletions(-) diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 37e1d700639..043116f9480 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -66,7 +66,6 @@ dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen dev,sinon-chai,WTFPL and BSD-2-Clause,Copyright 2004 Sam Hocevar 2012–2017 Domenic Denicola dev,tap,ISC,Copyright 2011-2022 Isaac Z. Schlueter and Contributors dev,tiktoken,MIT,Copyright (c) 2022 OpenAI, Shantanu Jain -dev,wait-on,MIT,Copyright (c) 2015 Jeff Barczewski file,aws-lambda-nodejs-runtime-interface-client,Apache 2.0,Copyright 2019 Amazon.com Inc. or its affiliates. All Rights Reserved. file,profile.proto,Apache license 2.0,Copyright 2016 Google Inc. file,is-git-url,MIT,Copyright (c) 2017 Jon Schlinkert. diff --git a/package.json b/package.json index 330cee80617..2e8d9187362 100644 --- a/package.json +++ b/package.json @@ -144,7 +144,6 @@ "sinon": "^15.2.0", "sinon-chai": "^3.7.0", "tap": "^16.3.7", - "tiktoken": "^1.0.15", - "wait-on": "^8.0.1" + "tiktoken": "^1.0.15" } } diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js index 7c441e72060..fbe5951abcb 100644 --- a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js @@ -9,7 +9,6 @@ const { const { spawn } = require('child_process') const { assert } = require('chai') const findProcess = require('find-process') -const waitOn = require('wait-on') describe('esm', () => { let agent @@ -74,15 +73,6 @@ async function spawnPluginIntegrationTestProc (cwd, command, args, agentPort, st function spawnProc (command, args, options = {}, stdioHandler, stderrHandler) { const proc = spawn(command, args, { ...options, stdio: 'pipe' }) return new Promise((resolve, reject) => { - waitOn({ - resources: ['http-get://127.0.0.1:7071'], - timeout: 5000 - }).then(() => { - resolve(proc) - }).catch(err => { - reject(new Error(`Error while waiting for process to start: ${err.message}`)) - }) - proc .on('error', reject) .on('exit', code => { @@ -98,6 +88,10 @@ function spawnProc (command, args, options = {}, stdioHandler, stderrHandler) { } // eslint-disable-next-line no-console if (!options.silent) console.log(data.toString()) + + if (data.toString().includes('http://localhost:7071/api/httptest')) { + resolve() + } }) proc.stderr.on('data', data => { diff --git a/yarn.lock b/yarn.lock index 1b9166d65d9..e8dc620ab5b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -444,18 +444,6 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== -"@hapi/hoek@^9.0.0", "@hapi/hoek@^9.3.0": - version "9.3.0" - resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb" - integrity sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ== - -"@hapi/topo@^5.1.0": - version "5.1.0" - resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.1.0.tgz#dc448e332c6c6e37a4dc02fd84ba8d44b9afb012" - integrity sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg== - dependencies: - "@hapi/hoek" "^9.0.0" - "@humanwhocodes/config-array@^0.11.14": version "0.11.14" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b" @@ -647,23 +635,6 @@ resolved "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz" integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw== -"@sideway/address@^4.1.5": - version "4.1.5" - resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.5.tgz#4bc149a0076623ced99ca8208ba780d65a99b9d5" - integrity sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q== - dependencies: - "@hapi/hoek" "^9.0.0" - -"@sideway/formula@^3.0.1": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@sideway/formula/-/formula-3.0.1.tgz#80fcbcbaf7ce031e0ef2dd29b1bfc7c3f583611f" - integrity sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg== - -"@sideway/pinpoint@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@sideway/pinpoint/-/pinpoint-2.0.0.tgz#cff8ffadc372ad29fd3f78277aeb29e632cc70df" - integrity sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ== - "@sinonjs/commons@^2.0.0": version "2.0.0" resolved "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz" @@ -1022,15 +993,6 @@ axios@^1.7.4: form-data "^4.0.0" proxy-from-env "^1.1.0" -axios@^1.7.7: - version "1.7.7" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f" - integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q== - dependencies: - follow-redirects "^1.15.6" - form-data "^4.0.0" - proxy-from-env "^1.1.0" - balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz" @@ -2999,17 +2961,6 @@ jmespath@0.16.0: resolved "https://registry.npmjs.org/jmespath/-/jmespath-0.16.0.tgz" integrity "sha1-sVsKhd/U2TDUPmntYFlDyAJ4UHY= sha512-9FzQjJ7MATs1tSpnco1K6ayiYE3figslrXA72G2HQ/n76RzvYlofyi5QM+iX4YRs/pu3yzxlVQSST23+dMDknw==" -joi@^17.13.3: - version "17.13.3" - resolved "https://registry.yarnpkg.com/joi/-/joi-17.13.3.tgz#0f5cc1169c999b30d344366d384b12d92558bcec" - integrity sha512-otDA4ldcIx+ZXsKHWmp0YizCweVRZG96J10b0FevjfuncLO1oX59THoAmHkNubYJ+9gWsYsp5k8v4ib6oDv1fA== - dependencies: - "@hapi/hoek" "^9.3.0" - "@hapi/topo" "^5.1.0" - "@sideway/address" "^4.1.5" - "@sideway/formula" "^3.0.1" - "@sideway/pinpoint" "^2.0.0" - "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz" @@ -3301,11 +3252,6 @@ minimist@^1.2.0, minimist@^1.2.6: resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz" integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g== -minimist@^1.2.8: - version "1.2.8" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" - integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== - minipass@^3.1.5, minipass@^3.1.6, minipass@^3.3.4: version "3.3.6" resolved "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz" @@ -4074,13 +4020,6 @@ run-parallel@^1.1.9: dependencies: queue-microtask "^1.2.2" -rxjs@^7.8.1: - version "7.8.1" - resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.1.tgz#6f6f3d99ea8044291efd92e7c7fcf562c4057543" - integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg== - dependencies: - tslib "^2.1.0" - safe-array-concat@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/safe-array-concat/-/safe-array-concat-1.1.2.tgz#81d77ee0c4e8b863635227c721278dd524c20edb" @@ -4586,11 +4525,6 @@ tsconfig-paths@^3.15.0: minimist "^1.2.6" strip-bom "^3.0.0" -tslib@^2.1.0: - version "2.7.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01" - integrity sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA== - type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz" @@ -4778,17 +4712,6 @@ vary@~1.1.2: resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz" integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg== -wait-on@^8.0.1: - version "8.0.1" - resolved "https://registry.yarnpkg.com/wait-on/-/wait-on-8.0.1.tgz#13c8ec77115517f8fbc2d670521a444201f03f53" - integrity sha512-1wWQOyR2LVVtaqrcIL2+OM+x7bkpmzVROa0Nf6FryXkS+er5Sa1kzFGjzZRqLnHa3n1rACFLeTwUqE1ETL9Mig== - dependencies: - axios "^1.7.7" - joi "^17.13.3" - lodash "^4.17.21" - minimist "^1.2.8" - rxjs "^7.8.1" - which-boxed-primitive@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz" From 3c004c535ea1541b1ca5740010e4e1c5bafc0ae2 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Tue, 8 Oct 2024 16:57:46 -0400 Subject: [PATCH 18/23] remove find-process dependency --- LICENSE-3rdparty.csv | 1 - package.json | 1 - .../test/integration-test/client.spec.js | 12 +++--------- yarn.lock | 14 -------------- 4 files changed, 3 insertions(+), 25 deletions(-) diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 043116f9480..45f88f66cb4 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -49,7 +49,6 @@ dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck dev,eslint-plugin-n,MIT,Copyright 2015 Toru Nagashima dev,eslint-plugin-promise,ISC,jden and other contributors dev,express,MIT,Copyright 2009-2014 TJ Holowaychuk 2013-2014 Roman Shtylman 2014-2015 Douglas Christopher Wilson -dev,find-process,MIT,Copyright (c) 2016 Zoujie dev,get-port,MIT,Copyright Sindre Sorhus dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors dev,graphql,MIT,Copyright 2015 Facebook Inc. diff --git a/package.json b/package.json index 2e8d9187362..49958f4861c 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,6 @@ "eslint-plugin-n": "^16.6.2", "eslint-plugin-promise": "^6.4.0", "express": "^4.18.2", - "find-process": "^1.4.7", "get-port": "^3.2.0", "glob": "^7.1.6", "graphql": "0.13.2", diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js index fbe5951abcb..dd43d3a7609 100644 --- a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js @@ -8,11 +8,9 @@ const { } = require('../../../../integration-tests/helpers') const { spawn } = require('child_process') const { assert } = require('chai') -const findProcess = require('find-process') describe('esm', () => { let agent - let proc let sandbox withVersions('azure-functions', '@azure/functions', version => { @@ -32,19 +30,15 @@ describe('esm', () => { }) afterEach(async () => { - const azureFuncProc = await findProcess('name', 'func', true) - const azureFuncProcPid = azureFuncProc[0]?.pid ?? null - azureFuncProcPid !== null && process.kill(azureFuncProcPid, 'SIGKILL') - - proc && proc.kill() await agent.stop() + process.kill(0, 'SIGINT') }) it('is instrumented', async () => { const envArgs = { PATH: `${sandbox.folder}/node_modules/.bin:${process.env.PATH}` } - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'func', ['start'], agent.port, undefined, envArgs) + await spawnPluginIntegrationTestProc(sandbox.folder, 'func', ['start'], agent.port, undefined, envArgs) return curlAndAssertMessage(agent, 'http://127.0.0.1:7071/api/httptest', ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) @@ -90,7 +84,7 @@ function spawnProc (command, args, options = {}, stdioHandler, stderrHandler) { if (!options.silent) console.log(data.toString()) if (data.toString().includes('http://localhost:7071/api/httptest')) { - resolve() + resolve(proc) } }) diff --git a/yarn.lock b/yarn.lock index e8dc620ab5b..ca8b325ec9f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1370,11 +1370,6 @@ combined-stream@^1.0.6, combined-stream@^1.0.8: dependencies: delayed-stream "~1.0.0" -commander@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae" - integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg== - commander@^9.1.0: version "9.5.0" resolved "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz" @@ -2141,15 +2136,6 @@ find-cache-dir@^3.2.0: make-dir "^3.0.2" pkg-dir "^4.1.0" -find-process@^1.4.7: - version "1.4.7" - resolved "https://registry.yarnpkg.com/find-process/-/find-process-1.4.7.tgz#8c76962259216c381ef1099371465b5b439ea121" - integrity sha512-/U4CYp1214Xrp3u3Fqr9yNynUrr5Le4y0SsJh2lMDDSbpwYSz3M2SMWQC+wqcx79cN8PQtHQIL8KnuY9M66fdg== - dependencies: - chalk "^4.0.0" - commander "^5.1.0" - debug "^4.1.1" - find-up@5.0.0, find-up@^5.0.0: version "5.0.0" resolved "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz" From a08812081720f3bf6086706e8c47b5fabc82ba61 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Tue, 8 Oct 2024 17:01:37 -0400 Subject: [PATCH 19/23] Revert "remove find-process dependency" This reverts commit 3c004c535ea1541b1ca5740010e4e1c5bafc0ae2. --- LICENSE-3rdparty.csv | 1 + package.json | 1 + .../test/integration-test/client.spec.js | 12 +++++++++--- yarn.lock | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 45f88f66cb4..043116f9480 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -49,6 +49,7 @@ dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck dev,eslint-plugin-n,MIT,Copyright 2015 Toru Nagashima dev,eslint-plugin-promise,ISC,jden and other contributors dev,express,MIT,Copyright 2009-2014 TJ Holowaychuk 2013-2014 Roman Shtylman 2014-2015 Douglas Christopher Wilson +dev,find-process,MIT,Copyright (c) 2016 Zoujie dev,get-port,MIT,Copyright Sindre Sorhus dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors dev,graphql,MIT,Copyright 2015 Facebook Inc. diff --git a/package.json b/package.json index 49958f4861c..2e8d9187362 100644 --- a/package.json +++ b/package.json @@ -128,6 +128,7 @@ "eslint-plugin-n": "^16.6.2", "eslint-plugin-promise": "^6.4.0", "express": "^4.18.2", + "find-process": "^1.4.7", "get-port": "^3.2.0", "glob": "^7.1.6", "graphql": "0.13.2", diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js index dd43d3a7609..fbe5951abcb 100644 --- a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js @@ -8,9 +8,11 @@ const { } = require('../../../../integration-tests/helpers') const { spawn } = require('child_process') const { assert } = require('chai') +const findProcess = require('find-process') describe('esm', () => { let agent + let proc let sandbox withVersions('azure-functions', '@azure/functions', version => { @@ -30,15 +32,19 @@ describe('esm', () => { }) afterEach(async () => { + const azureFuncProc = await findProcess('name', 'func', true) + const azureFuncProcPid = azureFuncProc[0]?.pid ?? null + azureFuncProcPid !== null && process.kill(azureFuncProcPid, 'SIGKILL') + + proc && proc.kill() await agent.stop() - process.kill(0, 'SIGINT') }) it('is instrumented', async () => { const envArgs = { PATH: `${sandbox.folder}/node_modules/.bin:${process.env.PATH}` } - await spawnPluginIntegrationTestProc(sandbox.folder, 'func', ['start'], agent.port, undefined, envArgs) + proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'func', ['start'], agent.port, undefined, envArgs) return curlAndAssertMessage(agent, 'http://127.0.0.1:7071/api/httptest', ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) @@ -84,7 +90,7 @@ function spawnProc (command, args, options = {}, stdioHandler, stderrHandler) { if (!options.silent) console.log(data.toString()) if (data.toString().includes('http://localhost:7071/api/httptest')) { - resolve(proc) + resolve() } }) diff --git a/yarn.lock b/yarn.lock index ca8b325ec9f..e8dc620ab5b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1370,6 +1370,11 @@ combined-stream@^1.0.6, combined-stream@^1.0.8: dependencies: delayed-stream "~1.0.0" +commander@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae" + integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg== + commander@^9.1.0: version "9.5.0" resolved "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz" @@ -2136,6 +2141,15 @@ find-cache-dir@^3.2.0: make-dir "^3.0.2" pkg-dir "^4.1.0" +find-process@^1.4.7: + version "1.4.7" + resolved "https://registry.yarnpkg.com/find-process/-/find-process-1.4.7.tgz#8c76962259216c381ef1099371465b5b439ea121" + integrity sha512-/U4CYp1214Xrp3u3Fqr9yNynUrr5Le4y0SsJh2lMDDSbpwYSz3M2SMWQC+wqcx79cN8PQtHQIL8KnuY9M66fdg== + dependencies: + chalk "^4.0.0" + commander "^5.1.0" + debug "^4.1.1" + find-up@5.0.0, find-up@^5.0.0: version "5.0.0" resolved "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz" From 4a6c8a63008b597379ee0f98bddd0a3c81d0b0f7 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Wed, 9 Oct 2024 10:23:28 -0400 Subject: [PATCH 20/23] call func start directly and remove find-process dependency --- LICENSE-3rdparty.csv | 1 - package.json | 1 - .../test/integration-test/client.spec.js | 11 +++-------- yarn.lock | 14 -------------- 4 files changed, 3 insertions(+), 24 deletions(-) diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 043116f9480..45f88f66cb4 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -49,7 +49,6 @@ dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck dev,eslint-plugin-n,MIT,Copyright 2015 Toru Nagashima dev,eslint-plugin-promise,ISC,jden and other contributors dev,express,MIT,Copyright 2009-2014 TJ Holowaychuk 2013-2014 Roman Shtylman 2014-2015 Douglas Christopher Wilson -dev,find-process,MIT,Copyright (c) 2016 Zoujie dev,get-port,MIT,Copyright Sindre Sorhus dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors dev,graphql,MIT,Copyright 2015 Facebook Inc. diff --git a/package.json b/package.json index 2e8d9187362..49958f4861c 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,6 @@ "eslint-plugin-n": "^16.6.2", "eslint-plugin-promise": "^6.4.0", "express": "^4.18.2", - "find-process": "^1.4.7", "get-port": "^3.2.0", "glob": "^7.1.6", "graphql": "0.13.2", diff --git a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js index fbe5951abcb..8d5a0d43fdb 100644 --- a/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-functions/test/integration-test/client.spec.js @@ -8,7 +8,6 @@ const { } = require('../../../../integration-tests/helpers') const { spawn } = require('child_process') const { assert } = require('chai') -const findProcess = require('find-process') describe('esm', () => { let agent @@ -32,17 +31,13 @@ describe('esm', () => { }) afterEach(async () => { - const azureFuncProc = await findProcess('name', 'func', true) - const azureFuncProcPid = azureFuncProc[0]?.pid ?? null - azureFuncProcPid !== null && process.kill(azureFuncProcPid, 'SIGKILL') - - proc && proc.kill() + proc && proc.kill('SIGINT') await agent.stop() }) it('is instrumented', async () => { const envArgs = { - PATH: `${sandbox.folder}/node_modules/.bin:${process.env.PATH}` + PATH: `${sandbox.folder}/node_modules/azure-functions-core-tools/bin:${process.env.PATH}` } proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'func', ['start'], agent.port, undefined, envArgs) @@ -90,7 +85,7 @@ function spawnProc (command, args, options = {}, stdioHandler, stderrHandler) { if (!options.silent) console.log(data.toString()) if (data.toString().includes('http://localhost:7071/api/httptest')) { - resolve() + resolve(proc) } }) diff --git a/yarn.lock b/yarn.lock index e8dc620ab5b..ca8b325ec9f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1370,11 +1370,6 @@ combined-stream@^1.0.6, combined-stream@^1.0.8: dependencies: delayed-stream "~1.0.0" -commander@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae" - integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg== - commander@^9.1.0: version "9.5.0" resolved "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz" @@ -2141,15 +2136,6 @@ find-cache-dir@^3.2.0: make-dir "^3.0.2" pkg-dir "^4.1.0" -find-process@^1.4.7: - version "1.4.7" - resolved "https://registry.yarnpkg.com/find-process/-/find-process-1.4.7.tgz#8c76962259216c381ef1099371465b5b439ea121" - integrity sha512-/U4CYp1214Xrp3u3Fqr9yNynUrr5Le4y0SsJh2lMDDSbpwYSz3M2SMWQC+wqcx79cN8PQtHQIL8KnuY9M66fdg== - dependencies: - chalk "^4.0.0" - commander "^5.1.0" - debug "^4.1.1" - find-up@5.0.0, find-up@^5.0.0: version "5.0.0" resolved "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz" From 91a2dd9752663cc57c61760ccf7b9737c60e00fb Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Wed, 9 Oct 2024 16:10:40 -0400 Subject: [PATCH 21/23] simplify serverless util --- .../src/index.js | 2 +- .../dd-trace/src/plugins/util/serverless.js | 124 +----------------- 2 files changed, 3 insertions(+), 123 deletions(-) diff --git a/packages/datadog-plugin-azure-functions/src/index.js b/packages/datadog-plugin-azure-functions/src/index.js index 926d8352c16..2c85403906c 100644 --- a/packages/datadog-plugin-azure-functions/src/index.js +++ b/packages/datadog-plugin-azure-functions/src/index.js @@ -59,7 +59,7 @@ class AzureFunctionsPlugin extends TracingPlugin { const context = web.patch(req) context.config = this.config context.paths = [path] - context.res = result + context.res = { statusCode: result.status } context.span = ctx.currentStore.span serverless.finishSpan(context) diff --git a/packages/dd-trace/src/plugins/util/serverless.js b/packages/dd-trace/src/plugins/util/serverless.js index a787a092c26..3e969ffdfad 100644 --- a/packages/dd-trace/src/plugins/util/serverless.js +++ b/packages/dd-trace/src/plugins/util/serverless.js @@ -1,127 +1,7 @@ -const tags = require('../../../../../ext/tags') const types = require('../../../../../ext/types') -const kinds = require('../../../../../ext/kinds') const web = require('./web') -const SERVERLESS = types.SERVERLESS -const SERVER = kinds.SERVER -const RESOURCE_NAME = tags.RESOURCE_NAME -const SPAN_TYPE = tags.SPAN_TYPE -const SPAN_KIND = tags.SPAN_KIND -const HTTP_METHOD = tags.HTTP_METHOD -const HTTP_STATUS_CODE = tags.HTTP_STATUS_CODE -const HTTP_ROUTE = tags.HTTP_ROUTE -const HTTP_REQUEST_HEADERS = tags.HTTP_REQUEST_HEADERS -const HTTP_RESPONSE_HEADERS = tags.HTTP_RESPONSE_HEADERS -const HTTP_URL = tags.HTTP_URL -const HTTP_USERAGENT = tags.HTTP_USERAGENT -const HTTP_CLIENT_IP = tags.HTTP_CLIENT_IP - -const HTTP2_HEADER_AUTHORITY = ':authority' -const HTTP2_HEADER_SCHEME = ':scheme' -const HTTP2_HEADER_PATH = ':path' - -const serverless = { - finishSpan (context) { - const { req, res } = context - - if (context.finished && !req.stream) return - - addRequestTags(context) - addResponseTags(context) - - context.config.hooks.request(context.span, req, res) - addResourceTag(context) - - context.span.finish() - context.finished = true - } -} - -function addRequestTags (context) { - const { req, span, config } = context - const url = extractURL(req) - - span.addTags({ - [HTTP_URL]: web.obfuscateQs(config, url), - [HTTP_METHOD]: req.method, - [SPAN_KIND]: SERVER, - [SPAN_TYPE]: SERVERLESS, - [HTTP_USERAGENT]: req.headers['user-agent'] - }) - - // if client ip has already been set by appsec, no need to run it again - if (config.clientIpEnabled && !span.context()._tags.hasOwnProperty(HTTP_CLIENT_IP)) { - const clientIp = web.extractIp(config, req) - - if (clientIp) { - span.setTag(HTTP_CLIENT_IP, clientIp) - } - } - - addHeaders(context) -} - -function addResponseTags (context) { - const { req, res, paths, span } = context - - if (paths.length > 0) { - span.setTag(HTTP_ROUTE, paths.join('')) - } - - span.addTags({ - [HTTP_STATUS_CODE]: res.status - }) - - web.addStatusError(req, res.status) -} - -function extractURL (req) { - const headers = req.headers - - if (req.stream) { - return `${headers[HTTP2_HEADER_SCHEME]}://${headers[HTTP2_HEADER_AUTHORITY]}${headers[HTTP2_HEADER_PATH]}` - } else { - const protocol = getProtocol(req) - return `${protocol}://${req.headers.host}${req.originalUrl || req.url}` - } -} - -function getProtocol (req) { - if (req.socket && req.socket.encrypted) return 'https' - if (req.connection && req.connection.encrypted) return 'https' - - return 'http' -} - -function addHeaders (context) { - const { req, res, config, span } = context - - config.headers.forEach(([key, tag]) => { - const reqHeader = req.headers[key] - const resHeader = res.getHeader(key) - - if (reqHeader) { - span.setTag(tag || `${HTTP_REQUEST_HEADERS}.${key}`, reqHeader) - } - - if (resHeader) { - span.setTag(tag || `${HTTP_RESPONSE_HEADERS}.${key}`, resHeader) - } - }) -} - -function addResourceTag (context) { - const { req, span } = context - const tags = span.context()._tags - - if (tags['resource.name']) return - - const resource = [req.method, tags[HTTP_ROUTE]] - .filter(val => val) - .join(' ') - - span.setTag(RESOURCE_NAME, resource) -} +const serverless = { ...web } +serverless.TYPE = types.SERVERLESS module.exports = serverless From 6967f7da74e411134b7d73e841d250f89f7b530f Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Wed, 9 Oct 2024 16:16:35 -0400 Subject: [PATCH 22/23] Revert "simplify serverless util" This reverts commit 91a2dd9752663cc57c61760ccf7b9737c60e00fb. --- .../src/index.js | 2 +- .../dd-trace/src/plugins/util/serverless.js | 124 +++++++++++++++++- 2 files changed, 123 insertions(+), 3 deletions(-) diff --git a/packages/datadog-plugin-azure-functions/src/index.js b/packages/datadog-plugin-azure-functions/src/index.js index 2c85403906c..926d8352c16 100644 --- a/packages/datadog-plugin-azure-functions/src/index.js +++ b/packages/datadog-plugin-azure-functions/src/index.js @@ -59,7 +59,7 @@ class AzureFunctionsPlugin extends TracingPlugin { const context = web.patch(req) context.config = this.config context.paths = [path] - context.res = { statusCode: result.status } + context.res = result context.span = ctx.currentStore.span serverless.finishSpan(context) diff --git a/packages/dd-trace/src/plugins/util/serverless.js b/packages/dd-trace/src/plugins/util/serverless.js index 3e969ffdfad..a787a092c26 100644 --- a/packages/dd-trace/src/plugins/util/serverless.js +++ b/packages/dd-trace/src/plugins/util/serverless.js @@ -1,7 +1,127 @@ +const tags = require('../../../../../ext/tags') const types = require('../../../../../ext/types') +const kinds = require('../../../../../ext/kinds') const web = require('./web') -const serverless = { ...web } -serverless.TYPE = types.SERVERLESS +const SERVERLESS = types.SERVERLESS +const SERVER = kinds.SERVER +const RESOURCE_NAME = tags.RESOURCE_NAME +const SPAN_TYPE = tags.SPAN_TYPE +const SPAN_KIND = tags.SPAN_KIND +const HTTP_METHOD = tags.HTTP_METHOD +const HTTP_STATUS_CODE = tags.HTTP_STATUS_CODE +const HTTP_ROUTE = tags.HTTP_ROUTE +const HTTP_REQUEST_HEADERS = tags.HTTP_REQUEST_HEADERS +const HTTP_RESPONSE_HEADERS = tags.HTTP_RESPONSE_HEADERS +const HTTP_URL = tags.HTTP_URL +const HTTP_USERAGENT = tags.HTTP_USERAGENT +const HTTP_CLIENT_IP = tags.HTTP_CLIENT_IP + +const HTTP2_HEADER_AUTHORITY = ':authority' +const HTTP2_HEADER_SCHEME = ':scheme' +const HTTP2_HEADER_PATH = ':path' + +const serverless = { + finishSpan (context) { + const { req, res } = context + + if (context.finished && !req.stream) return + + addRequestTags(context) + addResponseTags(context) + + context.config.hooks.request(context.span, req, res) + addResourceTag(context) + + context.span.finish() + context.finished = true + } +} + +function addRequestTags (context) { + const { req, span, config } = context + const url = extractURL(req) + + span.addTags({ + [HTTP_URL]: web.obfuscateQs(config, url), + [HTTP_METHOD]: req.method, + [SPAN_KIND]: SERVER, + [SPAN_TYPE]: SERVERLESS, + [HTTP_USERAGENT]: req.headers['user-agent'] + }) + + // if client ip has already been set by appsec, no need to run it again + if (config.clientIpEnabled && !span.context()._tags.hasOwnProperty(HTTP_CLIENT_IP)) { + const clientIp = web.extractIp(config, req) + + if (clientIp) { + span.setTag(HTTP_CLIENT_IP, clientIp) + } + } + + addHeaders(context) +} + +function addResponseTags (context) { + const { req, res, paths, span } = context + + if (paths.length > 0) { + span.setTag(HTTP_ROUTE, paths.join('')) + } + + span.addTags({ + [HTTP_STATUS_CODE]: res.status + }) + + web.addStatusError(req, res.status) +} + +function extractURL (req) { + const headers = req.headers + + if (req.stream) { + return `${headers[HTTP2_HEADER_SCHEME]}://${headers[HTTP2_HEADER_AUTHORITY]}${headers[HTTP2_HEADER_PATH]}` + } else { + const protocol = getProtocol(req) + return `${protocol}://${req.headers.host}${req.originalUrl || req.url}` + } +} + +function getProtocol (req) { + if (req.socket && req.socket.encrypted) return 'https' + if (req.connection && req.connection.encrypted) return 'https' + + return 'http' +} + +function addHeaders (context) { + const { req, res, config, span } = context + + config.headers.forEach(([key, tag]) => { + const reqHeader = req.headers[key] + const resHeader = res.getHeader(key) + + if (reqHeader) { + span.setTag(tag || `${HTTP_REQUEST_HEADERS}.${key}`, reqHeader) + } + + if (resHeader) { + span.setTag(tag || `${HTTP_RESPONSE_HEADERS}.${key}`, resHeader) + } + }) +} + +function addResourceTag (context) { + const { req, span } = context + const tags = span.context()._tags + + if (tags['resource.name']) return + + const resource = [req.method, tags[HTTP_ROUTE]] + .filter(val => val) + .join(' ') + + span.setTag(RESOURCE_NAME, resource) +} module.exports = serverless From 21c85afadb12824d7a073e8b6e9bfaf5cabea13f Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Thu, 10 Oct 2024 11:34:47 -0400 Subject: [PATCH 23/23] simplify serverless util --- .../src/index.js | 2 +- .../dd-trace/src/plugins/util/serverless.js | 124 +----------------- packages/dd-trace/src/plugins/util/web.js | 10 +- 3 files changed, 9 insertions(+), 127 deletions(-) diff --git a/packages/datadog-plugin-azure-functions/src/index.js b/packages/datadog-plugin-azure-functions/src/index.js index 926d8352c16..2c85403906c 100644 --- a/packages/datadog-plugin-azure-functions/src/index.js +++ b/packages/datadog-plugin-azure-functions/src/index.js @@ -59,7 +59,7 @@ class AzureFunctionsPlugin extends TracingPlugin { const context = web.patch(req) context.config = this.config context.paths = [path] - context.res = result + context.res = { statusCode: result.status } context.span = ctx.currentStore.span serverless.finishSpan(context) diff --git a/packages/dd-trace/src/plugins/util/serverless.js b/packages/dd-trace/src/plugins/util/serverless.js index a787a092c26..3e969ffdfad 100644 --- a/packages/dd-trace/src/plugins/util/serverless.js +++ b/packages/dd-trace/src/plugins/util/serverless.js @@ -1,127 +1,7 @@ -const tags = require('../../../../../ext/tags') const types = require('../../../../../ext/types') -const kinds = require('../../../../../ext/kinds') const web = require('./web') -const SERVERLESS = types.SERVERLESS -const SERVER = kinds.SERVER -const RESOURCE_NAME = tags.RESOURCE_NAME -const SPAN_TYPE = tags.SPAN_TYPE -const SPAN_KIND = tags.SPAN_KIND -const HTTP_METHOD = tags.HTTP_METHOD -const HTTP_STATUS_CODE = tags.HTTP_STATUS_CODE -const HTTP_ROUTE = tags.HTTP_ROUTE -const HTTP_REQUEST_HEADERS = tags.HTTP_REQUEST_HEADERS -const HTTP_RESPONSE_HEADERS = tags.HTTP_RESPONSE_HEADERS -const HTTP_URL = tags.HTTP_URL -const HTTP_USERAGENT = tags.HTTP_USERAGENT -const HTTP_CLIENT_IP = tags.HTTP_CLIENT_IP - -const HTTP2_HEADER_AUTHORITY = ':authority' -const HTTP2_HEADER_SCHEME = ':scheme' -const HTTP2_HEADER_PATH = ':path' - -const serverless = { - finishSpan (context) { - const { req, res } = context - - if (context.finished && !req.stream) return - - addRequestTags(context) - addResponseTags(context) - - context.config.hooks.request(context.span, req, res) - addResourceTag(context) - - context.span.finish() - context.finished = true - } -} - -function addRequestTags (context) { - const { req, span, config } = context - const url = extractURL(req) - - span.addTags({ - [HTTP_URL]: web.obfuscateQs(config, url), - [HTTP_METHOD]: req.method, - [SPAN_KIND]: SERVER, - [SPAN_TYPE]: SERVERLESS, - [HTTP_USERAGENT]: req.headers['user-agent'] - }) - - // if client ip has already been set by appsec, no need to run it again - if (config.clientIpEnabled && !span.context()._tags.hasOwnProperty(HTTP_CLIENT_IP)) { - const clientIp = web.extractIp(config, req) - - if (clientIp) { - span.setTag(HTTP_CLIENT_IP, clientIp) - } - } - - addHeaders(context) -} - -function addResponseTags (context) { - const { req, res, paths, span } = context - - if (paths.length > 0) { - span.setTag(HTTP_ROUTE, paths.join('')) - } - - span.addTags({ - [HTTP_STATUS_CODE]: res.status - }) - - web.addStatusError(req, res.status) -} - -function extractURL (req) { - const headers = req.headers - - if (req.stream) { - return `${headers[HTTP2_HEADER_SCHEME]}://${headers[HTTP2_HEADER_AUTHORITY]}${headers[HTTP2_HEADER_PATH]}` - } else { - const protocol = getProtocol(req) - return `${protocol}://${req.headers.host}${req.originalUrl || req.url}` - } -} - -function getProtocol (req) { - if (req.socket && req.socket.encrypted) return 'https' - if (req.connection && req.connection.encrypted) return 'https' - - return 'http' -} - -function addHeaders (context) { - const { req, res, config, span } = context - - config.headers.forEach(([key, tag]) => { - const reqHeader = req.headers[key] - const resHeader = res.getHeader(key) - - if (reqHeader) { - span.setTag(tag || `${HTTP_REQUEST_HEADERS}.${key}`, reqHeader) - } - - if (resHeader) { - span.setTag(tag || `${HTTP_RESPONSE_HEADERS}.${key}`, resHeader) - } - }) -} - -function addResourceTag (context) { - const { req, span } = context - const tags = span.context()._tags - - if (tags['resource.name']) return - - const resource = [req.method, tags[HTTP_ROUTE]] - .filter(val => val) - .join(' ') - - span.setTag(RESOURCE_NAME, resource) -} +const serverless = { ...web } +serverless.TYPE = types.SERVERLESS module.exports = serverless diff --git a/packages/dd-trace/src/plugins/util/web.js b/packages/dd-trace/src/plugins/util/web.js index c9cdf1990aa..832044b29f8 100644 --- a/packages/dd-trace/src/plugins/util/web.js +++ b/packages/dd-trace/src/plugins/util/web.js @@ -36,6 +36,8 @@ const contexts = new WeakMap() const ends = new WeakMap() const web = { + TYPE: WEB, + // Ensure the configuration has the correct structure and defaults. normalizeConfig (config) { const headers = getHeadersToRecord(config) @@ -103,7 +105,7 @@ const web = { context.res = res this.setConfig(req, config) - addRequestTags(context) + addRequestTags(context, this.TYPE) return span }, @@ -296,7 +298,7 @@ const web = { if (context.finished && !req.stream) return - addRequestTags(context) + addRequestTags(context, this.TYPE) addResponseTags(context) context.config.hooks.request(context.span, req, res) @@ -423,7 +425,7 @@ function reactivate (req, fn) { : fn() } -function addRequestTags (context) { +function addRequestTags (context, spanType) { const { req, span, config } = context const url = extractURL(req) @@ -431,7 +433,7 @@ function addRequestTags (context) { [HTTP_URL]: web.obfuscateQs(config, url), [HTTP_METHOD]: req.method, [SPAN_KIND]: SERVER, - [SPAN_TYPE]: WEB, + [SPAN_TYPE]: spanType, [HTTP_USERAGENT]: req.headers['user-agent'] })