-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out RpcAttributesGetter (#5548)
* Split out RpcAttributesGetter * code review comments * go back to RpcAttributesGetter
- Loading branch information
Mateusz Rzeszutek
authored
Mar 17, 2022
1 parent
2ce764b
commit 1ee60aa
Showing
28 changed files
with
285 additions
and
193 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
64 changes: 0 additions & 64 deletions
64
...in/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractor.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
.../main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesGetter.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,27 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.rpc; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* An interface for getting RPC attributes. | ||
* | ||
* <p>Instrumentation authors will create implementations of this interface for their specific | ||
* 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> { | ||
|
||
@Nullable | ||
String system(REQUEST request); | ||
|
||
@Nullable | ||
String service(REQUEST request); | ||
|
||
@Nullable | ||
String method(REQUEST request); | ||
} |
42 changes: 42 additions & 0 deletions
42
...a/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientAttributesExtractor.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,42 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.rpc; | ||
|
||
import io.opentelemetry.instrumentation.api.annotations.UnstableApi; | ||
import io.opentelemetry.instrumentation.api.internal.SpanKey; | ||
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider; | ||
|
||
/** | ||
* Extractor of <a | ||
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md">RPC | ||
* client attributes</a>. | ||
* | ||
* <p>This class delegates to a type-specific {@link RpcAttributesGetter} for individual attribute | ||
* extraction from request/response objects. | ||
*/ | ||
public final class RpcClientAttributesExtractor<REQUEST, RESPONSE> | ||
extends RpcCommonAttributesExtractor<REQUEST, RESPONSE> implements SpanKeyProvider { | ||
|
||
/** Creates the RPC client attributes extractor. */ | ||
public static <REQUEST, RESPONSE> RpcClientAttributesExtractor<REQUEST, RESPONSE> create( | ||
RpcAttributesGetter<REQUEST> getter) { | ||
return new RpcClientAttributesExtractor<>(getter); | ||
} | ||
|
||
private RpcClientAttributesExtractor(RpcAttributesGetter<REQUEST> getter) { | ||
super(getter); | ||
} | ||
|
||
/** | ||
* This method is internal and is hence not for public use. Its API is unstable and can change at | ||
* any time. | ||
*/ | ||
@UnstableApi | ||
@Override | ||
public SpanKey internalGetSpanKey() { | ||
return SpanKey.RPC_CLIENT; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...a/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcCommonAttributesExtractor.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,39 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.rpc; | ||
|
||
import io.opentelemetry.api.common.AttributesBuilder; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; | ||
import javax.annotation.Nullable; | ||
|
||
abstract class RpcCommonAttributesExtractor<REQUEST, RESPONSE> | ||
implements AttributesExtractor<REQUEST, RESPONSE> { | ||
|
||
private final RpcAttributesGetter<REQUEST> getter; | ||
|
||
RpcCommonAttributesExtractor(RpcAttributesGetter<REQUEST> getter) { | ||
this.getter = getter; | ||
} | ||
|
||
@Override | ||
public final void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { | ||
set(attributes, SemanticAttributes.RPC_SYSTEM, getter.system(request)); | ||
set(attributes, SemanticAttributes.RPC_SERVICE, getter.service(request)); | ||
set(attributes, SemanticAttributes.RPC_METHOD, getter.method(request)); | ||
} | ||
|
||
@Override | ||
public final void onEnd( | ||
AttributesBuilder attributes, | ||
Context context, | ||
REQUEST request, | ||
@Nullable RESPONSE response, | ||
@Nullable Throwable error) { | ||
// No response attributes | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...a/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerAttributesExtractor.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,28 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.rpc; | ||
|
||
/** | ||
* Extractor of <a | ||
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md">RPC | ||
* server attributes</a>. | ||
* | ||
* <p>This class delegates to a type-specific {@link RpcAttributesGetter} for individual attribute | ||
* extraction from request/response objects. | ||
*/ | ||
public final class RpcServerAttributesExtractor<REQUEST, RESPONSE> | ||
extends RpcCommonAttributesExtractor<REQUEST, RESPONSE> { | ||
|
||
/** Creates the RPC server attributes extractor. */ | ||
public static <REQUEST, RESPONSE> RpcServerAttributesExtractor<REQUEST, RESPONSE> create( | ||
RpcAttributesGetter<REQUEST> getter) { | ||
return new RpcServerAttributesExtractor<>(getter); | ||
} | ||
|
||
private RpcServerAttributesExtractor(RpcAttributesGetter<REQUEST> getter) { | ||
super(getter); | ||
} | ||
} |
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
Oops, something went wrong.