Skip to content

Commit

Permalink
Merge branch 'master' into automatic_userid_blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-id authored Jan 31, 2025
2 parents 86718b7 + 6f79a86 commit b9ffe92
Show file tree
Hide file tree
Showing 29 changed files with 186 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ description: Install dependencies
runs:
using: composite
steps: # retry in case of server error from registry
- run: yarn install --ignore-engines || yarn install --ignore-engines
- run: yarn install --frozen-lockfile --ignore-engines || yarn install --frozen-lockfile --ignore-engines
shell: bash

31 changes: 21 additions & 10 deletions .github/actions/testagent/logs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,44 @@ runs:
using: composite
steps:
- uses: actions/checkout@v2
- run: |
- name: Create Artifacts Directories
run: |
mkdir -p "./artifacts/logs"
mkdir -p "./artifacts/supported-integrations"
shell: bash
- name: Save Test Agent Logs
id: save_logs
if: runner.debug == '1' # only create test agent log artifacts if the github action has been re-run with debug mode
run: |
if [ -n "${{inputs.container-id}}" ]; then
docker logs ${{inputs.container-id}}
docker logs "${{inputs.container-id}}" > "artifacts/logs/test_agent_logs_${{ inputs.suffix }}.txt"
else
docker compose logs testagent
docker compose logs testagent > "artifacts/logs/test_agent_logs_${{ inputs.suffix }}.txt"
fi
shell: bash
- name: Archive Test Agent Logs
if: runner.debug == '1' # only create test agent log artifacts if the github action has been re-run with debug mode
uses: actions/upload-artifact@v4
with:
name: "test_agent_logs_${{ inputs.suffix }}"
path: "./artifacts/logs"
- name: Get Tested Integrations from Test Agent
run: |
# make temporary files to save response data to
response=$(mktemp) && headers=$(mktemp)
# create artifacts directory if it doesn't exist
mkdir -p "./artifacts"
# get tested integrations
curl -o "$response" -D "$headers" http://127.0.0.1:9126/test/integrations/tested_versions
# get filename representing the name of the tested integration from headers
filename=$(awk -F': ' '/file-name/{print $2}' "$headers" | tr -d '\r\n')
# copy data to final file and remove temp files
mv "$response" "artifacts/${filename}_supported_versions.csv"
mv "$response" "artifacts/supported-integrations/${filename}_supported_versions.csv"
rm "$headers"
shell: bash
- name: Archive Test Agent Artifacts
- name: Archive Test Agent Tested Versions Artifacts
uses: actions/upload-artifact@v4
with:
name: supported-integrations-${{inputs.suffix}}
path: ./artifacts
name: supported-integrations-${{ inputs.suffix }}
path: ./artifacts
3 changes: 1 addition & 2 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dev,@apollo/server,MIT,Copyright (c) 2016-2020 Apollo Graph, Inc. (Formerly Mete
dev,@types/node,MIT,Copyright Authors
dev,@eslint/eslintrc,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
dev,@eslint/js,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
dev,@msgpack/msgpack,ISC,Copyright 2019 The MessagePack Community
dev,@stylistic/eslint-plugin-js,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
dev,autocannon,MIT,Copyright 2016 Matteo Collina
dev,aws-sdk,Apache 2.0,Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand All @@ -58,12 +59,10 @@ dev,get-port,MIT,Copyright Sindre Sorhus
dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors
dev,globals,MIT,Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
dev,graphql,MIT,Copyright 2015 Facebook Inc.
dev,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
dev,jszip,MIT,Copyright 2015-2016 Stuart Knightley and contributors
dev,knex,MIT,Copyright (c) 2013-present Tim Griesser
dev,mkdirp,MIT,Copyright 2010 James Halliday
dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foundation
dev,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
dev,multer,MIT,Copyright 2014 Hage Yaapa
dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
dev,nyc,ISC,Copyright 2015 Contributors
Expand Down
7 changes: 3 additions & 4 deletions integration-tests/ci-visibility-intake.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const express = require('express')
const bodyParser = require('body-parser')
const msgpack = require('msgpack-lite')
const codec = msgpack.createCodec({ int64: true })
const msgpack = require('@msgpack/msgpack')
const http = require('http')
const multer = require('multer')
const upload = multer()
Expand Down Expand Up @@ -81,7 +80,7 @@ class FakeCiVisIntake extends FakeAgent {
res.status(200).send({ rate_by_service: { 'service:,env:': 1 } })
this.emit('message', {
headers: req.headers,
payload: msgpack.decode(req.body, { codec }),
payload: msgpack.decode(req.body, { useBigInt64: true }),
url: req.url
})
})
Expand All @@ -100,7 +99,7 @@ class FakeCiVisIntake extends FakeAgent {
res.status(200).send('OK')
this.emit('message', {
headers: req.headers,
payload: msgpack.decode(req.body, { codec }),
payload: msgpack.decode(req.body, { useBigInt64: true }),
url: req.url
})
}, waitingTime || 0)
Expand Down
5 changes: 2 additions & 3 deletions integration-tests/helpers/fake-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const EventEmitter = require('events')
const http = require('http')
const express = require('express')
const bodyParser = require('body-parser')
const msgpack = require('msgpack-lite')
const codec = msgpack.createCodec({ int64: true })
const msgpack = require('@msgpack/msgpack')
const upload = require('multer')()

module.exports = class FakeAgent extends EventEmitter {
Expand Down Expand Up @@ -241,7 +240,7 @@ function buildExpressServer (agent) {
res.status(200).send({ rate_by_service: { 'service:,env:': 1 } })
agent.emit('message', {
headers: req.headers,
payload: msgpack.decode(req.body, { codec })
payload: msgpack.decode(req.body, { useBigInt64: true })
})
})

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"@datadog/native-iast-rewriter": "2.6.1",
"@datadog/native-iast-taint-tracking": "3.2.0",
"@datadog/native-metrics": "^3.1.0",
"@datadog/pprof": "5.5.0",
"@datadog/pprof": "5.5.1",
"@datadog/sketches-js": "^2.1.0",
"@isaacs/ttlcache": "^1.4.1",
"@opentelemetry/api": ">=1.0.0 <1.9.0",
Expand Down Expand Up @@ -118,6 +118,7 @@
"@apollo/server": "^4.11.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.11.1",
"@msgpack/msgpack": "^3.0.0-beta3",
"@stylistic/eslint-plugin-js": "^2.8.0",
"@types/node": "^16.0.0",
"autocannon": "^4.5.2",
Expand All @@ -142,12 +143,10 @@
"glob": "^7.1.6",
"globals": "^15.10.0",
"graphql": "0.13.2",
"int64-buffer": "^0.1.9",
"jszip": "^3.5.0",
"knex": "^2.4.2",
"mkdirp": "^3.0.1",
"mocha": "^10",
"msgpack-lite": "^0.1.26",
"multer": "^1.4.5-lts.1",
"nock": "^11.3.3",
"nyc": "^15.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,45 @@ describe('esm', () => {
await agent.stop()
})

it('is instrumented', async () => {
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port)
const numberOfSpans = semver.intersects(version, '<5.0.0') ? 4 : 3

return curlAndAssertMessage(agent, proc, ({ 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, numberOfSpans)
assert.propertyVal(payload[0][0], 'name', 'express.request')
assert.propertyVal(payload[0][1], 'name', 'express.middleware')
describe('with DD_TRACE_MIDDLEWARE_TRACING_ENABLED unset', () => {
it('is instrumented', async () => {
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port)
const numberOfSpans = semver.intersects(version, '<5.0.0') ? 4 : 3

return curlAndAssertMessage(agent, proc, ({ 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, numberOfSpans)
assert.propertyVal(payload[0][0], 'name', 'express.request')
assert.propertyVal(payload[0][1], 'name', 'express.middleware')
})
}).timeout(50000)
})

describe('with DD_TRACE_MIDDLEWARE_TRACING_ENABLED=true', () => {
before(() => {
process.env.DD_TRACE_MIDDLEWARE_TRACING_ENABLED = false
})

after(() => {
delete process.env.DD_TRACE_MIDDLEWARE_TRACING_ENABLED
})
}).timeout(50000)

it('disables middleware spans when config.middlewareTracingEnabled is false via env var', async () => {
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port)
const numberOfSpans = 1

return curlAndAssertMessage(agent, proc, ({ 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, numberOfSpans)
assert.propertyVal(payload[0][0], 'name', 'express.request')
})
}).timeout(50000)
})
})
})
2 changes: 1 addition & 1 deletion packages/datadog-plugin-moleculer/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const os = require('os')
const agent = require('../../dd-trace/test/plugins/agent')
const { expectedSchema, rawExpectedSchema } = require('./naming')

const sort = trace => trace.sort((a, b) => a.start.toNumber() - b.start.toNumber())
const sort = trace => trace.sort((a, b) => Number(a.start - b.start))

describe('Plugin', () => {
let broker
Expand Down
9 changes: 4 additions & 5 deletions packages/datadog-plugin-net/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const dns = require('dns')
const agent = require('../../dd-trace/test/plugins/agent')
const { expectSomeSpan } = require('../../dd-trace/test/plugins/helpers')
const { Int64BE } = require('int64-buffer') // TODO remove dependency
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')

describe('Plugin', () => {
Expand Down Expand Up @@ -66,7 +65,7 @@ describe('Plugin', () => {
'span.kind': 'client',
'ipc.path': '/tmp/dd-trace.sock'
},
parent_id: new Int64BE(parent.context()._spanId._buffer)
parent_id: BigInt(parent.context()._spanId.toString(10))
}).then(done).catch(done)

tracer.scope().activate(parent, () => {
Expand Down Expand Up @@ -121,7 +120,7 @@ describe('Plugin', () => {
'tcp.remote.port': port,
'tcp.local.port': socket.localPort
},
parent_id: new Int64BE(parent.context()._spanId._buffer)
parent_id: BigInt(parent.context()._spanId.toString(10))
}, 2000).then(done).catch(done)
})
})
Expand Down Expand Up @@ -152,7 +151,7 @@ describe('Plugin', () => {
'tcp.remote.port': port,
'tcp.local.port': socket.localPort
},
parent_id: new Int64BE(parent.context()._spanId._buffer)
parent_id: BigInt(parent.context()._spanId.toString(10))
}).then(done).catch(done)
})
})
Expand All @@ -168,7 +167,7 @@ describe('Plugin', () => {
'span.kind': 'client',
'ipc.path': '/tmp/dd-trace.sock'
},
parent_id: new Int64BE(parent.context()._spanId._buffer)
parent_id: BigInt(parent.context()._spanId.toString(10))
}).then(done).catch(done)

tracer.scope().activate(parent, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
const { assert } = require('chai')

// TODO(sabrenner): re-enable once issues with mocking OpenAI calls are resolved
describe.skip('esm', () => {
describe('esm', () => {
let agent
let proc
let sandbox
Expand Down
18 changes: 1 addition & 17 deletions packages/datadog-plugin-openai/test/integration-test/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@ import nock from 'nock'

nock('https://api.openai.com:443')
.post('/v1/completions')
.reply(200, {}, [
'Date', 'Mon, 15 May 2023 17:24:22 GMT',
'Content-Type', 'application/json',
'Content-Length', '349',
'Connection', 'close',
'openai-model', 'text-davinci-002',
'openai-organization', 'kill-9',
'openai-processing-ms', '442',
'openai-version', '2020-10-01',
'x-ratelimit-limit-requests', '3000',
'x-ratelimit-limit-tokens', '250000',
'x-ratelimit-remaining-requests', '2999',
'x-ratelimit-remaining-tokens', '249984',
'x-ratelimit-reset-requests', '20ms',
'x-ratelimit-reset-tokens', '3ms',
'x-request-id', '7df89d8afe7bf24dc04e2c4dd4962d7f'
])
.reply(200, {})

const openaiApp = new openai.OpenAIApi(new openai.Configuration({
apiKey: 'sk-DATADOG-ACCEPTANCE-TESTS'
Expand Down
4 changes: 4 additions & 0 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ class Config {
this._setValue(defaults, 'lookup', undefined)
this._setValue(defaults, 'inferredProxyServicesEnabled', false)
this._setValue(defaults, 'memcachedCommandEnabled', false)
this._setValue(defaults, 'middlewareTracingEnabled', true)
this._setValue(defaults, 'openAiLogsEnabled', false)
this._setValue(defaults, 'openai.spanCharLimit', 128)
this._setValue(defaults, 'peerServiceMapping', {})
Expand Down Expand Up @@ -674,6 +675,7 @@ class Config {
DD_TRACE_HEADER_TAGS,
DD_TRACE_LEGACY_BAGGAGE_ENABLED,
DD_TRACE_MEMCACHED_COMMAND_ENABLED,
DD_TRACE_MIDDLEWARE_TRACING_ENABLED,
DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP,
DD_TRACE_PARTIAL_FLUSH_MIN_SPANS,
DD_TRACE_PEER_SERVICE_MAPPING,
Expand Down Expand Up @@ -806,6 +808,7 @@ class Config {
this._setBoolean(env, 'logInjection', DD_LOGS_INJECTION)
// Requires an accompanying DD_APM_OBFUSCATION_MEMCACHED_KEEP_COMMAND=true in the agent
this._setBoolean(env, 'memcachedCommandEnabled', DD_TRACE_MEMCACHED_COMMAND_ENABLED)
this._setBoolean(env, 'middlewareTracingEnabled', DD_TRACE_MIDDLEWARE_TRACING_ENABLED)
this._setBoolean(env, 'openAiLogsEnabled', DD_OPENAI_LOGS_ENABLED)
this._setValue(env, 'openai.spanCharLimit', maybeInt(DD_OPENAI_SPAN_CHAR_LIMIT))
this._envUnprocessed.openaiSpanCharLimit = DD_OPENAI_SPAN_CHAR_LIMIT
Expand Down Expand Up @@ -989,6 +992,7 @@ class Config {
this._setString(opts, 'llmobs.mlApp', options.llmobs?.mlApp)
this._setBoolean(opts, 'logInjection', options.logInjection)
this._setString(opts, 'lookup', options.lookup)
this._setBoolean(opts, 'middlewareTracingEnabled', options.middlewareTracingEnabled)
this._setBoolean(opts, 'openAiLogsEnabled', options.openAiLogsEnabled)
this._setValue(opts, 'peerServiceMapping', options.peerServiceMapping)
this._setBoolean(opts, 'plugins', options.plugins)
Expand Down
2 changes: 0 additions & 2 deletions packages/dd-trace/src/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ let batch = 0
// Internal representation of a trace or span ID.
class Identifier {
constructor (value, radix = 16) {
this._isUint64BE = true // msgpack-lite compatibility
this._buffer = radix === 16
? createBuffer(value)
: fromString(value, radix)
Expand All @@ -31,7 +30,6 @@ class Identifier {
return this._buffer
}

// msgpack-lite compatibility
toArray () {
if (this._buffer.length === 8) {
return this._buffer
Expand Down
10 changes: 9 additions & 1 deletion packages/dd-trace/src/plugin_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ module.exports = class PluginManager {
memcachedCommandEnabled,
ciVisibilityTestSessionName,
ciVisAgentlessLogSubmissionEnabled,
isTestDynamicInstrumentationEnabled
isTestDynamicInstrumentationEnabled,
middlewareTracingEnabled
} = this._tracerConfig

const sharedConfig = {
Expand Down Expand Up @@ -170,6 +171,13 @@ module.exports = class PluginManager {
sharedConfig.clientIpEnabled = clientIpEnabled
}

// For the global setting, we use the name `middlewareTracingEnabled`, but
// for the plugin-specific setting, we use `middleware`. They mean the same
// to an individual plugin, so we normalize them here.
if (middlewareTracingEnabled !== undefined) {
sharedConfig.middleware = middlewareTracingEnabled
}

return sharedConfig
}
}
Loading

0 comments on commit b9ffe92

Please sign in to comment.