jenkinsci / opentelemetry-plugin

Monitor and observe Jenkins with OpenTelemetry.
https://plugins.jenkins.io/opentelemetry/
Apache License 2.0
100 stars 53 forks source link

Ability to add an attribute/info via the pipeline #599

Closed neilharris123 closed 1 year ago

neilharris123 commented 1 year ago

What feature do you want to see added?

Hello. It would be good if atrribute could be added to the spans declaratively in the Jenkinsfile. Here's our use case: We are sending traces to Splunk APM, and generating alerts based on failed jobs. We have four different priorities of alerts, P1, P2, P3, P4. Certain pipelines are considered higher a propriety (so, for example P1), while others are lower priority (P4). We would like to be able to define this priority in the Jenkinsfiile for each job, so that this is then available in the spans when they land in Splunk Observability Platform. This would be possible if we were able to define the level of priority in the Jenkinsfile, so that an attribute with this info is added to the the spans. For example, something like ci.pipeline.alert.priority: P1 Are there any plan to implement something like this? Adding an attribute via the opentelemtry collector is not really feasible for this, because we need different priorities for each pipeline.

Upstream changes

No response

cyrille-leclerc commented 1 year ago

Did you see our feature withSpanAttribute(key: "ci.pipeline.alert.priority", value: "P1") that enables adding attributes to the spans?

The Jenkinsfile looks like:

withSpanAttribute(key: "ci.pipeline.alert.priority", value: "P1") // associate with the "Phase: Run" span
node {
    stage("build") {
        git credentialsId: 'github', url: 'https://github.com/cyrille-leclerc/my-war'
        sh "./mvnw clean verify"
    }
}

With an observability backend like Grafana with Tempo, you just have to query with

{resource.service.name = "my-jenkins" && span.ci.pipeline.alert.priority="P1"}

https://github.com/jenkinsci/opentelemetry-plugin/blob/master/docs/job-traces.md#enriching-pipeline-build-traces-with-custom-span-attributes

Would this solve your problem?

image

cyrille-leclerc commented 1 year ago

@neilharris123 please have a look at this coming feature that could help you:

cyrille-leclerc commented 1 year ago

withSpanAttribute enriched in 2.14.0 https://github.com/jenkinsci/opentelemetry-plugin/releases/tag/opentelemetry-2.13.0