Setup Tracing on a GitLab Pipeline

Setup Tracing on a GitLab Pipeline

To enable traces for your GitLab CI pipelines a native integration is available and hidden under a feature flag since release 13.7.0.

If you are a GitLab.com user and you want to early-adopt this integration, open a support ticket with GitLab requesting that the Datadog integration be enabled in your account.

If you manage your own GitLab installation and your version is recent enough, you can enable the feature flag yourself by executing the following commands that use GitLab’s Rails Runner depending on your installation type:

For Omnibus installations:

sudo gitlab-rails runner "Feature.enable(:datadog_ci_integration)"

For installations from source:

sudo -u git -H bundle exec rails runner -e production "Feature.enable(:datadog_ci_integration)"

For Kubernetes deployments:

kubectl exec -it <task-runner-pod-name> -- /srv/gitlab/bin/rails runner "Feature.enable(:datadog_ci_integration)"

Once the feature flag is enabled, configure the integration on a per project basis by going to Settings > Integrations > Datadog for each project you want to instrument. Mark it as active and paste a valid API key.

Note: Only datadoghq.com is currently supported.

There are a couple of optional parameters:

  • service: Sets the service name for all traces for this GitLab instance. Defaults to gitlab-ci. Useful if you’re using more than one GitLab instance.
  • env: Sets the environment tag for all traces for this GitLab instance. Useful in advanced setups where grouping GitLab instances per environment is required.

Test the integration with the Test settings button. After it’s successful, click Save changes to finish the integration set up.

Integrating through webhooks

As an alternative to using the native Datadog integration, you can use webhooks to send pipeline data to Datadog.

Note: The native Datadog integration is the recommended approach and the one that is actively under development. Use webhooks only if the native Datadog integration option is not available to you (for example, you have an older GitLab version and you’re not able to upgrade).

Go to Settings > Webhooks in your repository (or GitLab instance settings), and add a new webhook:

  • URL: https://webhooks-http-intake.logs.datadoghq.com/v1/input/<API_KEY> where <API_KEY> is available here.
  • Secret Token: leave blank
  • Trigger: Select Job events and Pipeline events.

To set custom env or service parameters, use query parameters in the webhooks URL: ?env=<YOUR_ENV>&service=<YOUR_SERVICE_NAME>

Visualize pipeline data in Datadog

After the integration is successfully configured, both Pipelines and Pipeline Executions pages will start populating with data after pipelines finish.

Note: The Pipelines page shows data for only the default branch of each repository.

Further reading