Search in sources :

Example 71 with Attributes

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);
}
Also used : EnvVars(hudson.EnvVars) Attributes(io.opentelemetry.api.common.Attributes) JenkinsOtelSemanticAttributes(io.jenkins.plugins.opentelemetry.semconv.JenkinsOtelSemanticAttributes) LogTaskListener(hudson.util.LogTaskListener)

Example 72 with Attributes

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")));
}
Also used : Shell(hudson.tasks.Shell) Attributes(io.opentelemetry.api.common.Attributes) JenkinsOtelSemanticAttributes(io.jenkins.plugins.opentelemetry.semconv.JenkinsOtelSemanticAttributes) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 73 with Attributes

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()));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Node(hudson.model.Node) Attributes(io.opentelemetry.api.common.Attributes) JenkinsOtelSemanticAttributes(io.jenkins.plugins.opentelemetry.semconv.JenkinsOtelSemanticAttributes) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 74 with Attributes

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()));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Node(hudson.model.Node) Attributes(io.opentelemetry.api.common.Attributes) JenkinsOtelSemanticAttributes(io.jenkins.plugins.opentelemetry.semconv.JenkinsOtelSemanticAttributes) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 75 with Attributes

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));
        }
    });
}
Also used : Meter(io.opentelemetry.api.metrics.Meter) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) Attributes(io.opentelemetry.api.common.Attributes) ArrayList(java.util.ArrayList)

Aggregations

Attributes (io.opentelemetry.api.common.Attributes)175 Test (org.junit.jupiter.api.Test)128 ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)45 Resource (io.opentelemetry.sdk.resources.Resource)33 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)27 Context (io.opentelemetry.context.Context)25 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)24 SpanContext (io.opentelemetry.api.trace.SpanContext)22 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)22 SpanData (io.opentelemetry.sdk.trace.data.SpanData)22 HashMap (java.util.HashMap)21 Duration (java.time.Duration)20 ExemplarData (io.opentelemetry.sdk.metrics.data.ExemplarData)18 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)18 TestClock (io.opentelemetry.sdk.testing.time.TestClock)18 AttributeKey (io.opentelemetry.api.common.AttributeKey)17 Span (io.opentelemetry.api.trace.Span)17 DoubleExemplarData (io.opentelemetry.sdk.metrics.data.DoubleExemplarData)17 AttributeKey.stringKey (io.opentelemetry.api.common.AttributeKey.stringKey)16 Map (java.util.Map)16