|
17 | 17 | package io.opentelemetry.javaagent.instrumentation.hypertrace.netty.v4_0; |
18 | 18 |
|
19 | 19 | import io.netty.util.AttributeKey; |
20 | | -import io.opentelemetry.javaagent.instrumentation.api.WeakMap; |
21 | 20 | import java.util.Map; |
22 | | -import java.util.concurrent.ConcurrentHashMap; |
23 | | -import java.util.concurrent.ConcurrentMap; |
24 | 21 | import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes; |
25 | 22 | import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream; |
26 | 23 |
|
27 | | -/** |
28 | | - * Copied from |
29 | | - * https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/deda1af9c0e420b882164e5f8240b51678cd646f/instrumentation/netty/netty-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v4_0/AttributeKeys.java#L14 |
30 | | - */ |
31 | 24 | public class AttributeKeys { |
32 | | - private static final WeakMap<ClassLoader, ConcurrentMap<String, AttributeKey<?>>> map = |
33 | | - WeakMap.Implementation.DEFAULT.get(); |
34 | | - private static final WeakMap.ValueSupplier<ClassLoader, ConcurrentMap<String, AttributeKey<?>>> |
35 | | - mapSupplier = |
36 | | - new WeakMap.ValueSupplier<ClassLoader, ConcurrentMap<String, AttributeKey<?>>>() { |
37 | | - @Override |
38 | | - public ConcurrentMap<String, AttributeKey<?>> get(ClassLoader ignore) { |
39 | | - return new ConcurrentHashMap<>(); |
40 | | - } |
41 | | - }; |
42 | | - |
43 | 25 | public static final AttributeKey<BoundedByteArrayOutputStream> RESPONSE_BODY_BUFFER = |
44 | | - attributeKey(HypertraceSemanticAttributes.HTTP_RESPONSE_BODY.getKey()); |
| 26 | + io.opentelemetry.javaagent.instrumentation.netty.v4_0.AttributeKeys.attributeKey( |
| 27 | + HypertraceSemanticAttributes.HTTP_RESPONSE_BODY.getKey()); |
45 | 28 |
|
46 | 29 | public static final AttributeKey<BoundedByteArrayOutputStream> REQUEST_BODY_BUFFER = |
47 | | - attributeKey(HypertraceSemanticAttributes.HTTP_REQUEST_BODY.getKey()); |
| 30 | + io.opentelemetry.javaagent.instrumentation.netty.v4_0.AttributeKeys.attributeKey( |
| 31 | + HypertraceSemanticAttributes.HTTP_REQUEST_BODY.getKey()); |
48 | 32 |
|
49 | 33 | public static final AttributeKey<Map<String, String>> REQUEST_HEADERS = |
50 | | - attributeKey(AttributeKeys.class.getName() + ".request-headers"); |
51 | | - |
52 | | - /** |
53 | | - * Generate an attribute key or reuse the one existing in the global app map. This implementation |
54 | | - * creates attributes only once even if the current class is loaded by several class loaders and |
55 | | - * prevents an issue with Apache Atlas project were this class loaded by multiple class loaders, |
56 | | - * while the Attribute class is loaded by a third class loader and used internally for the |
57 | | - * cassandra driver. |
58 | | - */ |
59 | | - private static <T> AttributeKey<T> attributeKey(String key) { |
60 | | - ConcurrentMap<String, AttributeKey<?>> classLoaderMap = |
61 | | - map.computeIfAbsent(AttributeKey.class.getClassLoader(), mapSupplier); |
62 | | - if (classLoaderMap.containsKey(key)) { |
63 | | - @SuppressWarnings("unchecked") |
64 | | - AttributeKey<T> attrKey = (AttributeKey<T>) classLoaderMap.get(key); |
65 | | - return attrKey; |
66 | | - } |
67 | | - |
68 | | - AttributeKey<T> value = new AttributeKey<>(key); |
69 | | - classLoaderMap.put(key, value); |
70 | | - return value; |
71 | | - } |
| 34 | + io.opentelemetry.javaagent.instrumentation.netty.v4_0.AttributeKeys.attributeKey( |
| 35 | + AttributeKeys.class.getName() + ".request-headers"); |
72 | 36 | } |
0 commit comments