Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capability to manually create spans #90

Open
cyrille-leclerc opened this issue May 5, 2021 · 4 comments
Open

Capability to manually create spans #90

cyrille-leclerc opened this issue May 5, 2021 · 4 comments
Labels
enhancement New feature or request waiting-for-user

Comments

@cyrille-leclerc
Copy link
Contributor

cyrille-leclerc commented May 5, 2021

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

  • Create a "grouping span" to group multiple atomic actions together.
    • Example: Get code from a complex Git repository incl fetching submodules
  • Add events to the trace typically to add "logs"
    • Probably better solved using the concept of "span events" in OpenTelemetry API
  • Add informations on shell steps to indicate the purpose of the shell step (e.g. an sh 'docker login -u $user -p $pass my.docker.registry')

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 {
                ...
            }
        }
    }
}
@cyrille-leclerc cyrille-leclerc changed the title WIP Capability to manually create spans Capability to manually create spans May 5, 2021
@cyrille-leclerc cyrille-leclerc added the enhancement New feature or request label May 6, 2021
@ipleten
Copy link

ipleten commented Nov 22, 2021

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
Copy link
Contributor

kuisathaverat commented Jul 2, 2024

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
Copy link
Contributor

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
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request waiting-for-user
Projects
None yet
Development

No branches or pull requests

4 participants