Skip to content

Adopt OTel cicd.* semantic conventions incl cicd.* metrics and spans - #1251

Merged
krisstern merged 67 commits into
jenkinsci:mainfrom
kamphaus:add-otel-cicd-metrics
Aug 3, 2026
Merged

Adopt OTel cicd.* semantic conventions incl cicd.* metrics and spans#1251
krisstern merged 67 commits into
jenkinsci:mainfrom
kamphaus:add-otel-cicd-metrics

Conversation

@kamphaus

@kamphaus kamphaus commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Related to #56

Building on #1096, we

  • Added plugin property semConvStability for switching between legacy Jenkins semantic conventions, Otel semantic conventions or both. Switching setting displays a warning to restart Jenkins.
image with help: image
  • Switched which metrics and attributes are used depending on semConvStability
  • Implemented cardinality protection
  • Fixed a bug in shortname logic for JobDSL
  • Implemented additional conventions (from a newer Otel SemConv v1.37.0):
    • span attributes

Testing done

  • Fixed integration test of metrics
  • Manual tests running pipelines with each SemConvStability value
  • Manual test clean installation (semConvStability value = JENKINS)
  • Manual test upgrade (semConvStability value = JENKINS)

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

cyrille-leclerc and others added 30 commits April 21, 2025 23:00
# Conflicts:
#	src/main/java/io/jenkins/plugins/opentelemetry/init/JenkinsExecutorMonitoringInitializer.java
# Conflicts:
#	src/main/java/io/jenkins/plugins/opentelemetry/init/JenkinsExecutorMonitoringInitializer.java
#	src/main/java/io/jenkins/plugins/opentelemetry/job/MonitoringRunListener.java
#	src/main/java/io/jenkins/plugins/opentelemetry/job/runhandler/DefaultRunHandler.java
#	src/main/java/io/jenkins/plugins/opentelemetry/job/runhandler/JobDslRunHandler.java
#	src/main/java/io/jenkins/plugins/opentelemetry/job/runhandler/MatrixRunHandler.java
#	src/main/java/io/jenkins/plugins/opentelemetry/semconv/ExtendedJenkinsAttributes.java

@kamphaus kamphaus left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I demoed this PR to some OpenTelemetry maintainers.
Here are 2 feedback items I will look into.

Comment on lines +45 to +49
public static LongUpDownCounter newCiCdPipelineRunActiveCounter(Meter meter) {
LongUpDownCounterBuilder cicdPipelineRunActiveCounterBuilder = meter.upDownCounterBuilder(
"cicd.pipeline.run.active")
.setUnit("{run}")
.setDescription("Number of active pipeline runs grouped by pipeline and state.");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Looks like active pipeline runs can be negative.

Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into this issue I couldn't reproduce it.
However I did find a type mismatch in CicdMetric: 6835e54

@kamphaus
kamphaus requested a review from kuisathaverat April 26, 2026 19:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR advances the plugin’s adoption of OpenTelemetry cicd.* semantic conventions by introducing a global semConvStability switch (Jenkins-only vs OTel-only vs both), updating span/metric attributes accordingly, and adding cardinality protection for pipeline-name metric attributes. It also updates integration/unit tests and JCasC fixtures to cover the new configuration behavior and metrics export strategy.

Changes:

  • Added SemConvStability configuration (UI + JCasC fixtures) to control emitting legacy Jenkins vs OTel CI/CD semantic conventions (or both).
  • Implemented/rewired CI/CD metrics and span attribute emission to follow the selected semantic convention stability, with pipeline-name cardinality protection for metrics.
  • Updated integration/unit tests and test harness metric export behavior to reduce flakiness and validate emitted metrics/spans.

Reviewed changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/zipkin.yml Adds semConvStability to JCasC test input.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/zipkin-expected.yml Updates expected exported config to include semConvStability.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/jaeger.yml Adds semConvStability to JCasC test input.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/jaeger-expected.yml Updates expected exported config to include semConvStability.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/elastic.yml Adds semConvStability to JCasC test input.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/elastic-expected.yml Updates expected exported config to include semConvStability.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/elastic-logs.yml Adds semConvStability to JCasC test input (and fixes formatting).
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/elastic-logs-expected.yml Updates expected exported config to include semConvStability.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/elastic-logs-exclusive.yml Adds semConvStability to JCasC test input (exclusive logs backend).
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/elastic-logs-exclusive-expected.yml Updates expected exported config to include semConvStability.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/configuration-as-code.yml Adds semConvStability to JCasC test input.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/configuration-as-code-expected.yml Updates expected exported config to include semConvStability.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/configuration-as-code-default.yml Adds semConvStability to default JCasC config test input.
src/test/resources/io/jenkins/plugins/opentelemetry/jcasc/configuration-as-code-default-expected.yml Updates expected exported default config to include semConvStability.
src/test/java/io/jenkins/plugins/opentelemetry/job/step/GitStepHandlerTest.java Sets SemConvStability explicitly to keep assertions stable under the new toggle.
src/test/java/io/jenkins/plugins/opentelemetry/JenkinsOtelPluginIntegrationTest.java Restores metrics assertions using explicit force-export and updates integration test setup.
src/test/java/io/jenkins/plugins/opentelemetry/JenkinsOpenTelemetryPluginConfigurationIntegrationTest.java Adds a helper to force metric export after reconfiguration and validates reconfig behavior via metrics.
src/test/java/io/jenkins/plugins/opentelemetry/BaseIntegrationTest.java Adds a shared forceMetricsExport() helper for integration tests.
src/main/resources/io/jenkins/plugins/opentelemetry/JenkinsOpenTelemetryPluginConfiguration/help-serviceName.html Fixes malformed help HTML structure.
src/main/resources/io/jenkins/plugins/opentelemetry/JenkinsOpenTelemetryPluginConfiguration/help-semConvStability.html Adds help text describing semantic convention stability and the restart implication.
src/main/resources/io/jenkins/plugins/opentelemetry/JenkinsOpenTelemetryPluginConfiguration/config.jelly Adds the semConvStability select control to global configuration.
src/main/java/io/jenkins/plugins/opentelemetry/semconv/SemConvStability.java Introduces the enum controlling legacy/OTel emission behavior.
src/main/java/io/jenkins/plugins/opentelemetry/semconv/ExtendedJenkinsAttributes.java Deprecates legacy CI/CD attributes in favor of OTel incubating attributes and clarifies intent.
src/main/java/io/jenkins/plugins/opentelemetry/semconv/CicdMetrics.java Adds OTel cicd.* metric builders and Jenkins→OTel value mapping helpers.
src/main/java/io/jenkins/plugins/opentelemetry/OpenTelemetryConfiguration.java Adjusts test-mode metric export interval to reduce background scraping conflicts.
src/main/java/io/jenkins/plugins/opentelemetry/job/step/BuildTriggerStepHandler.java Emits Jenkins vs OTel CI/CD pipeline-name attributes depending on semConvStability.
src/main/java/io/jenkins/plugins/opentelemetry/job/step/AbstractGitStepHandler.java Emits Jenkins vs OTel VCS attributes depending on semConvStability.
src/main/java/io/jenkins/plugins/opentelemetry/job/runhandler/RunHandler.java Adds getSpanName() to support low-cardinality pipeline naming.
src/main/java/io/jenkins/plugins/opentelemetry/job/runhandler/MatrixRunHandler.java Refactors to use getSpanName() for consistent span naming.
src/main/java/io/jenkins/plugins/opentelemetry/job/runhandler/JobDslRunHandler.java Uses getSpanName() and adjusts JobDSL naming logic.
src/main/java/io/jenkins/plugins/opentelemetry/job/runhandler/DefaultRunHandler.java Implements getSpanName() and simplifies root span builder creation.
src/main/java/io/jenkins/plugins/opentelemetry/job/opentelemetry/OtelContextAwareAbstractRunListener.java Injects and exposes SemConvStability for listeners.
src/main/java/io/jenkins/plugins/opentelemetry/job/MonitoringRunListener.java Adds cicd.* metrics, cardinality protection, and convention-controlled span/metric attribute emission.
src/main/java/io/jenkins/plugins/opentelemetry/job/MonitoringPipelineListener.java Adds convention-controlled step/task span attributes and worker attributes.
src/main/java/io/jenkins/plugins/opentelemetry/job/MonitoringBuildStepListener.java Adds convention-controlled span attributes for freestyle build steps.
src/main/java/io/jenkins/plugins/opentelemetry/JenkinsOpenTelemetryPluginConfiguration.java Persists semConvStability, adds UI fill/check endpoints, and restart warning validation.
src/main/java/io/jenkins/plugins/opentelemetry/JenkinsControllerOpenTelemetry.java Exposes a testing-only metric reader accessor used by tests to force flush.
src/main/java/io/jenkins/plugins/opentelemetry/jenkins/OpenTelemetryConfigurerComputerListener.java Adds convention-controlled worker resource attributes for agents.
src/main/java/io/jenkins/plugins/opentelemetry/init/JenkinsExecutorMonitoringInitializer.java Adds cicd.worker.count emission and reorganizes executor/node metrics callbacks.
src/main/java/io/jenkins/plugins/opentelemetry/computer/MonitoringComputerListener.java Adds convention-controlled worker attributes on controller/agent computers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/io/jenkins/plugins/opentelemetry/job/MonitoringRunListener.java Outdated
kamphaus added 3 commits June 20, 2026 09:57
The test works on Windows, hence no need to follow Copilot's suggestion
to uncomment.
@kamphaus

kamphaus commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

I'm not that familiar with @RequirePOST.
Are those 2 Copilot suggestions valid?
Those annotations were previously added in 20dfebf to fix findings by github-advanced-security: #1251 (review)
Manually testing the config UI, these seem to be working.

@krisstern

Copy link
Copy Markdown
Member

It looks like these warnings are not really valid to me

@krisstern
krisstern merged commit e62d394 into jenkinsci:main Aug 3, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants