Auto-instrumentation runs on the CI executor and does not automatically apply to tests in a separate container. Before using it for containerized tests, see Tests in Containers.
If the auto-instrumentation step configures the process that runs your tests, you can skip the rest of the setup steps below.
If you are using a cloud CI provider without access to the underlying worker nodes, such as GitHub Actions or CircleCI, configure the library to use the Agentless mode. For this, set the following environment variables:
Set these variables before starting the test process. For parallel test runners, set them on the parent process so every worker inherits them.
DD_CIVISIBILITY_AGENTLESS_ENABLED=true selects Agentless mode. DD_API_KEY provides authentication but does not enable Agentless mode.
DD_CIVISIBILITY_AGENTLESS_ENABLED=true (Required for Agentless mode)
Enables Agentless mode to send test results directly to Datadog. Default: false
DD_API_KEY (Required for Agentless mode)
The Datadog API key used to authenticate test result uploads. Default: (empty)
If you use a Datadog site other than US1, set the following variable:
DD_SITE (Optional for Agentless mode)
The Datadog site to upload results to. Default: datadoghq.com
If you are running tests on an on-premises CI provider, such as Jenkins or self-managed GitLab CI, install the Datadog Agent on each worker node by following the Agent installation instructions.
This is the recommended option as it allows you to automatically link test results to logs and underlying host metrics.
If you are using a Kubernetes executor, Datadog recommends using the Datadog Operator.
The operator includes Datadog Admission Controller which can automatically inject the tracer library into the build pods.
Note: If you use the Datadog Operator, there is no need to download and inject the tracer library since the Admission Controller can do this for you, so you can skip the corresponding step below.
However, you still need to make sure that your pods set the environment variables or command-line parameters necessary to enable Test Visibility.
If you are not using Kubernetes or can’t use the Datadog Admission Controller and the CI provider is using a container-based executor, set the DD_TRACE_AGENT_URL environment variable (which defaults to http://localhost:8126) in the build container running the tracer to an endpoint that is accessible from within that container. Note: Using localhost inside the build references the container itself and not the underlying worker node or any container where the Agent might be running in.
DD_TRACE_AGENT_URL includes the protocol and port (for example, http://localhost:8126) and takes precedence over DD_AGENT_HOST and DD_TRACE_AGENT_PORT, and is the recommended configuration parameter to configure the Datadog Agent’s URL for CI Visibility.
If you still have issues connecting to the Datadog Agent, use the Agentless Mode.
Note: When using this method, tests are not correlated with logs and infrastructure metrics.
수동 계측
이 섹션은 CI 공급자가 자동 계측을 지원하지 않는 경우에만 필요합니다. 위의 보고 메서드 설정 섹션에서 자동 계측을 지원하는 CI 공급자를 선택했다면, 이 섹션을 건너뛰고 구성 설정으로 진행하세요.
CI 공급자가 자동 계측을 지원하지 않는 경우(예: Cloud CI provider (Agentless) 또는 On-Premises CI Provider (Datadog Agent)를 선택한 경우), 다음 단계에 따라 라이브러리를 설치하고 테스트를 수동으로 계측하세요.
RUBYOPT="-rbundler/setup -rdatadog/ci/auto_instrument" bundle exec rake test
참고: RUBYOPT 환경 변수를 설정하지 않으려면 테스트 명령 앞에 bundle exec ddcirb exec를 추가하세요.
bundle exec ddcirb exec rake test
구성 설정
Test Optimization 라이브러리를 설정하려면 테스트 프로세스를 시작하기 전에 다음 환경 변수를 설정하세요. 병렬 테스트 실행기의 경우, 모든 작업자가 상속받을 수 있도록 상위 프로세스에서 설정하세요.
DD_CIVISIBILITY_ENABLED=true (필수)
Test Optimization을 활성화합니다. 기본: false
DD_ENV(선택 사항)
테스트가 실행되는 환경의 이름입니다. 기본: (empty) 예시: local, ci
DD_SERVICE(선택 사항)
테스트 중인 서비스 또는 라이브러리의 이름입니다. 기본값: 리포지토리 이름 예시: my-ruby-app
DD_CIVISIBILITY_AGENTLESS_ENABLED=true(Agentless 모드 사용 시 필수)
테스트 결과를 Datadog으로 직접 전송하기 위해 Agentless 모드를 활성화합니다. 기본값: false
DD_API_KEY(Agentless 모드 사용 시 필수)
테스트 결과 업로드를 인증하는 데 사용되는 Datadog API 키입니다. 이 변수는 Agentless 모드를 활성화하지 않습니다. 기본값: (empty)
DD_SITE(Agentless 모드 사용 시 선택 사항)
테스트 결과를 업로드할 Datadog 사이트입니다. US1 이외의 사이트를 사용할 때 이 구성을 설정하세요. 기본값: datadoghq.com
DD_TRACE_AGENT_URL(Datadog Agent를 사용할 때만)
http://hostname:port 형식의 트레이스 수집용 Datadog Agent URL입니다. 기본값: http://127.0.0.1:8126
DD_TEST_SESSION_NAME(선택 사항)
unit-tests, integration-tests 또는 smoke-tests와 같은 테스트 그룹을 식별합니다. 기본값: CI 작업 이름 및 테스트 명령, 또는 CI 작업 이름을 사용할 수 없는 경우 테스트 명령입니다. 예: unit-tests, integration-tests, smoke-tests
Datadog uses Git information for visualizing your test results and grouping them by repository, branch, and commit. Git metadata is automatically collected by the test instrumentation from CI provider environment variables and the local .git folder in the project path, if available.
If you are running tests in non-supported CI providers or with no .git folder, you can set the Git information manually using environment variables. These environment variables take precedence over any auto-detected information. Set the following environment variables to provide Git information:
DD_GIT_REPOSITORY_URL
URL of the repository where the code is stored. Both HTTP and SSH URLs are supported. Example: git@github.com:MyCompany/MyApp.git, https://github.com/MyCompany/MyApp.git
DD_GIT_BRANCH
Git branch being tested. Leave empty if providing tag information instead. Example: develop
DD_GIT_TAG
Git tag being tested (if applicable). Leave empty if providing branch information instead. Example: 1.0.1
DD_GIT_COMMIT_SHA
Full commit hash. Example: a18ebf361cc831f5535e58ec4fae04ffd98d8152
DD_GIT_COMMIT_MESSAGE
Commit message. Example: Set release number
DD_GIT_COMMIT_AUTHOR_NAME
Commit author name. Example: John Smith
DD_GIT_COMMIT_AUTHOR_EMAIL
Commit author email. Example: john@example.com
DD_GIT_COMMIT_AUTHOR_DATE
Commit author date in ISO 8601 format. Example: 2021-03-12T16:00:28Z
DD_GIT_COMMIT_COMMITTER_NAME
Commit committer name. Example: Jane Smith
DD_GIT_COMMIT_COMMITTER_EMAIL
Commit committer email. Example: jane@example.com
DD_GIT_COMMIT_COMMITTER_DATE
Commit committer date in ISO 8601 format. Example: 2021-03-12T16:00:28Z
지원되지 않는 테스트 프레임워크에 라이브러리의 공개 API 사용
RSpec, Minitest 또는 Cucumber를 사용하는 경우 수동 테스트 API를 사용하지 마세요. Test Optimization이 자동으로 이를 계측하고 테스트 결과를 Datadog으로 전송하기 때문입니다. 수동 테스트 API는 이미 지원되는 테스트 프레임워크와는 호환되지 않습니다.
지원되지 않는 테스팅 프레임워크를 사용하거나 다른 테스팅 메커니즘이 있는 경우에만 수동 테스팅 API를 사용하세요.
전체 공개 API 문서는 YARD 사이트에서 확인할 수 있습니다.
도메인 모델
API는 테스트 세션, 테스트 모듈, 테스트 스위트 및 테스트란 네 개의 개념을 기반으로 합니다.
테스트 세션
테스트 세션은 테스트 명령 실행을 나타냅니다.
테스트 세션을 시작하려면 Datadog::CI.start_test_session을(를) 호출하고 Datadog 서비스와 태그(예: 사용 중인 테스트 프레임워크
등)를 전달하세요.
DD_TEST_SESSION_NAME을 사용하여 테스트 세션의 이름과 관련 테스트 그룹을 정의하세요. 이 태그에 대한 값의 예시는 다음과 같습니다.
unit-tests
integration-tests
smoke-tests
flaky-tests
ui-tests
backend-tests
DD_TEST_SESSION_NAME이 지정되지 않은 경우, 기본값은 CI 작업 이름과 테스트 명령입니다. CI 작업 이름을 사용할 수 없는 경우 테스트 명령이 사용됩니다.
서로 다른 테스트 그룹을 구분하는 데 도움이 되도록 테스트 세션 이름은 리포지토리 내에서 고유해야 합니다.
DD_TEST_SESSION_NAME 사용 시점
Datadog은 테스트 세션 간의 대응 관계를 설정하기 위해 일련의 파라미터를 검사합니다. 테스트를 실행하는 데 사용된 테스트 명령이 그중 하나입니다. 테스트 명령에 실행할 파일 목록과 같이 실행할 때마다 변경되는 문자열이 포함되어 있는 경우, Datadog은 해당 세션들이 서로 관련이 없는 것으로 간주합니다. 예:
bundle exec rspec my_spec.rb my_other_spec.rb
테스트 명령이 실행마다 달라지는 경우 Datadog은 DD_TEST_SESSION_NAME 사용을 권장합니다.