This product is not supported for your selected
Datadog site. (
).
互換性
サポートされているテストフレームワーク:
レポート方法の設定
テスト結果を Datadog に送信するには、Datadog Go ライブラリを設定する必要があります:
We support auto-instrumentation for the following CI providers:
If you are using auto-instrumentation for one of these providers, 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:
DD_CIVISIBILITY_AGENTLESS_ENABLED=true (Required)- Enables or disables Agentless mode.
Default: false DD_API_KEY (Required)- The Datadog API key used to upload the test results.
Default: (empty)
Additionally, configure the Datadog site to which you want to send data.
DD_SITE (Required)- 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.
Orchestrion のインストール
Orchestrion は、コンパイル時に Go のソース コードを処理し、dd-trace-go を使ってインスツルメンテーションを自動挿入するツールです。
次のコマンドを使用して、https://github.com/datadog/orchestrion から orchestrion をインストールします:
$ go install github.com/DataDog/orchestrion@latest
Optional: project go.mod registration
You can automatically add orchestrion to your project’s dependencies by running:
This command has the following effects:
- Create a new
orchestrion.tool.go file containing content similar to:// Code generated by `orchestrion pin`; DO NOT EDIT.
// This file is generated by `orchestrion pin`, and is used to include a blank import of the
// orchestrion package(s) so that `go mod tidy` does not remove the requirements rom go.mod.
// This file should be checked into source control.
//go:build tools
package tools
import _ "github.com/DataDog/orchestrion"
- Run
go get github.com/DataDog/orchstrion@<current-release> to make sure the project version corresponds to the
one currently being used - Run
go mod tidy to make sure your go.mod and go.sum files are up-to-date
If you do not run this command, it is done automatically when required. Once done, the version of orchestrion
used by this project can be controlled directly using the go.mod file, as you would control any other dependency.
Orchestrion は Go の 公式リリース ポリシー に合わせて、最新 2 世代の Go リリースをサポートします。古い Go リリースでも正しく動作する可能性はありますが、動作しない古いリリースについて Datadog はサポートできません。
これに加えて、Orchestrion は Go モジュール を使用しているプロジェクトのみをサポートします。
テストのインスツルメンテーション
ライブラリを設定するため、次の環境変数を設定します:
DD_CIVISIBILITY_ENABLED=true (必須)- Test Optimization 製品を有効化します。
DD_ENV (必須)- テストを実行している環境 (例: 開発者のワークステーションで実行する場合は
local、CI プロバイダー上で実行する場合は ci)。
go test コマンドの先頭に orchestrion を付けて実行します:
$ orchestrion go test -race ./...
orchestrion pin をまだ実行していない場合、orchestrion pin が自動実行されるため、次のようなメッセージが表示されることがあります:
╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ Warning: github.com/DataDog/orchestrion is not present in your go.mod │
│ file. │
│ In order to ensure build reliability and reproductibility, orchestrion │
│ will now add itself in your go.mod file by: │
│ │
│ 1. creating a new file named orchestrion.tool.go │
│ 2. running go get github.com/DataDog/orchestrion@v0.9.4 │
│ 3. running go mod tidy │
│ │
│ You should commit the resulting changes into your source control system. │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯
代替手段
Orchestrion は本質的に、標準の Go ツールチェーンの -toolexec プロキシです。orchestrion go を使う代わりに、go 側で -toolexec 引数を受け付けるコマンドであれば、手動で -toolexec 引数を指定することもできます:
$ go build -toolexec 'orchestrion toolexec' .
$ go test -toolexec 'orchestrion toolexec' -race .
参考資料