jenkinsci / opentelemetry-plugin

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

Consume TRACEPARENT from upstream via environment variable while creating root span #864

Open amadragonfire opened 1 week ago

amadragonfire commented 1 week ago

What feature do you want to see added?

Can this plugin use the TRACEPARENT available from upstream via environment variable and use it while creating root span. Right now, it's working by passing in header. Is there any alternative way ?

Upstream changes

No response

Are you interested in contributing this feature?

No response

cyrille-leclerc commented 1 week ago

Hello @amadragonfire . Are you referring to passing traceparent when triggering a build through Jenkins APIs?

amadragonfire commented 1 week ago

Hi @cyrille-leclerc thanks for your response. I'm asking about triggering build using Jenkinsfile with multibranch pipeline. We need the plugin to read the traceparent available as environment variable from the pipeline.

amadragonfire commented 5 days ago

@cyrille-leclerc Could you please suggest if there is any other way to pass traceparent from upstream to Opentelemetry plugin apart from passing in http header ?

We’ve pipelines getting triggered from Bitbucket via webhook and there is no way to modify the webhook header from Bitbucket side.

cyrille-leclerc commented 5 days ago

Please help me understand a point about using the TRACEPARENT environment variable. An environment variable applies to an entire process, so it would apply to the entire Jenkins Controller JVM.

Do you want all the traces emitted by this Jenkins Controller, pipeline traces as well as web page traces, to share the same traceparent? A scenario where this behavior would make sense to me would be for "One Shot Jenkins Controllers", Jenkins controllers created on demand to execute just one run. From what I remember, there was a Jenkins Community initiative to create a distribution of the Jenkins Controller to ease this use case but I couldn't find any reference.

We’ve pipelines getting triggered from Bitbucket via webhook and there is no way to modify the webhook header from Bitbucket side.

Can you please explain if and how you would see context propagation from BitBucket webhooks and Jenkins? Can BitBucket be instrumented with traces and produce a traceparent?

We already have a feature flag to enable trace context propagation on Jenkins HTTP calls with otel.instrumentation.jenkins.remote.span.enabled, it's restricted to propagating context on job build requests (URI ^(/[^/]+)?/job/([\w/-]+)/build(WithParameters)?$), we could see if builds are triggered by SCM webhooks if we see that some SCMs can propagate traceparent in their web hook invocations.

nileshjoshi2799 commented 2 days ago

Let me elaborate objective here. We are looking to view lifespan of a service request flowing through bitbucket-> Jenkins pipeline as single TRACE(multiple spans)

  1. Jenkins ready with opentelemetry plugin and configured with OTLP endpoint.
  2. A service request comes into Bitbucket source repo with a PR.
  3. Bitbucket POST webhook calls a jenkins pipeline on remote host. We send this TRACEPARENT as string parameter to jenkins.(build with parameters)
  4. Jenkins generates its's own ROOT SPAN and sends traces to OTLP endpoint.

Objective: Jenkins opentelemetry to append its pipeline spans to TRACEPARENT received from Bitbucket webhook.

On jenkins, we tried:

  1. Setting TRACEPARENT string as OS Environment variable
  2. Changing stage/step within jenkins pipeline to change env.TRACEPARENT to new value each time pipeline is called from webhoo,

Observation: Jenkins opentelemetry generates its own root span each time and disregards what is received from Bitbucket or OS Env variable.

Expectation: jenkins plugin to honor TRACEPARENT from env variable OR build parameter as opentelemetry context. So that: Entire request of lifespan is shown properly with origin as BB span -> Jenkins pipelines spans (ALL having single TRACE_ID)