# Monitoring GRPC servers on JVM (Kotlin)

**URL:** <https://discuss.elastic.co/t/monitoring-grpc-servers-on-jvm-kotlin/204392>\
**Category:** APM\
**Tags:** java\
**Created:** [October 21, 2019, 2:04am UTC](https://discuss.elastic.co/t/monitoring-grpc-servers-on-jvm-kotlin/204392 "2019-10-21T02:04:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterBecker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peterbecker/32/45904_2.png) [@PeterBecker](https://discuss.elastic.co/u/PeterBecker)\
**Post date:** [October 21, 2019, 2:04am UTC](https://discuss.elastic.co/t/monitoring-grpc-servers-on-jvm-kotlin/204392/1 "2019-10-21T02:04:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [October 21, 2019, 8:37am UTC](https://discuss.elastic.co/t/monitoring-grpc-servers-on-jvm-kotlin/204392/2 "2019-10-21T08:37:23Z")

</div>

Hi and welcome to the forum 👋

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](https://github.com/elastic/apm-agent-java/blob/master/CONTRIBUTING.md) on how to get started.

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![PeterBecker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peterbecker/32/45904_2.png) [@PeterBecker](https://discuss.elastic.co/u/PeterBecker)\
**Post date:** [October 23, 2019, 5:52am UTC](https://discuss.elastic.co/t/monitoring-grpc-servers-on-jvm-kotlin/204392/3 "2019-10-23T05:52:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [October 23, 2019, 7:47am UTC](https://discuss.elastic.co/t/monitoring-grpc-servers-on-jvm-kotlin/204392/4 "2019-10-23T07:47:27Z")

</div>

We already have an issue here: [Support gRPC · Issue #256 · elastic/apm-agent-java · GitHub](https://github.com/elastic/apm-agent-java/issues/256)

> [@PeterBecker](#):
>
> 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?

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 13, 2019, 3:47am UTC](https://discuss.elastic.co/t/monitoring-grpc-servers-on-jvm-kotlin/204392/5 "2019-11-13T03:47:27Z")

</div>

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