-
Notifications
You must be signed in to change notification settings - Fork 55
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
Added step withSpanAttributes to set the attributes also on child spans, added setSpanAttributes for setting the attribute only on the target #827
Conversation
This parameter is not yet functional, but it should be accepted in a Jenkinsfile.
…nAttributeStep This is to make it clear that it's testing the target parameter. An additional withSpanAttribute asserts that the root span can be edited from anywhere in the pipeline.
…nAttributeStepSetOn The test pipeline sets the parameter setOn.
The asserts for setting of attributes on children (not yet implemented) are commented out.
Also we rename some variables to align with the attribute key being tested
This makes it possible to distinguish setAttribute performed by withSpanAttribute and later setAttributes for child spans.
@cyrille-leclerc would you mind taking a look? |
Should the new behavior of the |
the
Serialized and memory consumption are the possible issues |
src/main/java/io/jenkins/plugins/opentelemetry/job/OtelTraceService.java
Outdated
Show resolved
Hide resolved
probably not; there are other steps like withCredentials that propagate something to lower levels in the pipeline like environment variables; they enclose the children into a closure to make it obvious that you are propagation something to your children, and I doubt they use actions to propagate the context. https://www.jenkins.io/doc/pipeline/steps/credentials-binding/ |
I will take a look how they do it. Thanks for the links. |
This will prevent more expensive iterations and listing of all actions of type AttributeSetterAction. Also replace AttributeSetterAction by the existing OpenTelemetryAttributesAction. OpenTelemetryAttributesAction was not yet used for Run, Build, FlowNode instances.
depending on whether it takes a closure (and sets the attribute on child spans as well) or not. Also splits the tests accordingly (WIP).
This way no span will be created for it same as for withSpanAttribute.
Instead of setting child span attributes from this action, the context's OpenTelemetryAttributesAction is used. We keep it only for setting it for the "Phase: Finalise" span.
This will allow running it in the declarative pipeline options
DONE |
…ttribute This ensures backwards compatibility of existing pipelines.
After some reflection I've implemented this change.
For consistency with other plugins (eg. Should |
Only do this if asked for in PR review.
src/main/java/io/jenkins/plugins/opentelemetry/job/OtelTraceService.java
Show resolved
Hide resolved
Thank you for the effort, it took a long time. I suggested to add an explanation through javadocs. |
The code LGTM, I have to find some time to make a manual test to verify there is nothing weird. |
Any update @kuisathaverat @cyrille-leclerc ? |
I'm sorry. It is still on my plate, but I do not find time to test it. I will try to find some gap this week. |
The
withSpanAttributes
step was added. This new step sets the attributes on all child spans created inside the body block. This is implemented using the StepContext.setSpanAttributes
was added to set attribute on the target without a body block similar to the existingwithSpanAttribute
.setSpanAttributes
is preferred overwithSpanAttribute
for consistency with other plugins (eg.withCredentials
).Fixes #173
The main difficulty in implementing a solution for #173 was how to efficiently
otelTraceService.getSpan
to set the attributes of some child spans of the root span and documented the limitations of the current implementation.OpenTelemetryAttributesAction
to the Run tracking child attributes for later agent and phase spans. TheOpenTelemetryAttributesAction
is added to the SpanContext to track attributes to be set to new spans within that context.OpenTelemetryAttributesAction
to be serializable to fix the errorFailed to serialize OpenTelemetryAttributesAction
.Limitations
Some child spans that were created before the execution of setSpanAttributes / withSpanAttributes might be missed.
For example closed spans or some open child spans.
Child spans created after the execution of withSpanAttributes will all have the attribute set correctly.
Declarative pipelines can only use a single
withSpanAttributes
step inside theoptions
block.Potential future work (not in this PR)
Testing done
withSpanAttributes
andsetSpanAttributes
withSpanAttributes
steps with the same key.withSpanAttributes([spanAttribute(key: 'build.tool', value: 'gradle', target: 'PIPELINE_ROOT_SPAN')]) { ... }
and verified in Jaeger that all expected spans have this tag.Submitter checklist