Skip to content

ObservationGrpcServerInterceptor does not store observation in a context #4218

@AleksanderBrzozowski

Description

@AleksanderBrzozowski

Please describe the feature request.
Let's say that we have a gRPC server written in kotlin with coroutines support enabled:

class ExampleServer(private val registry: ObservationRegistry) :ServiceGrpcKt.CoroutineImplBase() {
    override suspend fun exampleMethod(request: Request): Response {
        // logic
    }

And let's assume that ObservationGrpcServerInterceptor was added as an interceptor.

When we try to get the current observation from the registry, it always return null, which is expected as suspended function are ran in a different thread:

override suspend fun exampleMethod(request: Request): Response {
    this.registry.currentObservation // returns null
}

I wonder how we can fix this, so that we can get the current observation the same as we do for blocking API.

It would be nice if the existing function could be used to retrieve the current observation created by the interceptor:

class ExampleServer(private val registry: ObservationRegistry) :ServiceGrpcKt.CoroutineImplBase() {
    override suspend fun exampleMethod(request: Request): Response {
        coroutineContext.currentObservation()
    }

Rationale
It is currently not possible to create a child observation based on the parent one that was created in the gRPC Server Interceptor.

Additional context
#3256

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions