use of io.opentelemetry.api.common.Attributes in project opentelemetry-plugin by jenkinsci.
the class BaseIntegrationTest method assertJobMetadata.
protected void assertJobMetadata(AbstractBuild build, Tree<SpanDataWrapper> spans, String jobType) throws Exception {
List<SpanDataWrapper> root = spans.byDepth().get(0);
Attributes attributes = root.get(0).spanData.getAttributes();
MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.CI_PIPELINE_TYPE), CoreMatchers.is(jobType));
MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.CI_PIPELINE_MULTIBRANCH_TYPE), CoreMatchers.nullValue());
// Environment variables are populated
EnvVars environment = build.getEnvironment(new LogTaskListener(LOGGER, Level.INFO));
assertEnvironmentVariables(environment);
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-plugin by jenkinsci.
the class JenkinsOtelPluginFreestyleIntegrationTest method testFreestyleJob_with_causes.
@Test
public void testFreestyleJob_with_causes() throws Exception {
assumeFalse(SystemUtils.IS_OS_WINDOWS);
final String jobName = "test-cause-" + jobNameSuffix.incrementAndGet();
FreeStyleProject project = jenkinsRule.createFreeStyleProject(jobName);
project.getBuildersList().add(new Shell("set -u && touch \"x\""));
jenkinsRule.assertBuildStatusSuccess(project.scheduleBuild2(0, new Cause.UserIdCause()));
Tree<SpanDataWrapper> spans = getGeneratedSpans();
List<SpanDataWrapper> root = spans.byDepth().get(0);
Attributes attributes = root.get(0).spanData.getAttributes();
MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.CI_PIPELINE_RUN_CAUSE), CoreMatchers.is(Arrays.asList("UserIdCause:SYSTEM")));
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-plugin by jenkinsci.
the class JenkinsOtelPluginIntegrationTest method testPipelineWithSkippedSteps.
@Test
public void testPipelineWithSkippedSteps() throws Exception {
assumeFalse(SystemUtils.IS_OS_WINDOWS);
String pipelineScript = "def xsh(cmd) {if (isUnix()) {sh cmd} else {bat cmd}};\n" + "node() {\n" + " stage('ze-stage1') {\n" + " xsh (label: 'shell-1', script: 'echo ze-echo-1') \n" + " echo 'ze-echo-step' \n" + " }\n" + " stage('ze-stage2') {\n" + " xsh (label: 'shell-2', script: 'echo ze-echo-2') \n" + " }\n" + "}";
final Node agent = jenkinsRule.createOnlineSlave();
String jobName = "test-pipeline-with-skipped-tests-" + jobNameSuffix.incrementAndGet();
WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, jobName);
pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));
String rootSpanName = JenkinsOtelSemanticAttributes.CI_PIPELINE_RUN_ROOT_SPAN_NAME_PREFIX + jobName;
Tree<SpanDataWrapper> spans = getGeneratedSpans();
checkChainOfSpans(spans, "shell-1", "Stage: ze-stage1", JenkinsOtelSemanticAttributes.AGENT_UI, "Phase: Run", rootSpanName);
checkChainOfSpans(spans, "shell-2", "Stage: ze-stage2", JenkinsOtelSemanticAttributes.AGENT_UI, "Phase: Run", rootSpanName);
MatcherAssert.assertThat(spans.cardinality(), CoreMatchers.is(10L));
Optional<Tree.Node<SpanDataWrapper>> stageNode = spans.breadthFirstSearchNodes(node -> "Stage: ze-stage1".equals(node.getData().spanData.getName()));
MatcherAssert.assertThat(stageNode, CoreMatchers.is(CoreMatchers.notNullValue()));
Attributes attributes = stageNode.get().getData().spanData.getAttributes();
MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.JENKINS_STEP_PLUGIN_NAME), CoreMatchers.is(CoreMatchers.notNullValue()));
MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.JENKINS_STEP_PLUGIN_VERSION), CoreMatchers.is(CoreMatchers.notNullValue()));
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-plugin by jenkinsci.
the class JenkinsOtelPluginIntegrationTest method testPipelineWithParallelStep.
@Test
public void testPipelineWithParallelStep() throws Exception {
assumeFalse(SystemUtils.IS_OS_WINDOWS);
String pipelineScript = "def xsh(cmd) {if (isUnix()) {sh cmd} else {bat cmd}};\n" + "node() {\n" + " stage('ze-parallel-stage') {\n" + " parallel parallelBranch1: {\n" + " xsh (label: 'shell-1', script: 'echo this-is-the-parallel-branch-1')\n" + " } ,parallelBranch2: {\n" + " xsh (label: 'shell-2', script: 'echo this-is-the-parallel-branch-2')\n" + " } ,parallelBranch3: {\n" + " xsh (label: 'shell-3', script: 'echo this-is-the-parallel-branch-3')\n" + " }\n" + " }\n" + "}";
final Node agent = jenkinsRule.createOnlineSlave();
WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "test-pipeline-with-parallel-step" + jobNameSuffix.incrementAndGet());
pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));
final Tree<SpanDataWrapper> spans = getGeneratedSpans();
checkChainOfSpans(spans, "shell-1", "Parallel branch: parallelBranch1", "Stage: ze-parallel-stage", JenkinsOtelSemanticAttributes.AGENT_UI, "Phase: Run");
checkChainOfSpans(spans, "shell-2", "Parallel branch: parallelBranch2", "Stage: ze-parallel-stage", JenkinsOtelSemanticAttributes.AGENT_UI, "Phase: Run");
checkChainOfSpans(spans, "shell-3", "Parallel branch: parallelBranch3", "Stage: ze-parallel-stage", JenkinsOtelSemanticAttributes.AGENT_UI, "Phase: Run");
MatcherAssert.assertThat(spans.cardinality(), CoreMatchers.is(13L));
Optional<Tree.Node<SpanDataWrapper>> branchNode = spans.breadthFirstSearchNodes(node -> "Parallel branch: parallelBranch1".equals(node.getData().spanData.getName()));
MatcherAssert.assertThat(branchNode, CoreMatchers.is(CoreMatchers.notNullValue()));
Attributes attributes = branchNode.get().getData().spanData.getAttributes();
MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.JENKINS_STEP_PLUGIN_NAME), CoreMatchers.is(CoreMatchers.notNullValue()));
MatcherAssert.assertThat(attributes.get(JenkinsOtelSemanticAttributes.JENKINS_STEP_PLUGIN_VERSION), CoreMatchers.is(CoreMatchers.notNullValue()));
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-plugin by jenkinsci.
the class GarbageCollector method registerObservers.
/**
* Register all observers provided by this module.
*/
public static void registerObservers() {
List<GarbageCollectorMXBean> garbageCollectors = ManagementFactory.getGarbageCollectorMXBeans();
Meter meter = GlobalOpenTelemetry.get().getMeterProvider().get(GarbageCollector.class.getName());
List<Attributes> labelSets = new ArrayList<>(garbageCollectors.size());
for (GarbageCollectorMXBean gc : garbageCollectors) {
labelSets.add(Attributes.of(GC_KEY, gc.getName()));
}
meter.gaugeBuilder("runtime.jvm.gc.time").ofLongs().setDescription("Time spent in a given JVM garbage collector in milliseconds.").setUnit("ms").buildWithCallback(resultLongObserver -> {
for (int i = 0; i < garbageCollectors.size(); i++) {
resultLongObserver.record(garbageCollectors.get(i).getCollectionTime(), labelSets.get(i));
}
});
meter.gaugeBuilder("runtime.jvm.gc.count").ofLongs().setDescription("The number of collections that have occurred for a given JVM garbage collector.").setUnit("collections").buildWithCallback(resultLongObserver -> {
for (int i = 0; i < garbageCollectors.size(); i++) {
resultLongObserver.record(garbageCollectors.get(i).getCollectionCount(), labelSets.get(i));
}
});
}
Aggregations