jenkinsci / opentelemetry-plugin

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

Capability to manually create spans #90

Closed cyrille-leclerc closed 5 days ago

cyrille-leclerc commented 3 years ago

Problem description

I want to manually create spans in my pipeline, similar to manually creating spans when instrumenting applications with distributed tracing.

Example use cases

Example with the OpenTelemetry APIs for Java

Tracer tracer = null;
tracer.spanBuilder("Get code from Git (incl fetching sub modules)")
    .setAttribute("my.attribute", "my value")
    .startSpan();

See other problem statements

Proposed solutions

createSpan pipeline step

pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                createSpan(name:'my-span', attributes:[TODO 'command':'git']) {
                    // TODO sequence of shell steps to `git`+ fetch git submodules
                    // Get some code from a GitHub repository
                    // git credentialsId: 'my-user-git', url: 'https://github.com/jglick/simple-maven-project-with-tests.git'
                }
            }
        }
        stage('Build') {
            steps {
                ...
            }
        }
    }
}
ipleten commented 2 years ago

It also might be beneficial to get id of span and of traceID to enrich trace with data from other tools. Like we have deployment tool being triggered within pipeline which we can update to send spans to current trace therefore we could track deployment status linked to pipeline.

kuisathaverat commented 4 months ago

Does the following pipeline code do the same? I think so

def my_span(List spanAttributes, Closure body) {
    withSpanAttributes(spanAttributes) {
        body()
    }
}

pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                my_span([spanAttribute(key: "test.tool", value: "junit")]) {
                    // TODO sequence of shell steps to `git`+ fetch git submodules
                    // Get some code from a GitHub repository
                    // git credentialsId: 'my-user-git', url: 'https://github.com/jglick/simple-maven-project-with-tests.git'
                }
            }
        }
        stage('Build') {
            steps {
                ...
            }
        }
    }
}
kuisathaverat commented 4 months ago

I am wrong; the functions and shared library steps do not create a new span. I will review if it is possible to generate a span there.

roeycarmi commented 2 months ago

Hello, I am really looking forward the ability to create my own spans while still being part of the auto genrated trace created by the plugin.

I followed the #84 PR for a long time and I don't understand why is it closed? Would mean a lot to my team, and thanks for everyone involved :)

xBis7 commented 1 month ago

Hi @cyrille-leclerc @v1v, I would like to pick up PR #84 if it's ok with you.

I see that the PR was based on an older version of the plugin and that the implementation needs to be updated. I don't know if there has been an issue with the PR approach.

I have some suggestions and questions

kuisathaverat commented 1 month ago

Feel free to open the PR, we will review it ñ.

xBis7 commented 1 month ago

@kuisathaverat Thanks! I'll create a PR and tag you, once the code is ready for review.

xBis7 commented 3 weeks ago

PR https://github.com/jenkinsci/opentelemetry-plugin/pull/956 is ready for review. @cyrille-leclerc @kuisathaverat could you please take a look?

tabathad commented 2 weeks ago

Our organization is keen to have this capability and we're happy to assist in moving it forward. Let us know if there's anything specific we can help with to get this across the finish line.

kuisathaverat commented 2 weeks ago

Our organization is keen to have this capability and we're happy to assist in moving it forward. Let us know if there's anything specific we can help with to get this across the finish line.

Nothing blocks you from using it; you can use the incremental version from the PR.

kuisathaverat commented 5 days ago

released as https://github.com/jenkinsci/opentelemetry-plugin/releases/tag/3.1419.v3b_27ca_911066

roeycarmi commented 5 days ago

Should add documentation to: https://www.jenkins.io/doc/pipeline/steps/opentelemetry/

kuisathaverat commented 4 days ago

Should add documentation to: https://www.jenkins.io/doc/pipeline/steps/opentelemetry/

IFAIR that documentation is generated from the plugin classes, so at some point, it will be updated.