-
|
We have the requirement that we need to be able to send gRPC requests to arbitrary hosts (the hostname/port to send the message to are part of the user request essentially). Since Quarkus only supports pointing gRPC clients towards static hosts, we have the following bit of code: suspend fun runAction(endpoint: RuntimeEndpoint, request: RunActionRequest): RunActionResponse {
val channel = ManagedChannelBuilder.forAddress(
endpoint.host,
endpoint.port,
).usePlaintext().build()
val stub = ActionServiceGrpc.newBlockingStub(channel)
return try {
withTimeout(request.limits.wallTime * 60) {
stub.runAction(request)
}
} finally {
channel.shutdown()
}
}However we would really like to add otel tracing to this like the managed gRPC clients by Quarkus have. I have tried to look through the documentation and the code, but found it all a bit much and hard to grasp. Would you perhaps have any pointers for how I can integrate this with the Quarkus otel tracing like the Quarkus managed gRPC clients have? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
/cc @alesj (grpc), @brunobat (opentelemetry), @cescoffier (grpc), @geoand (kotlin), @radcortez (opentelemetry) |
Beta Was this translation helpful? Give feedback.
-
|
Actually I managed to solve it! For anyone else who is trying to do a similar thing, it's as simple as: @ApplicationScoped
class ActionRunner {
@Inject
private lateinit var otelTracingInterceptor: GrpcTracingClientInterceptor
/**
* Runs an action on a runtime.
*
* @param endpoint The endpoint to send the action gRPC request to.
* @param request The request to run against the runtime.
*
* @return The response from the runtime.
*/
suspend fun runAction(endpoint: RuntimeEndpoint, request: RunActionRequest): RunActionResponse {
val channel = Grpc
.newChannelBuilderForAddress(endpoint.host, endpoint.port, InsecureChannelCredentials.create())
.build()
val stub = ActionServiceGrpc.newBlockingStub(channel).withInterceptors(
otelTracingInterceptor
)
return try {
withTimeout(request.limits.wallTime * 60) {
stub.runAction(request)
}
} finally {
channel.shutdown()
}
}
}You just inject Quarkus' |
Beta Was this translation helpful? Give feedback.
Actually I managed to solve it!
For anyone else who is trying to do a similar thing, it's as simple as: