Skip to content
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
Expand Up @@ -14,14 +14,18 @@
* library/framework. It will be used by the {@link RpcClientAttributesExtractor} or {@link
* RpcServerAttributesExtractor} to obtain the various RPC attributes in a type-generic way.
*/
public interface RpcAttributesGetter<REQUEST> {
public interface RpcAttributesGetter<REQUEST, RESPONSE> {

@Nullable
String getSystem(REQUEST request);

@Nullable
String getService(REQUEST request);

/**
* @deprecated Use {@link #getRpcMethod(REQUEST)} for stable semconv.
*/
@Deprecated
@Nullable
String getMethod(REQUEST request);

Expand All @@ -34,4 +38,35 @@ default Long getRequestSize(REQUEST request) {
default Long getResponseSize(REQUEST request) {
return null;
}

/**
* Returns the fully-qualified RPC method name for stable semconv.
*
* @param request the request object
* @return the fully-qualified RPC method name (e.g., "my.Service/Method"), or null if service or
* method is unavailable
*/
@Nullable
default String getRpcMethod(REQUEST request) {
return null;
}

/**
* Returns a description of a class of error the operation ended with.
*
* <p>This method should return {@code null} if there was no error.
*
* <p>If this method is not implemented, or if it returns {@code null}, the exception class name
* will be used as error type.
*
* <p>The cardinality of the error type should be low. The instrumentations implementing this
* method are recommended to document the custom values they support.
*
* <p>Examples: {@code OK}, {@code CANCELLED}, {@code UNKNOWN}, {@code -32602}
*/
@Nullable
default String getErrorType(
REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public final class RpcClientAttributesExtractor<REQUEST, RESPONSE>

/** Creates the RPC client attributes extractor. */
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
RpcAttributesGetter<REQUEST> getter) {
RpcAttributesGetter<REQUEST, RESPONSE> getter) {
return new RpcClientAttributesExtractor<>(getter);
}

private RpcClientAttributesExtractor(RpcAttributesGetter<REQUEST> getter) {
private RpcClientAttributesExtractor(RpcAttributesGetter<REQUEST, RESPONSE> getter) {
super(getter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ abstract class RpcCommonAttributesExtractor<REQUEST, RESPONSE>
static final AttributeKey<String> RPC_SERVICE = AttributeKey.stringKey("rpc.service");
static final AttributeKey<String> RPC_SYSTEM = AttributeKey.stringKey("rpc.system");

private final RpcAttributesGetter<REQUEST> getter;
private final RpcAttributesGetter<REQUEST, RESPONSE> getter;

RpcCommonAttributesExtractor(RpcAttributesGetter<REQUEST> getter) {
RpcCommonAttributesExtractor(RpcAttributesGetter<REQUEST, RESPONSE> getter) {
this.getter = getter;
}

@SuppressWarnings("deprecation") // for getMethod()
@Override
public final void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalSet(attributes, RPC_SYSTEM, getter.getSystem(request));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public final class RpcServerAttributesExtractor<REQUEST, RESPONSE>

/** Creates the RPC server attributes extractor. */
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
RpcAttributesGetter<REQUEST> getter) {
RpcAttributesGetter<REQUEST, RESPONSE> getter) {
return new RpcServerAttributesExtractor<>(getter);
}

private RpcServerAttributesExtractor(RpcAttributesGetter<REQUEST> getter) {
private RpcServerAttributesExtractor(RpcAttributesGetter<REQUEST, RESPONSE> getter) {
super(getter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public final class RpcSizeAttributesExtractor<REQUEST, RESPONSE>
static final AttributeKey<Long> RPC_REQUEST_SIZE = AttributeKey.longKey("rpc.request.size");
static final AttributeKey<Long> RPC_RESPONSE_SIZE = AttributeKey.longKey("rpc.response.size");

private final RpcAttributesGetter<REQUEST> getter;
private final RpcAttributesGetter<REQUEST, RESPONSE> getter;

RpcSizeAttributesExtractor(RpcAttributesGetter<REQUEST> getter) {
RpcSizeAttributesExtractor(RpcAttributesGetter<REQUEST, RESPONSE> getter) {
this.getter = getter;
}

Expand All @@ -30,7 +30,7 @@ public final class RpcSizeAttributesExtractor<REQUEST, RESPONSE>
* attributesGetter} instance to determine the request and response size.
*/
public static <REQUEST, RESPONSE> RpcSizeAttributesExtractor<REQUEST, RESPONSE> create(
RpcAttributesGetter<REQUEST> attributesGetter) {
RpcAttributesGetter<REQUEST, RESPONSE> attributesGetter) {
return new RpcSizeAttributesExtractor<>(attributesGetter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ public final class RpcSpanNameExtractor<REQUEST> implements SpanNameExtractor<RE
* conventions: {@code <rpc.service>/<rpc.method>}.
*/
public static <REQUEST> SpanNameExtractor<REQUEST> create(
RpcAttributesGetter<REQUEST> attributesExtractor) {
RpcAttributesGetter<REQUEST, ?> attributesExtractor) {
return new RpcSpanNameExtractor<>(attributesExtractor);
}

private final RpcAttributesGetter<REQUEST> getter;
private final RpcAttributesGetter<REQUEST, ?> getter;

private RpcSpanNameExtractor(RpcAttributesGetter<REQUEST> getter) {
private RpcSpanNameExtractor(RpcAttributesGetter<REQUEST, ?> getter) {
this.getter = getter;
}

@SuppressWarnings("deprecation") // for getMethod()
@Override
public String extract(REQUEST request) {
String service = getter.getService(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@SuppressWarnings("deprecation") // using deprecated semconv
class RpcAttributesExtractorTest {

enum TestGetter implements RpcAttributesGetter<Map<String, String>> {
enum TestGetter implements RpcAttributesGetter<Map<String, String>, Void> {
INSTANCE;

@Override
Expand All @@ -33,6 +33,7 @@ public String getService(Map<String, String> request) {
return request.get("service");
}

@Deprecated
@Override
public String getMethod(Map<String, String> request) {
return request.get("method");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
@ExtendWith(MockitoExtension.class)
class RpcSpanNameExtractorTest {

@Mock RpcAttributesGetter<RpcRequest> getter;
@Mock RpcAttributesGetter<RpcRequest, Void> getter;

@SuppressWarnings("deprecation") // testing deprecated method
@Test
void normal() {
RpcRequest request = new RpcRequest();
Expand All @@ -30,6 +31,7 @@ void normal() {
assertThat(extractor.extract(request)).isEqualTo("my.Service/Method");
}

@SuppressWarnings("deprecation") // testing deprecated method
@Test
void serviceNull() {
RpcRequest request = new RpcRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
package io.opentelemetry.instrumentation.apachedubbo.v2_7;

import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcAttributesGetter;
import org.apache.dubbo.rpc.Result;

enum DubboRpcAttributesGetter implements RpcAttributesGetter<DubboRequest> {
enum DubboRpcAttributesGetter implements RpcAttributesGetter<DubboRequest, Result> {
INSTANCE;

@Override
Expand All @@ -20,6 +21,7 @@ public String getService(DubboRequest request) {
return request.invocation().getInvoker().getInterface().getName();
}

@Deprecated
@Override
public String getMethod(DubboRequest request) {
return request.invocation().getMethodName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
package io.opentelemetry.instrumentation.awssdk.v1_11;

import com.amazonaws.Request;
import com.amazonaws.Response;
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcAttributesGetter;

enum AwsSdkRpcAttributesGetter implements RpcAttributesGetter<Request<?>> {
enum AwsSdkRpcAttributesGetter implements RpcAttributesGetter<Request<?>, Response<?>> {
INSTANCE;

private static final ClassValue<String> OPERATION_NAME =
Expand Down Expand Up @@ -37,6 +38,7 @@ public String getService(Request<?> request) {
return request.getServiceName();
}

@Deprecated
@Override
public String getMethod(Request<?> request) {
return OPERATION_NAME.get(request.getOriginalRequest().getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AwsSdkSpanNameExtractor implements SpanNameExtractor<Request<?>> {
private static final AwsSdkRpcAttributesGetter rpcAttributes = AwsSdkRpcAttributesGetter.INSTANCE;
private final NamesCache namesCache = new NamesCache();

@SuppressWarnings("deprecation") // for getMethod()
@Override
public String extract(Request<?> request) {
return qualifiedOperation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;

enum AwsSdkRpcAttributesGetter implements RpcAttributesGetter<ExecutionAttributes> {
enum AwsSdkRpcAttributesGetter implements RpcAttributesGetter<ExecutionAttributes, Response> {
INSTANCE;

@Override
Expand All @@ -22,6 +22,7 @@ public String getService(ExecutionAttributes request) {
return request.getAttribute(SdkExecutionAttribute.SERVICE_NAME);
}

@Deprecated
@Override
public String getMethod(ExecutionAttributes request) {
return request.getAttribute(SdkExecutionAttribute.OPERATION_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
package io.opentelemetry.instrumentation.grpc.v1_6;

import io.grpc.Metadata;
import io.grpc.Status;
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcAttributesGetter;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import javax.annotation.Nullable;

enum GrpcRpcAttributesGetter implements RpcAttributesGetter<GrpcRequest> {
enum GrpcRpcAttributesGetter implements RpcAttributesGetter<GrpcRequest, Status> {
INSTANCE;

@Override
Expand All @@ -32,6 +33,7 @@ public String getService(GrpcRequest request) {
return fullMethodName.substring(0, slashIndex);
}

@Deprecated
@Override
@Nullable
public String getMethod(GrpcRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcAttributesGetter;
import java.lang.reflect.Method;

enum GwtRpcAttributesGetter implements RpcAttributesGetter<Method> {
enum GwtRpcAttributesGetter implements RpcAttributesGetter<Method, Void> {
INSTANCE;

@Override
Expand All @@ -21,6 +21,7 @@ public String getService(Method method) {
return method.getDeclaringClass().getName();
}

@Deprecated
@Override
public String getMethod(Method method) {
return method.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcAttributesGetter;
import java.lang.reflect.Method;

enum RmiClientAttributesGetter implements RpcAttributesGetter<Method> {
enum RmiClientAttributesGetter implements RpcAttributesGetter<Method, Void> {
INSTANCE;

@Override
Expand All @@ -21,6 +21,7 @@ public String getService(Method method) {
return method.getDeclaringClass().getName();
}

@Deprecated
@Override
public String getMethod(Method method) {
return method.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcAttributesGetter;
import io.opentelemetry.instrumentation.api.incubator.semconv.util.ClassAndMethod;

enum RmiServerAttributesGetter implements RpcAttributesGetter<ClassAndMethod> {
enum RmiServerAttributesGetter implements RpcAttributesGetter<ClassAndMethod, Void> {
INSTANCE;

@Override
Expand All @@ -21,6 +21,7 @@ public String getService(ClassAndMethod classAndMethod) {
return classAndMethod.declaringClass().getName();
}

@Deprecated
@Override
public String getMethod(ClassAndMethod classAndMethod) {
return classAndMethod.methodName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcAttributesGetter;
import java.lang.reflect.Method;

public enum ClientAttributesGetter implements RpcAttributesGetter<Method> {
public enum ClientAttributesGetter implements RpcAttributesGetter<Method, Void> {
INSTANCE;

@Override
Expand All @@ -21,6 +21,7 @@ public String getService(Method method) {
return method.getDeclaringClass().getName();
}

@Deprecated
@Override
public String getMethod(Method method) {
return method.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcAttributesGetter;
import io.opentelemetry.instrumentation.api.incubator.semconv.util.ClassAndMethod;

public enum ServerAttributesGetter implements RpcAttributesGetter<ClassAndMethod> {
public enum ServerAttributesGetter implements RpcAttributesGetter<ClassAndMethod, Void> {
INSTANCE;

@Override
Expand All @@ -21,6 +21,7 @@ public String getService(ClassAndMethod classAndMethod) {
return classAndMethod.declaringClass().getName();
}

@Deprecated
@Override
public String getMethod(ClassAndMethod classAndMethod) {
return classAndMethod.methodName();
Expand Down
Loading