Este producto no es compatible con el sitio Datadog seleccionado. ().

Compatibilidad

Marcos para tests compatibles:

  • Paquete de testing

Configuración del método de notificación

Para informar de los resultados de test a Datadog, debes configurar la biblioteca de Go Datadog:

We support auto-instrumentation for the following CI providers:

CI ProviderAuto-Instrumentation method
GitHub ActionsDatadog Test Visibility Github Action
JenkinsUI-based configuration with Datadog Jenkins plugin
GitLabDatadog Test Visibility GitLab Script
CircleCIDatadog Test Visibility CircleCI Orb

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.

Instalación de Orchestrion

Orchestrion es una herramienta para procesar código fuente de Go en tiempo de compilación e insertar automáticamente instrumentación mediante dd-trace-go.

Instala orchestrion desde https://github.com/datadog/orchestrion con el comando:

$ go install github.com/DataDog/orchestrion@latest
  • Optional: project go.mod registration

    You can automatically add orchestrion to your project’s dependencies by running:

    $ orchestrion pin
    

    This command has the following effects:

    1. 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"
      
    2. Run go get github.com/DataDog/orchstrion@<current-release> to make sure the project version corresponds to the one currently being used
    3. 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 es compatible con las dos versiones más recientes de Go, que coinciden con la política oficial de versiones de Go. Puede funcionar correctamente con versiones anteriores de Go, pero Datadog no puede dar soporte a versiones anteriores que no funcionen.

Además, Orchestrion solo admite proyectos que utilicen módulos de Go.

Instrumentación de tests

Establece las siguientes variables de entorno para configurar la biblioteca:

DD_CIVISIBILITY_ENABLED=true (Obligatorio)
Activa el producto Test Optimization.
DD_ENV (Obligatorio)
entorno donde se ejecutan los tests (por ejemplo: local cuando se ejecutan tests en una estación de trabajo de desarrollador o ci cuando se ejecutan en un proveedor de CI).

Prefija tu comando de test de go con orchestrion:

$ orchestrion go test -race ./...

Si no has ejecutado orchestrion pin, es posible que aparezca un mensaje similar al siguiente, ya que orchestrion pin se ejecuta automáticamente:

  ╭──────────────────────────────────────────────────────────────────────────────╮
                                                                                
    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.    
                                                                                
  ╰──────────────────────────────────────────────────────────────────────────────╯

Alternativa

Orchestrion en el núcleo es un proxy estándar de la cadena de herramientas de Go -toolexec. En lugar de utilizar orchestrion go, también puedes proporcionar manualmente el argumento -toolexec a los comandos go que lo acepten:

$ go build -toolexec 'orchestrion toolexec' .
$ go test -toolexec 'orchestrion toolexec' -race .

Referencias adicionales