Datadog CI CLI

repository·master·Indexed 41 days ago

https://github.com/datadog/datadog-ci

A CLI tool for Continuous Integration and Continuous Delivery pipelines to facilitate integration with Datadog. Features include uploading dSYM, ELF, PE, and Flutter symbols for symbolication and deobfuscation, uploading git commit metadata for repository linking, and adding numeric measures to CI Visibility pipeline and job spans.

Tokens
147.5K
Snippets
406
Records
588
Agent score
51%

What's inside Datadog CI

  1. Link errors to source code in Datadog

    master

    To enable direct links from Datadog errors to your source code (e.g., GitHub, GitLab, Bitbucket, Azure DevOps), the upload command must be able to associate sourcemaps with your repository.

    Requirements for automatic linking:

    1. The git executable must be installed.
    2. datadog-ci must be run within the git repository.
    3. --disable-git must not be set.

    Manual Configuration (Bypassing Git): If your build environment lacks a .git/ folder, you can still enable linking by providing:

    • --repository-url <url> (or DD_GIT_REPOSITORY_URL)
    • --commit-sha <sha> (or DD_GIT_COMMIT_SHA)

    Note: In this mode, source files are extracted directly from the sourcemap sources field, so untracked files may be sent to Datadog.

    Handling Path Prefixes: If your sourcemap references paths with a prefix before the repository root (e.g., webpack://MyProject/src/file.js), use the --project-path MyProject/ flag so files are correctly matched to the repository.

  2. How Git context resolution works for SBOM upload

    master

    The CLI resolves Git context using the following priority order:

    1. Current process location: The directory where the command is executed.
    2. CI environment variables: Automatically detected CI context (can be disabled using the --no-ci-tags flag).
    3. Explicit Git repository: The path provided via the --git-repository option.
    4. Override environment variables: Any provided DD_GIT_* environment variables.
  3. Exclude source files using `--ignored-source-paths`

    master

    The --ignored-source-paths option (or the DD_COVERAGE_IGNORED_SOURCE_PATHS environment variable) excludes specific source files from the coverage computation.

    Important Behaviors

    • Replacement, not Merging: This option replaces the ignore list defined in code-coverage.datadog.yml. If this option is not provided, the configuration file's list is used.
    • Server-side Matching: Patterns are sent verbatim to Datadog and matched server-side; they are not expanded against your local filesystem.
    • Pattern Syntax:
      • Patterns are separated by commas or newlines.
      • Use brace groups {} to protect commas from being treated as separators (e.g., **/*.{js,ts}).
      • A comma inside a character class (e.g., [a,b]) is still treated as a separator; use [ab] instead.
    • Limits: Up to 2,000 patterns and 256 KB total are accepted. If you exceed 1,000 patterns or 100 KB, the upload proceeds but prints a warning.

    Platform-specific Argument Limits

    If your list is very large, be aware of OS limits:

    • Linux: 128 KB limit for arguments/environment variables.
    • Windows: ~8,191 character limit via cmd.exe (used by npm/yarn shims).
    • macOS: No per-argument limit, but shares a budget with the environment (256 KB limit applies).
    # Exclude generated files using glob patterns
    datadog-ci coverage upload --ignored-source-paths "**/generated/**,src/gen/**" .
  4. How plugins work in datadog-ci

    master

    Starting from version 4.0, many commands were moved into specialized plugins to reduce the core package size.

    Automatic Installation

    By default, if you run a command that requires a plugin (e.g., lambda instrument), the CLI will automatically install the necessary plugin if it is not already present in your environment.

    Disabling Auto-Installation

    If you want to prevent the CLI from automatically downloading plugins, set the following environment variable: DISABLE_PLUGIN_AUTO_INSTALL=1

  5. Configure APM instrumentation with `--tracing`

    master

    The --tracing flag controls Application Performance Monitoring (APM) instrumentation.

    Available values:

    • inject: Automatically detects the application language and injects the appropriate tracer.
    • manual: Use this if your application image already includes a tracer (e.g., for Go applications using dd-trace-go).
    • disabled: Turns tracing off.
    • true/1: Alias for manual.
    • false/0: Alias for disabled.

    Note: If you omit the --tracing flag, the command preserves existing automatic instrumentation and DD_TRACE_ENABLED values, or enables tracing if no value currently exists.

    # Enable automatic APM instrumentation with language detection
    datadog-ci cloud-run instrument -p <gcp-project> -r us-central1 -s <service-name> --tracing inject
    
    # Use manual mode if the tracer is already in the image
    datadog-ci cloud-run instrument -p <gcp-project> -r us-central1 -s <service-name> --tracing manual
  6. How Git context resolution works for SARIF uploads

    master

    The CLI resolves Git context to provide environment metadata with your reports. It follows this priority order:

    1. Current process location
    2. CI environment variables (can be disabled using the --no-ci-tags flag)
    3. Explicitly provided Git repository (via the --git-repository flag)
    4. Override environment variables (using DD_GIT_* variables)
  7. How Git context and repository ID are resolved

    master

    The command automatically attempts to resolve Git context and repository identifiers to associate artifacts with your source code.

    Git context resolution priority:

    1. CI environment variables
    2. Current Git repository metadata
    3. Override environment variables (DD_GIT_* variables)

    Repository identifier (repo_id) resolution priority:

    1. --repo-id flag value
    2. DD_GIT_REPOSITORY_URL or DD_REPOSITORY_URL environment variable
    3. Git metadata from the current repository
  8. Configure Automatic APM instrumentation for Container Apps

    master

    You can automatically inject language-specific tracers into your Container App using the --tracing inject flag. This process uses an init container to copy the tracer into your application without rebuilding the image.

    Key Behaviors:

    • Language Detection: Using --tracing inject without a --language flag will attempt to detect the application language automatically. This uses a larger composite tracer image.
    • Single Language Injection: To reduce image size and potential cold-start delays (especially for scale-to-zero workloads), specify a single language using --language <language>. Supported values are: java, nodejs, csharp, python, ruby, and php.
    • Go Support: Go tracers cannot be injected automatically. You must install dd-trace-go in your application image and use --tracing manual.
    • Manual Tracing: If the tracer is already installed in your application image, use --tracing manual.
    • Container Selection: If your Container App has multiple application containers, use --container-name to target a specific one. Note that --name refers to the Container App resource itself.

    Constraints:

    • Ruby injection does not support musl.
    • .NET tracer versions before 3.0 are not supported.
    • --tracer-version and --tracer-libc require the --language flag.
    # Detect the application language and add its tracer automatically
    datadog-ci container-app instrument \
      --subscription-id <subscription-id> \
      --resource-group <resource-group-name> \
      --name <container-app-name> \
      --tracing inject
    
    # Add only the Python tracer
    datadog-ci container-app instrument \
      --subscription-id <subscription-id> \
      --resource-group <resource-group-name> \
      --name <container-app-name> \
      --tracing inject \
      --language python
  9. Link React Native errors to source code

    master

    You can enrich Datadog errors with direct links to your source code in GitHub, GitLab, Bitbucket, or Azure DevOps.

    Requirements

    • The git executable must be installed.
    • datadog-ci must be run from within the git repository.

    When these are met, the command automatically gathers the commit hash, repository URL, and tracked file paths.

    Configuration

    • Repository URL: Inferred from the origin remote. Use --repository-url to override this (e.g., if using a custom GitLab URL).
    • Project Path: If running the command outside the React Native project root, use --project-path to provide the absolute path to the project root. This ensures absolute paths in the source maps are correctly mapped to your local files.

    Supported Providers

    Datadog generates links for:

    • GitHub/GitLab: https://<url>/blob/<commit>/<path>#L<line>
    • Bitbucket: https://<url>/src/<commit>/<path>#lines-<line>
    • Azure DevOps: Uses a specific query parameter format for version and path.
  10. Install the Datadog CI CLI

    master

    The datadog-ci CLI allows you to execute commands from CI/CD pipelines to integrate with Datadog products. You can install it as a project dependency, globally, or run it without a permanent installation.

    Note: Datadog recommends pinning an exact version (e.g., @v5.24.1) to prevent breaking changes and mitigate supply chain risks.

    # Install as a dev dependency (Recommended for projects)
    npm install --save-dev @datadog/datadog-ci
    # or
    yarn add --dev @datadog/datadog-ci
    
    # One-shot execution (No permanent installation)
    npx @datadog/datadog-ci@v5 [scope]
    # or
    yarn dlx @datadog/datadog-ci@v5 [scope]
  11. Configure Azure credentials for Container Apps

    master

    To run datadog-ci container-app commands, you must have valid Azure credentials configured. The CLI uses the Azure SDK's default credential chain, which supports:

    • Environment variables
    • Managed Identity (when running in Azure)
    • Azure CLI credentials (az login)
    • Visual Studio Code credentials
    • Azure PowerShell credentials

    For local development, authenticate using the Azure CLI:

    az login
  12. Instrument Azure Container Apps with Datadog

    master

    Use the datadog-ci container-app instrument command to apply Datadog instrumentation to your Azure Container Apps. This command modifies the existing Container App configuration to include the Datadog sidecar, enabling tracing, log collection, and custom metrics without requiring a redeployment of your application image.

    Note: You may still need to follow language-specific application steps as described in the Datadog documentation.

    # Instrument a Container App using subscription ID, resource group, and name
    datadog-ci container-app instrument \
      --subscription-id <subscription-id> \
      --resource-group <resource-group-name> \
      --name <container-app-name>