opentelemetry-java-instrumentation: Kotlin coroutine missing trace

Describe the bug Code snippet from a gRPC ClientInterceptor:

private fun getOrCreateUuid(userId: String): String {
    ...
    CoroutineScope(AppGlobal.IODispatcher + AppGlobal.ExceptionHandler).launch {
        uuidRepository.save(uuid)
        LOG.debug("Saved user id: {} in the DB", userId)
    }
}

The log statement is missing trace and span, but log statements outside the launch coroutine have trace and span.

Steps to reproduce Launch a coroutine from inside a gRPC ClientInterceptor.

What did you expect to see? Trace and span in the log statements.

What did you see instead? Trace and span missing in the log statements.

What version are you using? v0.9.0

Environment N/A.

Additional context N/A.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 48 (23 by maintainers)

Most upvoted comments

Thanks for the app @asarkar. Since that time, the behavior of the SDK changed to default to being completely no-op - you have to configure the SDK yourself once to set it up. I changed your app to have an implementation dependency on io.opentelemetry:opentelemetry-sdk and modified Application to be

@SpringBootApplication
class Application {
    private val LOG: Logger = LoggerFactory.getLogger(Application::class.java)

    @Bean
    fun openTelemetry(): OpenTelemetry {
        return OpenTelemetrySdk.builder()
            .buildAndRegisterGlobal()
    }

    @Bean
    @GrpcGlobalServerInterceptor
    // Run after MetricCollectingServerInterceptor
    @Order(InterceptorOrder.ORDER_TRACING_METRICS + 1)
    fun tracingServerInterceptor(openTelemetry: OpenTelemetry): ServerInterceptor {
        LOG.info("gRPC server tracing is enabled")
        return TracingServerInterceptor.newInterceptor(openTelemetry.getTracer("grpc"))
    }

    @Bean
    @GrpcGlobalClientInterceptor
    // Run after MetricCollectingClientInterceptor
    @Order(InterceptorOrder.ORDER_TRACING_METRICS + 1)
    fun tracingClientInterceptor(openTelemetry: OpenTelemetry): ClientInterceptor {
        LOG.info("gRPC client tracing is enabled")
        return TracingClientInterceptor.newInterceptor(openTelemetry.getTracer("grpc"))
    }
}

and it seems to work ok.

FYI, in the next release, the entrypoint to gRPC will change to GrpcTracing.create(openTelemetry).newServerInterceptor() / GrpcTracing.create(openTelemetry).newClientInterceptor()

@asarkar The latest snapshots of the SDK include a new artifact, opentelemetry-extension-kotlin which includes the helper method.

https://github.com/open-telemetry/opentelemetry-java/blob/master/extensions/kotlin/src/main/kotlin/io/opentelemetry/extension/kotlin/ContextExtensions.kt