You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[test optimization] [SDTEST-996] Add instructions for test session name (#26807)
* add test session name instructions
* troubleshooting nad better examples
* Apply suggestions from code review
Co-authored-by: Brett Blue <[email protected]>
---------
Co-authored-by: Brett Blue <[email protected]>
Copy file name to clipboardExpand all lines: content/en/tests/setup/javascript.md
+48-15
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ Supported test frameworks:
33
33
| Test Framework | Version | Notes |
34
34
|---|---|---|
35
35
| 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.<br><br>Only [`jest-circus`][1] is supported as [`testRunner`][2].<br><br>[`test.concurrent`](#jests-testconcurrent) is not supported. |
@@ -79,10 +79,10 @@ For more information, see the [JavaScript Tracer installation documentation][4].
79
79
80
80
{{< tabs >}}
81
81
{{% tab "Jest/Mocha" %}}
82
-
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:
82
+
Set the `NODE_OPTIONS` environment variable to `-r dd-trace/ci/init`. Run your tests as you normally would, optionally specifying a name for your test session with `DD_TEST_SESSION_NAME`:
83
83
84
84
```bash
85
-
NODE_OPTIONS="-r dd-trace/ci/init"DD_ENV=ci DD_SERVICE=my-javascript-app yarn test
85
+
NODE_OPTIONS="-r dd-trace/ci/init"DD_TEST_SESSION_NAME=unit-tests yarn test
86
86
```
87
87
88
88
**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:
@@ -137,10 +137,10 @@ For more information about custom measures, see the [Add Custom Measures Guide][
137
137
{{% /tab %}}
138
138
139
139
{{% tab "Playwright" %}}
140
-
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:
140
+
Set the `NODE_OPTIONS` environment variable to `-r dd-trace/ci/init`. Run your tests as you normally would, optionally specifying a name for your test session with `DD_TEST_SESSION_NAME`:
141
141
142
142
```bash
143
-
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:
@@ -220,10 +220,9 @@ The format of the annotations is the following, where `$TAG_NAME` is a *string*
220
220
{{% /tab %}}
221
221
222
222
{{% tab "Cucumber" %}}
223
-
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:
224
-
223
+
Set the `NODE_OPTIONS` environment variable to `-r dd-trace/ci/init`. Run your tests as you normally would, optionally specifying a name for your test session with `DD_TEST_SESSION_NAME`:
225
224
```bash
226
-
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:
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:
422
+
Run your tests as you normally would, optionally specifying a name for your test session with `DD_TEST_SESSION_NAME`:
424
423
425
424
{{< code-block lang="shell" >}}
426
-
DD_ENV=ci DD_SERVICE=my-ui-app npm test
425
+
DD_TEST_SESSION_NAME=ui-tests yarn test:ui
427
426
{{< /code-block >}}
428
427
429
428
@@ -493,10 +492,10 @@ If the browser application being tested is instrumented using [Browser Monitorin
493
492
494
493
`vitest` and `dd-trace` require Node.js>=18.19 or Node.js>=20.6 to work.
495
494
496
-
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:
495
+
Set the `NODE_OPTIONS` environment variable to `--import dd-trace/register.js -r dd-trace/ci/init`. Run your tests as you normally would, optionally specifying a name for your test session with `DD_TEST_SESSION_NAME`:
497
496
498
497
```bash
499
-
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:
@@ -533,6 +532,7 @@ jobs:
533
532
my-job:
534
533
name: Run tests
535
534
runs-on: ubuntu-latest
535
+
# Invalid NODE_OPTIONS
536
536
env:
537
537
NODE_OPTIONS: -r dd-trace/ci/init
538
538
steps:
@@ -599,6 +599,12 @@ For more information, see [Code Coverage][6].
599
599
600
600
The following is a list of the most important configuration settings that can be used with the tracer.
601
601
602
+
`test_session.name`
603
+
: Use it to identify a group of tests, such as `integration-tests`, `unit-tests` or `smoke-tests`.<br/>
When you use this approach, both the testing framework and Test Optimization can tell your tests apart.
797
803
804
+
### Test session name `DD_TEST_SESSION_NAME`
805
+
806
+
Use `DD_TEST_SESSION_NAME` to define the test session name for your tests (`test_session.name` tag). Use this to identify a group of tests. Examples of values for this tag would be:
807
+
808
+
- `unit-tests`
809
+
- `integration-tests`
810
+
- `smoke-tests`
811
+
- `flaky-tests`
812
+
- `ui-tests`
813
+
- `backend-tests`
814
+
815
+
If `DD_TEST_SESSION_NAME` is not specified, the default value used is a combination of:
816
+
817
+
- CI job name
818
+
- Command used to run the tests (such as `yarn test`)
819
+
820
+
The test session name should be unique within a repository to help you distinguish different groups of tests.
821
+
822
+
#### When to use `DD_TEST_SESSION_NAME`
823
+
824
+
If your tests are run with commands that include a dynamic string, such as:
825
+
826
+
- `yarn test --temp-dir=/var/folders/t1/rs2htfh55mz9px2j4prmpg_c0000gq/T`
Copy file name to clipboardExpand all lines: content/en/tests/troubleshooting/_index.md
+18
Original file line number
Diff line number
Diff line change
@@ -153,6 +153,24 @@ It is likely that the [test case configuration][13] is unstable because one or m
153
153
154
154
The best way to fix this is to make sure that the test parameters are the same between test runs.
155
155
156
+
## Session history, performance or code coverage tab only show a single execution
157
+
158
+
This is likely caused by an unstable test session fingerprint. The default value for the test session fingerprint includes the test command, so an unstable test command might cause the test session fingerprint to be unstable. Some examples of unstable test commands include:
159
+
160
+
-`yarn test --temp-dir=/var/folders/t1/rs2htfh55mz9px2j4prmpg_c0000gq/T`
161
+
-`mvn test --temp-dir=/var/folders/t1/rs2htfh55mz9px2j4prmpg_c0000gq/T`
-`dotnet test --results-directory /var/folders/t1/rs2htfh55mz9px2j4prmpg_c0000gq/T`
164
+
165
+
This can be solved by using the `DD_TEST_SESSION_NAME` environment variable. Use `DD_TEST_SESSION_NAME` to identify a group of tests. Example values for this tag include:
0 commit comments