Monitoring GRPC servers on JVM (Kotlin)

Hello all,

We are trying to monitor some services that are written in Kotlin and use GRPC as their API layer.

Before I start adding manual traces everywhere: is there some way I could try and support that in a generic fashion? I assume there is some AOP mechanism or similar used to support things like HTTP. Would it be feasible to do that for the generated GRPC server side code so that we can write the logic once and then just wire it into the services?

I'd be happy to give this idea a go if it sounds feasible and someone points me to the right code base to look at.

Cheers,
Peter

Hi and welcome to the forum :wave:

gRPC is something we do want to support out-of-the-box eventually but we did have the time yet to tackle it. We'd be more than happy to accept a PR for gRPC. See the contributing guide on how to get started.

Cheers,
Felix

Thanks, Felix.

I'm not going to promise anything, but from our point of view that would make sense. I tried using this first to make sure tracing generally works:

fun Tracer.withSpan(name: String, block: () -> Unit) {
    val span = this.buildSpan(name).start()
    this.scopeManager().activate(span).use {
        try {
            block()
        } catch (t: Throwable) {
            Tags.ERROR.set(span, true)
            span.log(
                mapOf(
                    Fields.EVENT to "error",
                    Fields.ERROR_OBJECT to t,
                    Fields.MESSAGE to t.message
                )
            )
            throw t
        }
    }
    span.finish()
}

Wrapping those around each implementation of a GRPC stub looks fine, I'm seeing the spans, including the JDBC queries being tracked.

Am I right to assume that the task basically comes down to wiring this kind of wrapper in via AOP? And that should be it?

Also: do you want me to raise an issue on GitHub to track this?

Cheers,
Peter

We already have an issue here: Support gRPC · Issue #256 · elastic/apm-agent-java · GitHub

Yes, kind-of. The biggest difference is that internally, we don't use the OpenTracing API to create Spans.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.