Skip to content

Commit

Permalink
Merge branch 'master' into igor/standalone-asm-priority-sampler-channel
Browse files Browse the repository at this point in the history
  • Loading branch information
iunanua authored Jul 3, 2024
2 parents ea548ea + 2c1367b commit 61f7b11
Show file tree
Hide file tree
Showing 85 changed files with 7,199 additions and 4,787 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ jobs:
- uses: codecov/codecov-action@v2

couchbase:
strategy:
matrix:
range: ['^2.6.12', '^3.0.7', '>=4.2.0']
runs-on: ubuntu-latest
services:
couchbase:
Expand All @@ -373,6 +376,7 @@ jobs:
env:
PLUGINS: couchbase
SERVICES: couchbase
PACKAGE_VERSION_RANGE: ${{ matrix.range }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/testagent/start
Expand Down Expand Up @@ -938,9 +942,11 @@ jobs:
version:
- 18
- latest
range: ['>=9.5 <11.1', '>=11.1 <13.2', '>=13.2']
runs-on: ubuntu-latest
env:
PLUGINS: next
PACKAGE_VERSION_RANGE: ${{ matrix.range }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/testagent/start
Expand Down
33 changes: 32 additions & 1 deletion .github/workflows/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,25 @@ jobs:
- run: sudo sysctl -w kernel.core_pattern='|/bin/false'
- run: yarn test:integration

# We'll run these separately for earlier (i.e. unsupported) versions
integration-guardrails:
strategy:
matrix:
version: [12, 14, 16]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.version }}
- run: yarn install --ignore-engines
- run: node node_modules/.bin/mocha --colors --timeout 30000 -r packages/dd-trace/test/setup/core.js integration-tests/init.spec.js

integration-ci:
strategy:
matrix:
version: [18, latest]
framework: [cucumber, playwright, selenium]
framework: [cucumber, playwright, selenium, jest, mocha]
runs-on: ubuntu-latest
env:
DD_SERVICE: dd-trace-js-integration-tests
Expand Down Expand Up @@ -96,6 +110,23 @@ jobs:
CYPRESS_VERSION: ${{ matrix.cypress-version }}
NODE_OPTIONS: '-r ./ci/init'

integration-vitest:
runs-on: ubuntu-latest
env:
DD_SERVICE: dd-trace-js-integration-tests
DD_CIVISIBILITY_AGENTLESS_ENABLED: 1
DD_API_KEY: ${{ secrets.DD_API_KEY_CI_APP }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/node/setup
- run: yarn install
- uses: actions/setup-node@v3
with:
node-version: 20
- run: yarn test:integration:vitest
env:
NODE_OPTIONS: '-r ./ci/init'

lint:
runs-on: ubuntu-latest
steps:
Expand Down
50 changes: 22 additions & 28 deletions .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ on:
- cron: '00 04 * * 2-6'

jobs:
build-artifacts:
runs-on: ubuntu-latest
steps:
- name: Checkout dd-trace-js
uses: actions/checkout@v4
with:
path: dd-trace-js
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: system_tests_binaries
path: .

get-essential-scenarios:
runs-on: ubuntu-latest
outputs:
Expand Down Expand Up @@ -71,31 +84,12 @@ jobs:
path: artifact.tar.gz

parametric:
runs-on: ubuntu-latest
env:
TEST_LIBRARY: nodejs
steps:
- name: Checkout system tests
uses: actions/checkout@v4
with:
repository: 'DataDog/system-tests'
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Checkout dd-trace-js
uses: actions/checkout@v4
with:
path: 'binaries/dd-trace-js'
- name: Build
run: ./build.sh -i runner
- name: Run
run: ./run.sh PARAMETRIC
- name: Compress artifact
if: ${{ always() }}
run: tar -czvf artifact.tar.gz $(ls | grep logs)
- name: Upload artifact
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: logs_parametric
path: artifact.tar.gz
needs:
- build-artifacts
uses: DataDog/system-tests/.github/workflows/run-parametric.yml@main
secrets: inherit
with:
library: nodejs
binaries_artifact: system_tests_binaries
_experimental_job_count: 8
_experimental_job_matrix: '[1,2,3,4,5,6,7,8]'
2 changes: 1 addition & 1 deletion .gitlab/single-step-instrumentation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ onboarding_tests:
parallel:
matrix:
- ONBOARDING_FILTER_WEBLOG: [test-app-nodejs]
SCENARIO: [SIMPLE_HOST_AUTO_INJECTION]
SCENARIO: [SIMPLE_HOST_AUTO_INJECTION_PROFILING]
- ONBOARDING_FILTER_WEBLOG: [test-app-nodejs-container]
SCENARIO: [SIMPLE_CONTAINER_AUTO_INJECTION]
script:
Expand Down
7 changes: 6 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
/integration-tests/cucumber/ @DataDog/ci-app-libraries
/integration-tests/cypress/ @DataDog/ci-app-libraries
/integration-tests/playwright/ @DataDog/ci-app-libraries
/integration-tests/ci-visibility.spec.js @DataDog/ci-app-libraries
/integration-tests/jest/jest.spec.js @DataDog/ci-app-libraries
/integration-tests/mocha/mocha.spec.js @DataDog/ci-app-libraries
/integration-tests/playwright/playwright.spec.js @DataDog/ci-app-libraries
/integration-tests/cucumber/cucumber.spec.js @DataDog/ci-app-libraries
/integration-tests/cypress/cypress.spec.js @DataDog/ci-app-libraries
/integration-tests/vitest/vitest.spec.js @DataDog/ci-app-libraries
/integration-tests/test-api-manual.spec.js @DataDog/ci-app-libraries

/packages/dd-trace/src/service-naming/ @Datadog/apm-idm-js
Expand Down
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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,tape,MIT,Copyright James Halliday
dev,tiktoken,MIT,Copyright (c) 2022 OpenAI, Shantanu Jain
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.
3 changes: 3 additions & 0 deletions docs/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ const elasticsearchOptions: plugins.elasticsearch = {
const awsSdkOptions: plugins.aws_sdk = {
service: 'test',
splitByAwsService: false,
batchPropagationEnabled: false,
hooks: {
request: (span?: Span, response?) => {},
},
Expand Down Expand Up @@ -363,6 +364,8 @@ tracer.use('sharedb');
tracer.use('sharedb', sharedbOptions);
tracer.use('tedious');
tracer.use('undici');
tracer.use('vitest');
tracer.use('vitest', { service: 'vitest-service' });
tracer.use('winston');

tracer.use('express', false)
Expand Down
2 changes: 1 addition & 1 deletion ext/exporters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare const exporters: {
DATADOG: 'datadog',
AGENT_PROXY: 'agent_proxy',
JEST_WORKER: 'jest_worker',
CUCUMBER_WORKER: 'cucumber_worker'
CUCUMBER_WORKER: 'cucumber_worker',
MOCHA_WORKER: 'mocha_worker'
}

Expand Down
16 changes: 15 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ interface Plugins {
"sharedb": tracer.plugins.sharedb;
"tedious": tracer.plugins.tedious;
"undici": tracer.plugins.undici;
"vitest": tracer.plugins.vitest;
"winston": tracer.plugins.winston;
}

Expand Down Expand Up @@ -1222,6 +1223,13 @@ declare namespace tracer {
*/
splitByAwsService?: boolean;

/**
* Whether to inject all messages during batch AWS SQS, Kinesis, and SNS send operations. Normal
* behavior is to inject the first message in batch send operations.
* @default false
*/
batchPropagationEnabled?: boolean;

/**
* Hooks to run before spans are finished.
*/
Expand Down Expand Up @@ -1556,7 +1564,7 @@ declare namespace tracer {

/**
* This plugin automatically instruments the
* [jest](https://github.com/facebook/jest) module.
* [jest](https://github.com/jestjs/jest) module.
*/
interface jest extends Integration {}

Expand Down Expand Up @@ -1839,6 +1847,12 @@ declare namespace tracer {
*/
interface undici extends HttpClient {}

/**
* This plugin automatically instruments the
* [vitest](https://github.com/vitest-dev/vitest) module.
*/
interface vitest extends Integration {}

/**
* This plugin patches the [winston](https://github.com/winstonjs/winston)
* to automatically inject trace identifiers in log records when the
Expand Down
41 changes: 40 additions & 1 deletion init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,26 @@

const path = require('path')
const Module = require('module')
const telemetry = require('./packages/dd-trace/src/telemetry/init-telemetry')
const semver = require('semver')

function isTrue (envVar) {
return ['1', 'true', 'True'].includes(envVar)
}

// eslint-disable-next-line no-console
let log = { info: isTrue(process.env.DD_TRACE_DEBUG) ? console.log : () => {} }
if (semver.satisfies(process.versions.node, '>=16')) {
const Config = require('./packages/dd-trace/src/config')
log = require('./packages/dd-trace/src/log')

// eslint-disable-next-line no-new
new Config() // we need this to initialize the logger
}

let initBailout = false
let clobberBailout = false
const forced = isTrue(process.env.DD_INJECT_FORCE)

if (process.env.DD_INJECTION_ENABLED) {
// If we're running via single-step install, and we're not in the app's
Expand All @@ -19,13 +37,34 @@ if (process.env.DD_INJECTION_ENABLED) {
if (resolvedInApp) {
const ourselves = path.join(__dirname, 'index.js')
if (ourselves !== resolvedInApp) {
clobberBailout = true
}
}

// If we're running via single-step install, and the runtime doesn't match
// the engines field in package.json, then we should not initialize the tracer.
if (!clobberBailout) {
const { engines } = require('./package.json')
const version = process.versions.node
if (!semver.satisfies(version, engines.node)) {
initBailout = true
telemetry([
{ name: 'abort', tags: ['reason:incompatible_runtime'] },
{ name: 'abort.runtime', tags: [] }
])
log.info('Aborting application instrumentation due to incompatible_runtime.')
log.info(`Found incompatible runtime nodejs ${version}, Supported runtimes: nodejs ${engines.node}.`)
if (forced) {
log.info('DD_INJECT_FORCE enabled, allowing unsupported runtimes and continuing.')
}
}
}
}

if (!initBailout) {
if (!clobberBailout && (!initBailout || forced)) {
const tracer = require('.')
tracer.init()
module.exports = tracer
telemetry('complete', [`injection_forced:${forced && initBailout ? 'true' : 'false'}`])
log.info('Application instrumentation bootstrapping complete')
}
13 changes: 8 additions & 5 deletions initialize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ export async function getSource (...args) {
}

if (isMainThread) {
await import('./init.js')
const { register } = await import('node:module')
if (register) {
register('./loader-hook.mjs', import.meta.url)
}
// Need this IIFE for versions of Node.js without top-level await.
(async () => {
await import('./init.js')
const { register } = await import('node:module')
if (register) {
register('./loader-hook.mjs', import.meta.url)
}
})()
}
Loading

0 comments on commit 61f7b11

Please sign in to comment.