Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
# <img height="25" src="logos/test_visibility_logo.png" /> Datadog Test Visibility GitLab Script
# <img height="25" src="logos/test_visibility_logo.png" /> Datadog Test Optimization GitLab Script

Bash script that installs and configures [Datadog Test Visibility](https://docs.datadoghq.com/tests/) for GitLab.
Supported languages are .NET, Java, Javascript, and Python.
Bash script that installs and configures [Datadog Test Optimization](https://docs.datadoghq.com/tests/) for GitLab.
Supported languages are .NET, Java, Javascript, Python, and Ruby.

## About Datadog Test Visibility
## About Datadog Test Optimization

[Test Visibility](https://docs.datadoghq.com/tests/) provides a test-first view into your CI health by displaying important metrics and results from your tests.
[Test Optimization](https://docs.datadoghq.com/tests/) provides a test-first view into your CI health by displaying important metrics and results from your tests.
It can help you investigate and mitigate performance problems and test failures that are most relevant to your work, focusing on the code you are responsible for, rather than the pipelines which run your tests.

## Usage

Execute this script in your GitLab CI's job YAML before running the tests. Pass the languages, api key and [site](https://docs.datadoghq.com/getting_started/site/) environment variables:

```yaml
test_node:
```yaml
test_node:
image: node:latest
script:
- LANGUAGES="js" SITE="datadoghq.com" API_KEY="YOUR_API_KEY_SECRET" source <(curl -Ls https://github.com/DataDog/test-visibility-gitlab-script/releases/download/v1.0.1/script.sh)
- npm run test
```
- LANGUAGES="js" SITE="datadoghq.com" API_KEY="YOUR_API_KEY_SECRET" source <(curl -Ls https://github.com/DataDog/test-visibility-gitlab-script/releases/download/v1.0.1/script.sh)
- npm run test
```

## Configuration

The script takes in the following environment variables:

| Name | Description | Required | Default |
| ---- | ----------- | -------- | ------- |
| LANGUAGES | List of languages to be instrumented. Can be either "all" or any of "java", "js", "python", "dotnet" (multiple languages can be specified as a space-separated list). | true | |
| API_KEY | Datadog API key. Can be found at https://app.datadoghq.com/organization-settings/api-keys | true | |
| SITE | Datadog site. See https://docs.datadoghq.com/getting_started/site for more information about sites. | false | datadoghq.com |
| SERVICE | The name of the service or library being tested. | false | |
| DOTNET_TRACER_VERSION | The version of Datadog .NET tracer to use. Defaults to the latest release. | false | |
| JAVA_TRACER_VERSION | The version of Datadog Java tracer to use. Defaults to the latest release. | false | |
| JS_TRACER_VERSION | The version of Datadog JS tracer to use. Defaults to the latest release. | false | |
| PYTHON_TRACER_VERSION | The version of Datadog Python tracer to use. Defaults to the latest release. | false | |
| JAVA_INSTRUMENTED_BUILD_SYSTEM | If provided, only the specified build systems will be instrumented (allowed values are `gradle`,`maven`,`sbt`,`ant`,`all`). `all` is a special value that instruments every Java process. If this property is not provided, all known build systems will be instrumented (Gradle, Maven, SBT, Ant). | false | |
| Name | Description | Required | Default |
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------- |
| LANGUAGES | List of languages to be instrumented. Can be either "all" or any of "java", "js", "python", "dotnet", "ruby" (multiple languages can be specified as a space-separated list). | true | |
| API_KEY | Datadog API key. Can be found at https://app.datadoghq.com/organization-settings/api-keys | true | |
| SITE | Datadog site. See https://docs.datadoghq.com/getting_started/site for more information about sites. | false | datadoghq.com |
| SERVICE | The name of the service or library being tested. | false | |
| DOTNET_TRACER_VERSION | The version of Datadog .NET tracer to use. Defaults to the latest release. | false | |
| JAVA_TRACER_VERSION | The version of Datadog Java tracer to use. Defaults to the latest release. | false | |
| JS_TRACER_VERSION | The version of Datadog JS tracer to use. Defaults to the latest release. | false | |
| PYTHON_TRACER_VERSION | The version of Datadog Python tracer to use. Defaults to the latest release. | false | |
| RUBY_TRACER_VERSION | The version of datadog-ci gem to use. Defaults to the latest release. | false | |
| JAVA_INSTRUMENTED_BUILD_SYSTEM | If provided, only the specified build systems will be instrumented (allowed values are `gradle`,`maven`,`sbt`,`ant`,`all`). `all` is a special value that instruments every Java process. If this property is not provided, all known build systems will be instrumented (Gradle, Maven, SBT, Ant). | false | |

### Additional configuration

Any [additional configuration values](https://docs.datadoghq.com/tracing/trace_collection/library_config/) can be added directly to the job that runs your tests:

```yaml
test_node:
test_node:
image: node:latest
script:
- export DD_API_KEY="YOUR_API_KEY_SECRET"
- export DD_ENV="staging-tests"
- export DD_TAGS="layer:api,team:intake,key:value"
- LANGUAGES="js" SITE="datad0g.com" source <(curl -Ls https://github.com/DataDog/test-visibility-gitlab-script/releases/download/v1.0.1/script.sh)
- npm run test
- export DD_API_KEY="YOUR_API_KEY_SECRET"
- export DD_ENV="staging-tests"
- export DD_TAGS="layer:api,team:intake,key:value"
- LANGUAGES="js" SITE="datad0g.com" source <(curl -Ls https://github.com/DataDog/test-visibility-gitlab-script/releases/download/v1.0.1/script.sh)
- npm run test
```

## Limitations
Expand All @@ -59,17 +60,17 @@ Any [additional configuration values](https://docs.datadoghq.com/tracing/trace_c

To use this script with vitest you need to modify the NODE_OPTIONS environment variable adding the `--import` flag with the value of the `DD_TRACE_ESM_IMPORT` environment variable.

```yaml
test_node_vitest:
```yaml
test_node_vitest:
image: node:latest
script:
- LANGUAGES="js" SITE="datadoghq.com" API_KEY="YOUR_API_KEY_SECRET" source <(curl -Ls https://github.com/DataDog/test-visibility-gitlab-script/releases/download/v1.0.1/script.sh)
- export NODE_OPTIONS="$NODE_OPTIONS --import $DD_TRACE_ESM_IMPORT"
- npm run test
```
- LANGUAGES="js" SITE="datadoghq.com" API_KEY="YOUR_API_KEY_SECRET" source <(curl -Ls https://github.com/DataDog/test-visibility-gitlab-script/releases/download/v1.0.1/script.sh)
- export NODE_OPTIONS="$NODE_OPTIONS --import $DD_TRACE_ESM_IMPORT"
- npm run test
```

**Important**: `vitest` and `dd-trace` require Node.js>=18.19 or Node.js>=20.6 to work together.

### Tracing cypress tests

To instrument your [Cypress](https://www.cypress.io/) tests with Datadog Test Visibility, please follow the manual steps in the [docs](https://docs.datadoghq.com/tests/setup/javascript/?tab=cypress).
To instrument your [Cypress](https://www.cypress.io/) tests with Datadog Test Optimization, please follow the manual steps in the [docs](https://docs.datadoghq.com/tests/setup/javascript/?tab=cypress).
12 changes: 10 additions & 2 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ if [ -n "$PYTHON_TRACER_VERSION" ]; then
export DD_SET_TRACER_VERSION_PYTHON=${PYTHON_TRACER_VERSION}
fi

# $RUBY_TRACER_VERSION or $DD_SET_TRACER_VERSION_RUBY are optional
if [ -n "$RUBY_TRACER_VERSION" ]; then
export DD_SET_TRACER_VERSION_RUBY=${RUBY_TRACER_VERSION}
fi

# $JAVA_INSTRUMENTED_BUILD_SYSTEM or $DD_INSTRUMENTATION_BUILD_SYSTEM_JAVA are optional
if [ -n "$JAVA_INSTRUMENTED_BUILD_SYSTEM" ]; then
export DD_INSTRUMENTATION_BUILD_SYSTEM_JAVA=${JAVA_INSTRUMENTED_BUILD_SYSTEM}
fi

export DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER="gitlab"

installation_script_url="https://install.datadoghq.com/scripts/install_test_visibility_v4.sh"
installation_script_checksum="41c0df6833bd371cbebf38767cf358c94a3fd1547056281e3ae9cade53fb39e2"
installation_script_url="https://install.datadoghq.com/scripts/install_test_visibility_v5.sh"
installation_script_checksum="903f1146fe123a1f7c6accdc48411546eead172f2d577fb41876d29b537eb7d6"
script_filepath="install_test_visibility.sh"

if command -v curl >/dev/null 2>&1; then
Expand Down Expand Up @@ -101,4 +106,7 @@ fi
if [ ! -z "$DD_TRACER_VERSION_PYTHON" ]; then
echo "- __Python:__ $DD_TRACER_VERSION_PYTHON"
fi
if [ ! -z "$DD_TRACER_VERSION_RUBY" ]; then
echo "- __Ruby:__ $DD_TRACER_VERSION_RUBY"
fi
echo "---"