Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traces disappear after calling gRPC with kotlin coroutine and @WithSpan annotation. #6542

Open
flexfrank opened this issue Sep 5, 2022 · 1 comment
Labels
bug Something isn't working repro provided

Comments

@flexfrank
Copy link

Describe the bug

When a suspend function is annotated with @WithSpan and call gRPC, traces disappear after calling gRPC.

Steps to reproduce
Here is an example code.
HelloWorldClient is copied from grpc-kotlin examples.
This logger is configured to display trace and span ids.

import io.grpc.ManagedChannelBuilder
import io.opentelemetry.extension.annotations.WithSpan
import kotlinx.coroutines.runBlocking
import org.slf4j.LoggerFactory

class App {
    companion object {
        private val log = LoggerFactory.getLogger(App::class.java)
    }

    fun run() {
        runBlocking {
            runInner()
        }
    }

    @WithSpan
    private suspend fun runInner() {
        log.info("start run")

        greet()

        log.info("finish run")
    }

    private suspend fun greet() {
        val channel = ManagedChannelBuilder.forAddress("localhost", 50051).usePlaintext().build()
        val client = HelloWorldClient(channel)

        client.use {
            log.info("before gRPC")
            it.greet("world")
            log.info("after gRPC")
        }
    }
}

fun main() {
    App().run()
}

If you annotate run() with @WithSpan instead of runInner(), the logs shows correct traces.

What did you expect to see?
All logs shows the same traces.

What did you see instead?

2022-09-05 15:46:57,329 INFO  [fd4f801b8fdb0d68813b93ec3e6bfe24-9532875b87e3c6f6-01] main App - start run
2022-09-05 15:46:58,044 INFO  [fd4f801b8fdb0d68813b93ec3e6bfe24-9532875b87e3c6f6-01] main App - before gRPC
2022-09-05 15:46:58,822 INFO  [--] main App - after gRPC
2022-09-05 15:46:58,874 INFO  [31410fbdd279d25857f4b0ccaa292ccb-4cd6a61499706ccf-01] main App - finish run

At the "after gRPC" log, the trace disappeared.
The "finish run" log shows newly created trace.

What version are you using?
1.17.0

Environment
Compiler: Corretto-17.0.2.8.1, Kotlin 1.6.20
OS: macOS 12.5.1

Additional context
gRPC Java 1.49.0
gRPC kotlin 1.3.0
protobuf 3.19.4

@flexfrank flexfrank added the bug Something isn't working label Sep 5, 2022
@andrewloux
Copy link

andrewloux commented Sep 8, 2022

This is the same issue @mateuszrzeszutek #6502

I think @flexfrank's repro is a lot more minimal though; I tried to display a variety of scenarios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working repro provided
Projects
None yet
Development

No branches or pull requests

3 participants