- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
Supported test frameworks:
Test Framework | Version | Notes |
---|---|---|
Jest | >= 24.8.0 | Only jsdom (in the jest-environment-jsdom package) and node (in the jest-environment-node package) are supported as test environments. Custom environments like @jest-runner/electron/environment in jest-electron-runner are not supported.Only jest-circus is supported as testRunner .test.concurrent is not supported. |
Mocha | >= 5.2.0 | Mocha >= 9.0.0 has partial support. |
Cucumber | >= 7.0.0 | |
Cypress | >= 6.7.0 | |
Playwright | >= 1.18.0 | |
Vitest | >= 1.16.0 | Supported from dd-trace>=4.42.0 and dd-trace>=5.18.0 . Only supported from Node.js>=18.19 or Node.js>=20.6 |
The instrumentation works at runtime, so any transpilers such as TypeScript, Webpack, or Babel are supported out-of-the-box.
To report test results to Datadog, you need to configure the Datadog JavaScript library:
We support auto-instrumentation for the following CI providers:
CI Provider | Auto-Instrumentation method |
---|---|
GitHub Actions | Datadog Test Visibility Github Action |
Jenkins | UI-based configuration with Datadog Jenkins plugin |
GitLab | Datadog Test Visibility GitLab Script |
CircleCI | Datadog Test Visibility CircleCI Orb |
If you are using auto-instrumentation for one of these providers, you can skip the rest of the setup steps below.
DD_CIVISIBILITY_AGENTLESS_ENABLED=true
(필수)false
DD_API_KEY
(필수)(empty)
추가로 데이터를 보낼 Datadog 사이트를 구성하세요.
DD_SITE
(필수)datadoghq.com
Jenkins 또는 자체 관리형 GitLab CI와 같은 온프레미스 CI 공급자에서 테스트를 실행하는 경우, 에이전트 설치 지침에 따라 각 작업자 노드에 Datadog 에이전트를 설치합니다. 자동으로 테스트 결과를 로그와 기본 호트스 메트릭과 연결할 수 있기 때문에 이 옵션을 추천합니다.
쿠버네티스 실행기를 사용하는 경우 Datadog에서는 Datadog 연산자를 사용할 것을 권고합니다. 연산자에는 Datadog 허용 제어기가 포함되어 있어 빌드 파드에 자동으로 추적기 라이브러리를 삽입합니다. 참고: Datadog 연산자를 사용할 경우 허용 제어기가 작업을 해주기 때문에 추적기 라이브러리를 다운로드 받고 삽입할 필요가 없습니다. 따라서 아래 해당 단계를 건너뛰어도 됩니다. 그러나 테스트 가시화 기능을 사용할 때 필요한 파드의 환경 변수나 명령줄 파라미터는 설정해야 합니다.
쿠버네티스를 사용하지 않거나 Datadog 허용 제어기를 사용할 수 없고 CI 공급자가 컨테이너 기반 실행기를 사용하는 경우, 추적기를 실행하는 빌드 컨테이너에서 환경 변수 DD_TRACE_AGENT_URL
(기본값 http://localhost:8126
)를 해당 컨테이너 내에서 액세스할 수 있는 엔드포인트로 설정합니다. 참고: 빌드 내에서 localhost
를 사용하면 기본 작업자 노드나 에이전트를 실행하는 컨테이너를 참조하지 않고 컨테이너 자체를 참조합니다.
DD_TRACE_AGENT_URL
은 프로토콜과 포트(예: http://localhost:8126
)를 포함하고 DD_AGENT_HOST
과 DD_TRACE_AGENT_PORT
보다 우선하며, CI Visibility를 위해 Datadog 에이전트의 URL을 설정하는 데 권장되는 설정 파라미터입니다.
Datdog 에이전트에 연결하는 데 아직 문제가 있다면 에이전트리스 모드를 사용해 보세요. 참고: 이 방법을 사용할 경우 테스트가 로그 및 인프라스트럭처 메트릭과 상관 관계를 수립하지 않습니다.
To install the JavaScript Tracer, run:
yarn add --dev dd-trace
For more information, see the JavaScript Tracer installation documentation.
Set the NODE_OPTIONS
environment variable to -r dd-trace/ci/init
. Run your tests as you normally would, specifying the environment where the tests are run in the DD_ENV
environment variable. For example, set DD_ENV
to local
when running tests on a developer workstation, or ci
when running them on a CI provider:
NODE_OPTIONS="-r dd-trace/ci/init" DD_ENV=ci DD_SERVICE=my-javascript-app yarn test
Note: If you set a value for NODE_OPTIONS
, make sure it does not overwrite -r dd-trace/ci/init
. This can be done using the ${NODE_OPTIONS:-}
clause:
package.json
{
"scripts": {
"test": "NODE_OPTIONS=\"--max-old-space-size=12288 ${NODE_OPTIONS:-}\" jest"
}
}
You can add custom tags to your tests by using the current active span:
it('sum function can sum', () => {
const testSpan = require('dd-trace').scope().active()
testSpan.setTag('team_owner', 'my_team')
// test continues normally
// ...
})
To create filters or group by
fields for these tags, you must first create facets. For more information about adding tags, see the Adding Tags section of the Node.js custom instrumentation documentation.
Just like tags, you can add custom measures to your tests by using the current active span:
it('sum function can sum', () => {
const testSpan = require('dd-trace').scope().active()
testSpan.setTag('memory_allocations', 16)
// test continues normally
// ...
})
For more information about custom measures, see the Add Custom Measures Guide.
Mocha >=9.0.0 uses an ESM-first approach to load test files. Set NODE_OPTIONS
to -r dd-trace/ci/init --import dd-trace/register.js
to get full visibility into your tests. See dd-trace-js
ESM support for more information.
Set the NODE_OPTIONS
environment variable to -r dd-trace/ci/init
. Run your tests as you normally would, specifying the environment where the tests are run in the DD_ENV
environment variable. For example, set DD_ENV
to local
when running tests on a developer workstation, or ci
when running them on a CI provider:
NODE_OPTIONS="-r dd-trace/ci/init" DD_ENV=ci DD_SERVICE=my-javascript-app yarn test
Note: If you set a value for NODE_OPTIONS
, make sure it does not overwrite -r dd-trace/ci/init
. This can be done using the ${NODE_OPTIONS:-}
clause:
package.json
{
"scripts": {
"test": "NODE_OPTIONS=\"--max-old-space-size=12288 ${NODE_OPTIONS:-}\" jest"
}
}
You can add custom tags to your tests by using the custom annotations API from Playwright:
test('user profile', async ({ page }) => {
test.info().annotations.push({
type: 'DD_TAGS[test.memory.usage]', // DD_TAGS is mandatory and case sensitive
description: 'low',
});
test.info().annotations.push({
type: 'DD_TAGS[test.task.id]',
description: '41123',
});
// ...
});
test('landing page', async ({ page }) => {
test.info().annotations.push({
type: 'DD_TAGS[test.cpu.usage]',
description: 'high',
});
// ...
});
The format of the annotations is the following, where $TAG_NAME
and $TAG_VALUE
are strings representing tag name and value respectively:
{
"type": "DD_TAGS[$TAG_NAME]",
"description": "$TAG_VALUE"
}
Custom measures also use custom annotations:
test('user profile', async ({ page }) => {
test.info().annotations.push({
type: 'DD_TAGS[test.memory.allocations]', // DD_TAGS is mandatory and case sensitive
description: 16, // this is a number
});
});
The format of the annotations is the following, where $TAG_NAME
is a string representing the tag name and $TAG_VALUE
is a number representing the tag value:
{
"type": "DD_TAGS[$TAG_NAME]",
"description": $TAG_VALUE
}
Note: description
values in annotations are typed as strings. Numbers also work, but you may need to disable the typing error with // @ts-expect-error
.
DD_TAGS
prefix is mandatory and case sensitive.Set the NODE_OPTIONS
environment variable to -r dd-trace/ci/init
. Run your tests as you normally would, specifying the environment where the tests are run in the DD_ENV
environment variable. For example, set DD_ENV
to local
when running tests on a developer workstation, or ci
when running them on a CI provider:
NODE_OPTIONS="-r dd-trace/ci/init" DD_ENV=ci DD_SERVICE=my-javascript-app yarn test
Note: If you set a value for NODE_OPTIONS
, make sure it does not overwrite -r dd-trace/ci/init
. This can be done using the ${NODE_OPTIONS:-}
clause:
package.json
{
"scripts": {
"test": "NODE_OPTIONS=\"--max-old-space-size=12288 ${NODE_OPTIONS:-}\" jest"
}
}
You can add custom tags to your test by grabbing the current active span:
When('the function is called', function () {
const stepSpan = require('dd-trace').scope().active()
testSpan.setTag('team_owner', 'my_team')
// test continues normally
// ...
})
To create filters or group by
fields for these tags, you must first create facets. For more information about adding tags, see the Adding Tags section of the Node.js custom instrumentation documentation.
You may also add custom measures to your test by grabbing the current active span:
When('the function is called', function () {
const stepSpan = require('dd-trace').scope().active()
testSpan.setTag('memory_allocations', 16)
// test continues normally
// ...
})
For more information about custom measures, see the Add Custom Measures Guide.
Use the Cypress API documentation to learn how to use plugins for cypress>=10
.
In your cypress.config.js
file, set the following:
cypress.config.js
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
setupNodeEvents: require('dd-trace/ci/cypress/plugin'),
supportFile: 'cypress/support/e2e.js'
}
})
Add the following line to the top level of your supportFile
:
cypress/support/e2e.js
// Your code can be before this line
// require('./commands')
require('dd-trace/ci/cypress/support')
// Also supported:
// import 'dd-trace/ci/cypress/support'
// Your code can also be after this line
// Cypress.Commands.add('login', (email, pw) => {})
If you’re using other Cypress plugins, your cypress.config.js
file should contain the following:
cypress.config.js
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// your previous code is before this line
require('dd-trace/ci/cypress/plugin')(on, config)
}
}
})
after:run
eventDatadog requires the after:run
Cypress event to work, and Cypress does not allow multiple handlers for that event. If you defined handlers for after:run
already, add the Datadog handler manually by importing 'dd-trace/ci/cypress/after-run'
:
cypress.config.js
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
require('dd-trace/ci/cypress/plugin')(on, config)
// other plugins
on('after:run', (details) => {
// other 'after:run' handlers
// important that this function call is returned
return require('dd-trace/ci/cypress/after-run')(details)
})
}
}
})
after:spec
eventDatadog requires the after:spec
Cypress event to work, and Cypress does not allow multiple handlers for that event. If you defined handlers for after:spec
already, add the Datadog handler manually by importing 'dd-trace/ci/cypress/after-spec'
:
cypress.config.js
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
require('dd-trace/ci/cypress/plugin')(on, config)
// other plugins
on('after:spec', (...args) => {
// other 'after:spec' handlers
// Important that this function call is returned
// Important that all the arguments are passed
return require('dd-trace/ci/cypress/after-spec')(...args)
})
}
}
})
These are the instructions if you’re using a version older than cypress@10
. See the Cypress documentation for more information about migrating to a newer version.
pluginsFile
to "dd-trace/ci/cypress/plugin"
, for example, through cypress.json
:cypress.json
{
"pluginsFile": "dd-trace/ci/cypress/plugin"
}
If you already defined a pluginsFile
, initialize the instrumentation with:
cypress/plugins/index.js
module.exports = (on, config) => {
// your previous code is before this line
require('dd-trace/ci/cypress/plugin')(on, config)
}
supportFile
:cypress/support/index.js
// Your code can be before this line
// require('./commands')
require('dd-trace/ci/cypress/support')
// Your code can also be after this line
// Cypress.Commands.add('login', (email, pw) => {})
after:run
eventDatadog requires the after:run
Cypress event to work, and Cypress does not allow multiple handlers for that event. If you defined handlers for after:run
already, add the Datadog handler manually by importing 'dd-trace/ci/cypress/after-run'
:
cypress/plugins/index.js
module.exports = (on, config) => {
// your previous code is before this line
require('dd-trace/ci/cypress/plugin')(on, config)
on('after:run', (details) => {
// other 'after:run' handlers
// important that this function call is returned
return require('dd-trace/ci/cypress/after-run')(details)
})
}
after:spec
eventDatadog requires the after:spec
Cypress event to work, and Cypress does not allow multiple handlers for that event. If you defined handlers for after:spec
already, add the Datadog handler manually by importing 'dd-trace/ci/cypress/after-spec'
:
cypress/plugins/index.js
module.exports = (on, config) => {
// your previous code is before this line
require('dd-trace/ci/cypress/plugin')(on, config)
on('after:spec', (...args) => {
// other 'after:spec' handlers
// Important that this function call is returned
// Important that all the arguments are passed
return require('dd-trace/ci/cypress/after-run')(...args)
})
}
Run your tests as you normally do, specifying the environment where test are being run (for example, local
when running tests on a developer workstation, or ci
when running them on a CI provider) in the DD_ENV
environment variable. For example:
DD_ENV=ci DD_SERVICE=my-ui-app npm test
To add additional information to your tests, such as the team owner, use cy.task('dd:addTags', { yourTags: 'here' })
in your test or hooks.
For example:
beforeEach(() => {
cy.task('dd:addTags', {
'before.each': 'certain.information'
})
})
it('renders a hello world', () => {
cy.task('dd:addTags', {
'team.owner': 'ui'
})
cy.get('.hello-world')
.should('have.text', 'Hello World')
})
To create filters or group by
fields for these tags, you must first create facets. For more information about adding tags, see the Adding Tags section of the Node.js custom instrumentation documentation.
To add custom measures to your tests, such as memory allocations, use cy.task('dd:addTags', { yourNumericalTags: 1 })
in your test or hooks.
For example:
it('renders a hello world', () => {
cy.task('dd:addTags', {
'memory_allocations': 16
})
cy.get('.hello-world')
.should('have.text', 'Hello World')
})
For more information about custom measures, see the Add Custom Measures Guide.
If the browser application being tested is instrumented using Browser Monitoring, the Cypress test results and their generated RUM browser sessions and session replays are automatically linked. For more information, see the Instrumenting your browser tests with RUM guide.
vitest
and dd-trace
require Node.js>=18.19 or Node.js>=20.6 to work.
Set the NODE_OPTIONS
environment variable to --import dd-trace/register.js -r dd-trace/ci/init
. Run your tests as you normally would, specifying the environment where the tests are run in the DD_ENV
environment variable. For example, set DD_ENV
to local
when running tests on a developer workstation, or ci
when running them on a CI provider:
NODE_OPTIONS="--import dd-trace/register.js -r dd-trace/ci/init" DD_ENV=ci DD_SERVICE=my-javascript-app yarn test
Note: If you set a value for NODE_OPTIONS
, make sure it does not overwrite --import dd-trace/register.js -r dd-trace/ci/init
. This can be done using the ${NODE_OPTIONS:-}
clause:
package.json
{
"scripts": {
"test": "NODE_OPTIONS=\"--max-old-space-size=12288 ${NODE_OPTIONS:-}\" vitest run"
}
}
Not supported.
When using dd-trace
, you might encounter the following error message:
Error: Cannot find module 'dd-trace/ci/init'
This might be because of an incorrect usage of NODE_OPTIONS
.
For example, if your GitHub Action looks like this:
jobs:
my-job:
name: Run tests
runs-on: ubuntu-latest
env:
NODE_OPTIONS: -r dd-trace/ci/init
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install node
uses: actions/setup-node@v3
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
Note: This does not work because NODE_OPTIONS
are interpreted by every node process, including npm install
. If you try to import dd-trace/ci/init
before it’s installed, this step fails.
Your GitHub Action should instead look like this:
jobs:
my-job:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install node
uses: actions/setup-node@v3
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
env:
NODE_OPTIONS: -r dd-trace/ci/init
Follow these best practices:
NODE_OPTIONS
environment variable is only set to the process running tests.NODE_OPTIONS
in the global environment variables settings in your pipeline or job definition.If you’re using yarn>=2
and a .pnp.cjs
file, you might also get the same error:
Error: Cannot find module 'dd-trace/ci/init'
You can fix it by setting NODE_OPTIONS
to the following:
NODE_OPTIONS="-r $(pwd)/.pnp.cjs -r dd-trace/ci/init" yarn test
When tests are instrumented with Istanbul, the Datadog Tracer (v3.20.0 or later) reports it under the test.code_coverage.lines_pct
tag for your test sessions.
You can see the evolution of the test coverage in the Coverage tab of a test session.
For more information, see Code Coverage.
The following is a list of the most important configuration settings that can be used with the tracer.
service
DD_SERVICE
my-ui
env
DD_ENV
none
local
, ci
url
http://hostname:port
.DD_TRACE_AGENT_URL
http://localhost:8126
For more information about service
and env
reserved tags, see Unified Service Tagging. All other Datadog Tracer configuration options can also be used.
Datadog은 Git 정보를 사용하여 테스트 결과를 시각화하고 리포지토리, 브랜치, 커밋별로 그룹화합니다. Git 메타데이터는 CI 공급자 환경 변수와 프로젝트 경로의 로컬 .git
폴더(사용 가능한 경우)에서 테스트 계측으로 자동 수집합니다.
지원되지 않는 CI 공급자이거나 .git
폴더가 없는 상태에서 테스트를 실행하는 경우, 환경 변수를 사용하여 Git 정보를 수동으로 설정할 수 있습니다. 해당 환경 변수는 자동 탐지된 정보보다 우선합니다. 다음 환경 변수를 설정하여 Git 정보를 제공합니다.
DD_GIT_REPOSITORY_URL
git@github.com:MyCompany/MyApp.git
, https://github.com/MyCompany/MyApp.git
DD_GIT_BRANCH
develop
DD_GIT_TAG
1.0.1
DD_GIT_COMMIT_SHA
a18ebf361cc831f5535e58ec4fae04ffd98d8152
DD_GIT_COMMIT_MESSAGE
Set release number
DD_GIT_COMMIT_AUTHOR_NAME
John Smith
DD_GIT_COMMIT_AUTHOR_EMAIL
john@example.com
DD_GIT_COMMIT_AUTHOR_DATE
2021-03-12T16:00:28Z
DD_GIT_COMMIT_COMMITTER_NAME
Jane Smith
DD_GIT_COMMIT_COMMITTER_EMAIL
jane@example.com
DD_GIT_COMMIT_COMMITTER_DATE
2021-03-12T16:00:28Z
dd-trace
versions 5.23.0
and 4.47.0
.If you use Jest, Mocha, Cypress, Playwright, Cucumber, or Vitest, do not use the manual testing API, as Test Optimization automatically instruments them and sends the test results to Datadog. The manual testing API is incompatible with already supported testing frameworks.
Use the manual testing API only if you use an unsupported testing framework or have a different testing mechanism.
The manual testing API leverages the node:diagnostics_channel
module from Node.js and is based on channels you can publish to:
const { channel } = require('node:diagnostics_channel')
const { describe, test, beforeEach, afterEach, assert } = require('my-custom-test-framework')
const testStartCh = channel('dd-trace:ci:manual:test:start')
const testFinishCh = channel('dd-trace:ci:manual:test:finish')
const testSuite = __filename
describe('can run tests', () => {
beforeEach((testName) => {
testStartCh.publish({ testName, testSuite })
})
afterEach((status, error) => {
testFinishCh.publish({ status, error })
})
test('first test will pass', () => {
assert.equal(1, 1)
})
})
Grab this channel by its ID dd-trace:ci:manual:test:start
to publish that a test is starting. A good place to do this is a beforeEach
hook or similar.
const { channel } = require('node:diagnostics_channel')
const testStartCh = channel('dd-trace:ci:manual:test:start')
// ... code for your testing framework goes here
beforeEach(() => {
const testDefinition = {
testName: 'a-string-that-identifies-this-test',
testSuite: 'what-suite-this-test-is-from.js'
}
testStartCh.publish(testDefinition)
})
// code for your testing framework continues here ...
The payload to be published has attributes testName
and testSuite
, both strings, that identify the test that is about to start.
Grab this channel by its ID dd-trace:ci:manual:test:finish
to publish that a test is ending. A good place to do this is an afterEach
hook or similar.
const { channel } = require('node:diagnostics_channel')
const testFinishCh = channel('dd-trace:ci:manual:test:finish')
// ... code for your testing framework goes here
afterEach(() => {
const testStatusPayload = {
status: 'fail',
error: new Error('assertion error')
}
testStartCh.publish(testStatusPayload)
})
// code for your testing framework continues here ...
The payload to be published has attributes status
and error
:
status
is a string that takes one of three values:
'pass'
when a test passes.'fail'
when a test fails.'skip'
when a test has been skipped.error
is an Error
object containing the reason why a test failed.
Grab this channel by its ID dd-trace:ci:manual:test:addTags
to publish that a test needs custom tags. This can be done within the test function:
const { channel } = require('node:diagnostics_channel')
const testAddTagsCh = channel('dd-trace:ci:manual:test:addTags')
// ... code for your testing framework goes here
test('can sum', () => {
testAddTagsCh.publish({ 'test.owner': 'my-team', 'number.assertions': 3 })
const result = sum(2, 1)
assert.equal(result, 3)
})
// code for your testing framework continues here ...
The payload to be published is a dictionary <string, string|number>
of tags or measures that are added to the test.
When the test start and end channels are in your code, run your testing framework like you normally do, including the following environment variables:
NODE_OPTIONS="-r dd-trace/ci/init" DD_ENV=ci DD_SERVICE=my-custom-framework-tests yarn run-my-test-framework
Browser tests executed with mocha
, jest
, cucumber
, cypress
, playwright
, and vitest
are instrumented by dd-trace-js
, but visibility into the browser session itself is not provided by default (for example, network calls, user actions, page loads, and more.).
If you want visibility into the browser process, consider using RUM & Session Replay. When using Cypress, test results and their generated RUM browser sessions and session replays are automatically linked. For more information, see the Instrumenting your browser tests with RUM guide.
Cypress interactive mode (which you can enter by running cypress open
) is not supported by Test Optimization because some cypress events, such as before:run
, are not fired. If you want to try it anyway, pass experimentalInteractiveRunEvents: true
to the cypress configuration file.
test.concurrent
Jest’s test.concurrent is not supported.
--forceExit
Jest’s –forceExit option may cause data loss. Datadog tries to send data immediately after your tests finish, but shutting down the process abruptly can cause some requests to fail. Use --forceExit
with caution.
--exit
Mocha’s –exit option may cause data loss. Datadog tries to send data immediately after your tests finish, but shutting down the process abruptly can cause some requests to fail. Use --exit
with caution.
Follow these practices to take full advantage of the testing framework and Test Optimization.
Whenever possible, leverage the tools that testing frameworks provide for parameterized tests. For example, for jest
:
Avoid this:
[[1,2,3], [3,4,7]].forEach((a,b,expected) => {
test('sums correctly', () => {
expect(a+b).toEqual(expected)
})
})
And use test.each
instead:
test.each([[1,2,3], [3,4,7]])('sums correctly %i and %i', (a,b,expected) => {
expect(a+b).toEqual(expected)
})
For mocha
, use mocha-each
:
const forEach = require('mocha-each');
forEach([
[1,2,3],
[3,4,7]
])
.it('adds %i and %i then returns %i', (a,b,expected) => {
expect(a+b).to.equal(expected)
});
When you use this approach, both the testing framework and Test Optimization can tell your tests apart.