Better span names for spring-data (#263)
This commit is contained in:
parent
a101e3a5de
commit
3233b9bef4
|
@ -18,7 +18,6 @@ package springdata
|
|||
import io.opentelemetry.auto.instrumentation.api.MoreTags
|
||||
import io.opentelemetry.auto.instrumentation.api.Tags
|
||||
import io.opentelemetry.auto.test.AgentTestRunner
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import spock.lang.Shared
|
||||
|
||||
|
@ -81,18 +80,13 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
|
|||
and:
|
||||
assertTraces(1) {
|
||||
trace(0, 2) {
|
||||
sortSpans {
|
||||
sort(spans)
|
||||
}
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "CrudRepository.findAll"
|
||||
spanKind INTERNAL
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "CrudRepository.findAll"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
||||
span(1) {
|
||||
operationName "elasticsearch.query"
|
||||
spanKind CLIENT
|
||||
|
@ -126,14 +120,10 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
|
|||
and:
|
||||
assertTraces(1) {
|
||||
trace(0, 4) {
|
||||
sortSpans {
|
||||
sort(spans)
|
||||
}
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "ElasticsearchRepository.index"
|
||||
spanKind INTERNAL
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "ElasticsearchRepository.index"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
@ -197,18 +187,13 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
|
|||
and:
|
||||
assertTraces(1) {
|
||||
trace(0, 2) {
|
||||
sortSpans {
|
||||
sort(spans)
|
||||
}
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "CrudRepository.findById"
|
||||
spanKind INTERNAL
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "CrudRepository.findById"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
||||
span(1) {
|
||||
operationName "elasticsearch.query"
|
||||
spanKind CLIENT
|
||||
|
@ -240,14 +225,10 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
|
|||
and:
|
||||
assertTraces(2) {
|
||||
trace(0, 3) {
|
||||
sortSpans {
|
||||
sort(spans)
|
||||
}
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "ElasticsearchRepository.index"
|
||||
spanKind INTERNAL
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "ElasticsearchRepository.index"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
@ -290,18 +271,13 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
|
|||
}
|
||||
}
|
||||
trace(1, 2) {
|
||||
sortSpans {
|
||||
sort(spans)
|
||||
}
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "CrudRepository.findById"
|
||||
spanKind INTERNAL
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "CrudRepository.findById"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
||||
span(1) {
|
||||
operationName "elasticsearch.query"
|
||||
spanKind CLIENT
|
||||
|
@ -332,18 +308,13 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
|
|||
and:
|
||||
assertTraces(2) {
|
||||
trace(0, 3) {
|
||||
sortSpans {
|
||||
sort(spans)
|
||||
}
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "CrudRepository.deleteById"
|
||||
spanKind INTERNAL
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "CrudRepository.deleteById"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
||||
span(1) {
|
||||
operationName "elasticsearch.query"
|
||||
spanKind CLIENT
|
||||
|
@ -383,18 +354,13 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
|
|||
}
|
||||
|
||||
trace(1, 2) {
|
||||
sortSpans {
|
||||
sort(spans)
|
||||
}
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "CrudRepository.findAll"
|
||||
spanKind INTERNAL
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "CrudRepository.findAll"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
||||
span(1) {
|
||||
operationName "elasticsearch.query"
|
||||
spanKind CLIENT
|
||||
|
@ -416,13 +382,4 @@ class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
|
|||
where:
|
||||
indexName = "test-index"
|
||||
}
|
||||
|
||||
def sort(List<SpanData> spans) {
|
||||
// need to normalize span ordering since they are finished by different threads
|
||||
if (spans[1].name == "repository.operation") {
|
||||
def tmp = spans[1]
|
||||
spans[1] = spans[0]
|
||||
spans[0] = tmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,10 +17,7 @@ package io.opentelemetry.auto.instrumentation.springdata;
|
|||
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.auto.bootstrap.instrumentation.decorator.ClientDecorator;
|
||||
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class SpringDataDecorator extends ClientDecorator {
|
||||
public static final SpringDataDecorator DECORATE = new SpringDataDecorator();
|
||||
|
@ -39,14 +36,4 @@ public final class SpringDataDecorator extends ClientDecorator {
|
|||
protected String getComponentName() {
|
||||
return "spring-data";
|
||||
}
|
||||
|
||||
public Span onOperation(final Span span, final Method method) {
|
||||
assert span != null;
|
||||
assert method != null;
|
||||
|
||||
if (method != null) {
|
||||
span.setAttribute(MoreTags.RESOURCE_NAME, spanNameForMethod(method));
|
||||
}
|
||||
return span;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,9 +118,8 @@ public final class SpringRepositoryInstrumentation extends Instrumenter.Default
|
|||
return methodInvocation.proceed();
|
||||
}
|
||||
|
||||
final Span span = TRACER.spanBuilder("repository.operation").startSpan();
|
||||
final Span span = TRACER.spanBuilder(DECORATE.spanNameForMethod(invokedMethod)).startSpan();
|
||||
DECORATE.afterStart(span);
|
||||
DECORATE.onOperation(span, invokedMethod);
|
||||
|
||||
final Scope scope = TRACER.withSpan(span);
|
||||
|
||||
|
|
|
@ -70,11 +70,10 @@ class SpringJpaTest extends AgentTestRunner {
|
|||
assertTraces(1) {
|
||||
trace(0, 2) {
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "JpaRepository.findAll"
|
||||
spanKind INTERNAL
|
||||
errored false
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "JpaRepository.findAll"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
@ -105,11 +104,10 @@ class SpringJpaTest extends AgentTestRunner {
|
|||
assertTraces(1) {
|
||||
trace(0, 2) {
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "CrudRepository.save"
|
||||
spanKind INTERNAL
|
||||
errored false
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "CrudRepository.save"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
@ -140,11 +138,10 @@ class SpringJpaTest extends AgentTestRunner {
|
|||
assertTraces(1) {
|
||||
trace(0, 3) {
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "CrudRepository.save"
|
||||
spanKind INTERNAL
|
||||
errored false
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "CrudRepository.save"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
@ -187,11 +184,10 @@ class SpringJpaTest extends AgentTestRunner {
|
|||
assertTraces(1) {
|
||||
trace(0, 2) {
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "JpaCustomerRepository.findByLastName"
|
||||
spanKind INTERNAL
|
||||
errored false
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "JpaCustomerRepository.findByLastName"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
@ -220,11 +216,10 @@ class SpringJpaTest extends AgentTestRunner {
|
|||
assertTraces(1) {
|
||||
trace(0, 3) {
|
||||
span(0) {
|
||||
operationName "repository.operation"
|
||||
operationName "CrudRepository.delete"
|
||||
spanKind INTERNAL
|
||||
errored false
|
||||
tags {
|
||||
"$MoreTags.RESOURCE_NAME" "CrudRepository.delete"
|
||||
"$Tags.COMPONENT" "spring-data"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue