-
Notifications
You must be signed in to change notification settings - Fork 883
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Trask Stalnaker <[email protected]>
- Loading branch information
1 parent
ec26d54
commit af2fb23
Showing
15 changed files
with
100 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
6 changes: 5 additions & 1 deletion
6
docs/apidiffs/current_vs_latest/opentelemetry-instrumentation-api.txt
This file contains 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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
Comparing source compatibility of opentelemetry-instrumentation-api-2.13.0-SNAPSHOT.jar against opentelemetry-instrumentation-api-2.12.0.jar | ||
No changes. | ||
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.instrumentation.api.semconv.util.SpanNames (not serializable) | ||
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. | ||
+++ NEW SUPERCLASS: java.lang.Object | ||
+++ NEW METHOD: PUBLIC(+) STATIC(+) java.lang.String fromMethod(java.lang.reflect.Method) | ||
+++ NEW METHOD: PUBLIC(+) STATIC(+) java.lang.String fromMethod(java.lang.Class<?>, java.lang.String) |
This file contains 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
47 changes: 47 additions & 0 deletions
47
...tation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/util/SpanNames.java
This file contains 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,47 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.semconv.util; | ||
|
||
import io.opentelemetry.instrumentation.api.internal.ClassNames; | ||
import io.opentelemetry.instrumentation.api.internal.cache.Cache; | ||
import java.lang.reflect.Method; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** A utility class used to generate span names. */ | ||
public final class SpanNames { | ||
|
||
private static final Cache<Class<?>, Map<String, String>> spanNameCaches = Cache.weak(); | ||
|
||
/** | ||
* This method is used to generate a span name based on a method. Anonymous classes are named | ||
* based on their parent. | ||
*/ | ||
public static String fromMethod(Method method) { | ||
return fromMethod(method.getDeclaringClass(), method.getName()); | ||
} | ||
|
||
/** | ||
* This method is used to generate a span name based on a method. Anonymous classes are named | ||
* based on their parent. | ||
*/ | ||
public static String fromMethod(Class<?> clazz, String methodName) { | ||
// the cache (ConcurrentHashMap) is naturally bounded by the number of methods in a class | ||
Map<String, String> spanNameCache = | ||
spanNameCaches.computeIfAbsent(clazz, c -> new ConcurrentHashMap<>()); | ||
|
||
// not using computeIfAbsent, because it would require a capturing (allocating) lambda | ||
String spanName = spanNameCache.get(methodName); | ||
if (spanName != null) { | ||
return spanName; | ||
} | ||
spanName = ClassNames.simpleName(clazz) + "." + methodName; | ||
spanNameCache.put(methodName, spanName); | ||
return spanName; | ||
} | ||
|
||
private SpanNames() {} | ||
} |
25 changes: 25 additions & 0 deletions
25
...on-api/src/test/java/io/opentelemetry/instrumentation/api/semconv/util/SpanNamesTest.java
This file contains 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,25 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.semconv.util; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.lang.reflect.Method; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class SpanNamesTest { | ||
@Test | ||
void testFromMethod() throws NoSuchMethodException { | ||
Method method = TestClass.class.getMethod("test"); | ||
assertThat(SpanNames.fromMethod(method)).isEqualTo("TestClass.test"); | ||
} | ||
|
||
static class TestClass { | ||
private TestClass() {} | ||
|
||
public void test() {} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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