-
Notifications
You must be signed in to change notification settings - Fork 92
Fix: traceparent variable issue #1219
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
Open
Zenith1415
wants to merge
9
commits into
jenkinsci:main
Choose a base branch
from
Zenith1415:fix-traceparent-variable-issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b72cbd8
fixed changes requested
Zenith1415 7c1d73d
Test: Add integration test verifying context propagation between layers
Zenith1415 02f6e9d
Fix: Remove incorrect imported class in same package
Zenith1415 cc87aea
Fix code formatting violations
Zenith1415 c05890b
Added regression test for TRACEPARENT propagation in nested pipeline …
Zenith1415 c10773b
Merge branch 'main' into fix-traceparent-variable-issue
Zenith1415 9522f47
Added WithEnv, multi stages and a try/catch case
Zenith1415 90ced8e
Added WithEnv, multi stages and a try/catch case
Zenith1415 135aa50
Update src/test/java/io/jenkins/plugins/opentelemetry/job/TraceParent…
Zenith1415 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/test/java/io/jenkins/plugins/opentelemetry/job/TraceParentPipelineTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package io.jenkins.plugins.opentelemetry.job; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
|
|
||
| import hudson.model.Result; | ||
| import io.jenkins.plugins.opentelemetry.JenkinsOpenTelemetryPluginConfiguration; | ||
| import jenkins.model.GlobalConfiguration; | ||
| import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; | ||
| import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
| import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.jvnet.hudson.test.JenkinsRule; | ||
|
|
||
| public class TraceParentPipelineTest { | ||
|
|
||
| @Rule | ||
| public JenkinsRule jenkinsRule = new JenkinsRule(); | ||
|
|
||
| @Test | ||
| public void TraceParentPropagation() throws Exception { | ||
| JenkinsOpenTelemetryPluginConfiguration config = | ||
| GlobalConfiguration.all().get(JenkinsOpenTelemetryPluginConfiguration.class); | ||
|
|
||
| assertNotNull(config); | ||
|
|
||
| config.setEndpoint("http://localhost:4317"); | ||
| config.setExportOtelConfigurationAsEnvironmentVariables(true); | ||
| config.save(); | ||
|
|
||
| WorkflowJob job = jenkinsRule.createProject(WorkflowJob.class, "traceparent-withenv-trycatch-test"); | ||
|
|
||
| String pipelineScript = "node {\n" + " stage('Stage-A') {\n" | ||
| + " sh 'echo a_tp=$TRACEPARENT'\n" | ||
| + " }\n" | ||
| + "\n" | ||
| + " withEnv(['FOO=bar']) {\n" | ||
| + " stage('Stage-B') {\n" | ||
| + " sh 'echo b_tp=$TRACEPARENT'\n" | ||
| + " try {\n" | ||
| + " sh 'echo try_tp=$TRACEPARENT'\n" | ||
| + " sh 'exit 1'\n" | ||
| + " } catch (err) {\n" | ||
| + " sh 'echo catch_tp=$TRACEPARENT'\n" | ||
| + " } finally {\n" | ||
| + " sh 'echo final_tp=$TRACEPARENT'\n" | ||
| + " }\n" | ||
| + " }\n" | ||
| + " }\n" | ||
| + "}"; | ||
|
|
||
| job.setDefinition(new CpsFlowDefinition(pipelineScript, true)); | ||
|
|
||
| WorkflowRun run = jenkinsRule.assertBuildStatus(Result.SUCCESS, job.scheduleBuild2(0)); | ||
|
|
||
| String logs = JenkinsRule.getLog(run); | ||
|
|
||
| String aTp = extract("a_tp=", logs); | ||
| String bTp = extract("b_tp=", logs); | ||
| String tryTp = extract("try_tp=", logs); | ||
| String catchTp = extract("catch_tp=", logs); | ||
| String finalTp = extract("final_tp=", logs); | ||
|
|
||
| assertNotNull(aTp); | ||
| assertNotNull(bTp); | ||
| assertNotNull(tryTp); | ||
| assertNotNull(catchTp); | ||
| assertNotNull(finalTp); | ||
|
|
||
| assertNotEquals(aTp, bTp); | ||
| assertNotEquals(bTp, tryTp); | ||
| assertNotEquals(bTp, catchTp); | ||
| assertNotEquals(bTp, finalTp); | ||
| assertNotEquals(tryTp, catchTp); | ||
| assertNotEquals(tryTp, finalTp); | ||
|
|
||
| String traceId = traceId(aTp); | ||
|
|
||
| assertEquals(traceId, traceId(bTp)); | ||
| assertEquals(traceId, traceId(tryTp)); | ||
| assertEquals(traceId, traceId(catchTp)); | ||
| assertEquals(traceId, traceId(finalTp)); | ||
| } | ||
|
|
||
| private String extract(String prefix, String log) { | ||
| for (String line : log.split("\n")) { | ||
| if (line.contains(prefix)) { | ||
| return line.substring(line.indexOf(prefix) + prefix.length()).trim(); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private String traceId(String traceParent) { | ||
| String[] parts = traceParent.split("-"); | ||
| return parts.length >= 2 ? parts[1] : null; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.