Skip to content
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

Add code attributes to quartz spans #4332

Merged
merged 2 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.quartz.v2_0;

import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.quartz.JobExecutionContext;

public class QuartzCodeAttributesExtractor
extends CodeAttributesExtractor<JobExecutionContext, Void> {
@Override
protected Class<?> codeClass(JobExecutionContext jobExecutionContext) {
return jobExecutionContext.getJobDetail().getJobClass();
}

@Override
protected String methodName(JobExecutionContext jobExecutionContext) {
return "execute";
}

@Override
@Nullable
protected String filePath(JobExecutionContext jobExecutionContext) {
return null;
}

@Override
@Nullable
protected Long lineNumber(JobExecutionContext jobExecutionContext) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public QuartzTracing build() {
Instrumenter.newBuilder(openTelemetry, INSTRUMENTATION_NAME, new QuartzSpanNameExtractor());

instrumenter.setErrorCauseExtractor(new QuartzErrorCauseExtractor());
instrumenter.addAttributesExtractor(new QuartzCodeAttributesExtractor());
instrumenter.addAttributesExtractors(additionalExtractors);

return new QuartzTracing(new TracingJobListener(instrumenter.newInstrumenter()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

package io.opentelemetry.instrumentation.quartz.v2_0;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.trace.data.StatusData;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.Properties;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -63,7 +64,14 @@ void successfulJob() throws Exception {
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasStatus(StatusData.unset())
.hasAttributes(Attributes.empty()),
.hasAttributesSatisfying(
attrs ->
assertThat(attrs)
.containsEntry(
SemanticAttributes.CODE_NAMESPACE,
SuccessfulJob.class.getName())
.containsEntry(
SemanticAttributes.CODE_FUNCTION, "execute")),
span ->
span.hasName("child")
.hasKind(SpanKind.INTERNAL)
Expand All @@ -88,7 +96,14 @@ void failingJob() throws Exception {
.hasNoParent()
.hasStatus(StatusData.error())
.hasException(new IllegalStateException("Bad job"))
.hasAttributes(Attributes.empty())));
.hasAttributesSatisfying(
attrs ->
assertThat(attrs)
.containsEntry(
SemanticAttributes.CODE_NAMESPACE,
FailingJob.class.getName())
.containsEntry(
SemanticAttributes.CODE_FUNCTION, "execute"))));
}

private static Scheduler createScheduler(String name) throws Exception {
Expand Down