jenkinsci / datadog-plugin

A Jenkins plugin used to forward metrics, events, and service checks to an account at Datadog, automatically.
https://plugins.jenkins.io/datadog/
MIT License
30 stars 48 forks source link

Add support for automatic APM tracers configuration #354

Closed nikita-tkachenko-datadog closed 11 months ago

nikita-tkachenko-datadog commented 1 year ago

Requirements for Contributing to this repository

What does this PR do?

Adds support for injecting Datadog APM Tracers into Jenkins builds transparently to the user. "Enable Datadog Test Visibility" checkbox should be set in job configuration UI in order to enable tracer injection for a specific job.

Description of the Change

A new JobProperty is added that stores tracer injection settings. An EnvironmentContributor (for freestyle projects) and a StepContributor (for pipelines) are added as well.

If Java tracer injection is enabled one of the contributors downloads the tracer JAR (the JAR is downloaded to the node where the build is running) and augments job environment with MAVEN_OPTS/GRADLE_OPTS and Datadog environment variables. Tracer JAR is stored inside the job workspace. By default it is downloaded only if no JAR has been downloaded previously, or if previous JAR is older than 12 hours (TTL is configurable).

Injection for other languages works similarly (a combination of installing the tracer and injecting it via environment variables).

Alternate Designs

  1. Configuring tracer injection centrally in Datadog plugin settings - rejected, as this is too coarse grained, customer might not want to run ALL of their jobs with the tracer, but likely only a subset of them.
  2. Adding custom a job/pipeline step - rejected, as this would require customer to alter their job/pipeline definitions, and is not likely to bring additional value (it is very unlikely that the customer might want to trigger multiple Maven/Gradle builds in the same job and only instrument some of them. Even in such situations the accepted design allows this by modifying the injected env variables).
  3. Using BuildWrapper instead of EnvironmentContributor - rejected, as using a build wrapper requires a dedicated UI control in addition to job property that is already there

Possible Drawbacks

Tracer injection will not work if a job starts Maven/Gradle build inside a container. In this case customer can fallback to manual tracer configuration, the way this is done at the moment.

Verification Process

Verified manually using a dockerized Jenkins instance. Checked the following scenarios:

Both Maven and Gradle builds were verified.

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)