- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
Supported languages:
Language | Version |
---|---|
Ruby | >= 2.7 |
JRuby | >= 9.4 |
Supported test frameworks:
Test Framework | Version |
---|---|
RSpec | >= 3.0.0 |
Minitest | >= 5.0.0 |
Cucumber | >= 3.0 |
Supported test runners:
Test runner | Version |
---|---|
Knapsack Pro | >= 7.2.0 |
ci-queue | >= 0.53.0 |
To report test results to Datadog, you need to configure the datadog-ci
gem:
GitHub Actions나 CircleCI와 같이 기본 작업자 노드에 액세스하지 않고 클라우드 CI 공급자를 사용할 경우, 라이브러리를 구성해 에이전트리스 모드로 사용하세요. 이 모드를 이용하려면 다음 환경 변수를 설정하세요.
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 Ruby test optimization library:
datadog-ci
gem to your Gemfile
:Gemfile
source "<https://rubygems.org>"
gem "datadog-ci", "~> 1.0", group: :test
bundle install
The RSpec integration traces all executions of example groups and examples when using the rspec
test framework.
To activate your integration, add this to the spec_helper.rb
file:
require "rspec"
require "datadog/ci"
# Only activates test instrumentation on CI
if ENV["DD_ENV"] == "ci"
Datadog.configure do |c|
# enables test optimization
c.ci.enabled = true
# The name of the service or library under test
c.service = "my-ruby-app"
# Enables the RSpec instrumentation
c.ci.instrument :rspec
end
end
Run your tests as you normally do, specifying the environment where tests are being run in the DD_ENV
environment variable.
You could use the following environments:
local
when running tests on a developer workstationci
when running them on a CI providerFor example:
DD_ENV=ci bundle exec rake spec
The Minitest integration traces all executions of tests when using the minitest
framework.
To activate your integration, add this to the test_helper.rb
file:
require "minitest"
require "datadog/ci"
# Only activates test instrumentation on CI
if ENV["DD_ENV"] == "ci"
Datadog.configure do |c|
# enables test optimization
c.ci.enabled = true
# The name of the service or library under test
c.service = "my-ruby-app"
c.ci.instrument :minitest
end
end
Run your tests as you normally do, specifying the environment where tests are being run in the DD_ENV
environment variable.
You could use the following environments:
local
when running tests on a developer workstationci
when running them on a CI providerFor example:
DD_ENV=ci bundle exec rake test
Example configuration with minitest/autorun
:
require "datadog/ci"
require "minitest/autorun"
if ENV["DD_ENV"] == "ci"
Datadog.configure do |c|
c.ci.enabled = true
c.service = "my-ruby-app"
c.ci.instrument :minitest
end
end
The Cucumber integration traces executions of scenarios and steps when using the cucumber
framework.
To activate your integration, add the following code to your application:
require "cucumber"
require "datadog/ci"
# Only activates test instrumentation on CI
if ENV["DD_ENV"] == "ci"
Datadog.configure do |c|
# enables test optimization
c.ci.enabled = true
# The name of the service or library under test
c.service = "my-ruby-app"
# Enables the Cucumber instrumentation
c.ci.instrument :cucumber
end
end
Run your tests as you normally do, specifying the environment where tests are being run in the DD_ENV
environment variable.
You could use the following environments:
local
when running tests on a developer workstationci
when running them on a CI providerFor example:
DD_ENV=ci bundle exec rake cucumber
You can add custom tags to your tests by using the current active test:
require "datadog/ci"
# inside your test
Datadog::CI.active_test&.set_tag("test_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 Ruby custom instrumentation documentation.
Like tags, you can add custom measures to your tests by using the current active test:
require "datadog/ci"
# inside your test
Datadog::CI.active_test&.set_metric("memory_allocations", 16)
# test continues normally
# ...
For more information on custom measures, see the Add Custom Measures Guide.
The following is a list of the most important configuration settings that can be used with the test optimization library, either in code by using a Datadog.configure
block, or using environment variables:
service
DD_SERVICE
$PROGRAM_NAME
my-ruby-app
env
DD_ENV
none
local
, ci
For more information about service
and env
reserved tags, see Unified Service Tagging.
The following environment variable can be used to configure the location of the Datadog Agent:
DD_TRACE_AGENT_URL
http://hostname:port
.http://localhost:8126
All other Datadog Tracer configuration options can also be used.
It can be useful to have rich tracing information about your tests that includes time spent performing database operations or other external calls, as seen in the following flame graph:
To achieve this, configure additional instrumentation in your configure
block:
if ENV["DD_ENV"] == "ci"
Datadog.configure do |c|
# ... ci configs and instrumentation here ...
c.tracing.instrument :redis
c.tracing.instrument :pg
# ... any other instrumentations supported by datadog gem ...
end
end
Alternatively, you can enable automatic instrumentation in test_helper/spec_helper
:
require "datadog/auto_instrument" if ENV["DD_ENV"] == "ci"
Note: In CI mode, these traces are submitted to CI Visibility, and they do not show up in Datadog APM.
For the full list of available instrumentation methods, see the tracing documentation
Webmock and VCR are popular Ruby libraries that stub HTTP requests when running tests. By default, they fail when used with datadog-ci because traces are being sent to Datadog with HTTP calls.
To allow HTTP connections for Datadog backend, you need to configure Webmock and VCR accordingly.
# Webmock
# when using Agentless mode:
WebMock.disable_net_connect!(:allow => /datadoghq/)
# when using Agent running locally:
WebMock.disable_net_connect!(:allow_localhost => true)
# or for more granular setting set your Agent URL, for example:
WebMock.disable_net_connect!(:allow => "localhost:8126")
# VCR
VCR.configure do |config|
# ... your usual configuration here ...
# when using Agent
config.ignore_hosts "127.0.0.1", "localhost"
# when using Agentless mode
config.ignore_request do |request|
# ignore all requests to datadoghq hosts
request.uri =~ /datadoghq/
end
end
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
If you use RSpec, Minitest, or Cucumber, do not use the manual testing API, as CI Visibility 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. Full public API documentation is available on YARD site.
The API is based around four concepts: test session, test module, test suite, and test.
A test session represents a test command run.
To start a test session, call Datadog::CI.start_test_session
and pass the Datadog service and tags (such as the test framework
you are using).
When all your tests have finished, call Datadog::CI::TestSession#finish
, which closes the session and sends the session
trace to the backend.
A test module represents a smaller unit of work within a session. For supported test frameworks, test module is always same as test session. For your use case, this could be a package in your componentized application.
To start a test module, call Datadog::CI.start_test_module
and pass the name of the module.
When the module run has finished, call Datadog::CI::TestModule#finish
.
A test suite comprises a set of tests that test similar functionality. A single suite usually corresponds to a single file where tests are defined.
Create test suites by calling Datadog::CI#start_test_suite
and passing the name of the test suite.
Call Datadog::CI::TestSuite#finish
when all the related tests in the suite have finished their execution.
A test represents a single test case that is executed as part of a test suite. Usually it corresponds to a method that contains testing logic.
Create tests in a suite by calling Datadog::CI#start_test
or Datadog::CI.trace_test
and passing the name of the test and name of the test suite. Test suite name must be the same as name of the test suite started in previous step.
Call Datadog::CI::Test#finish
when a test has finished execution.
The following code represents example usage of the API:
require "datadog/ci"
Datadog.configure do |c|
c.service = "my-test-service"
c.ci.enabled = true
end
def run_test_suite(tests, test_suite_name)
test_suite = Datadog::CI.start_test_suite(test_suite_name)
run_tests(tests, test_suite_name)
test_suite.passed!
test_suite.finish
end
def run_tests(tests, test_suite_name)
tests.each do |test_name|
Datadog::CI.trace_test(test_name, test_suite_name) do |test|
test.passed!
end
end
end
Datadog::CI.start_test_session(
tags: {
Datadog::CI::Ext::Test::TAG_FRAMEWORK => "my-framework",
Datadog::CI::Ext::Test::TAG_FRAMEWORK_VERSION => "0.0.1",
}
)
Datadog::CI.start_test_module("my-test-module")
run_test_suite(["test1", "test2", "test3"], "test-suite-name")
Datadog::CI.active_test_module&.passed!
Datadog::CI.active_test_module&.finish
Datadog::CI.active_test_session&.passed!
Datadog::CI.active_test_session&.finish