Skip to content

Commit 7737a54

Browse files
committed
open-telemetry: for gRPC
- fix #3911
1 parent 03092a1 commit 7737a54

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

docs/asciidoc/modules/opentelemetry.adoc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,55 @@ import io.jooby.opentelemetry.instrumentation.OtelDbScheduler
196196
}
197197
----
198198

199+
==== gRPC
200+
201+
Provides automatic tracing, metrics, and context propagation for gRPC services. It instruments both the embedded `grpc-java` server and loopback channels to ensure seamless distributed traces across your application.
202+
203+
Required dependency:
204+
[dependency, groupId="io.opentelemetry.instrumentation", artifactId="opentelemetry-grpc-1.6", version="${otel-instrumentation.version}"]
205+
.
206+
207+
.gRPC Integration
208+
[source, java, role = "primary"]
209+
----
210+
import io.jooby.grpc.GrpcModule;
211+
import io.opentelemetry.api.OpenTelemetry;
212+
import io.opentelemetry.instrumentation.grpc.v1_6.GrpcTelemetry;
213+
214+
{
215+
install(new OtelModule());
216+
217+
var grpcTelemetry = GrpcTelemetry.create(require(OpenTelemetry.class));
218+
219+
install(new GrpcModule(new GreeterService()
220+
.withServer(server -> server.intercept(grpcTelemetry.newServerInterceptor())) // <1>
221+
.withChannel(channel -> channel.intercept(grpcTelemetry.newClientInterceptor())) // <2>
222+
));
223+
}
224+
----
225+
226+
.Kotlin
227+
[source, kt, role="secondary"]
228+
----
229+
import io.jooby.grpc.GrpcModule
230+
import io.opentelemetry.api.OpenTelemetry
231+
import io.opentelemetry.instrumentation.grpc.v1_6.GrpcTelemetry
232+
233+
{
234+
install(OtelModule())
235+
236+
val grpcTelemetry = GrpcTelemetry.create(require(OpenTelemetry::class.java))
237+
238+
install(GrpcModule(GreeterService())
239+
.withServer { server -> server.intercept(grpcTelemetry.newServerInterceptor()) } // <1>
240+
.withChannel { channel -> channel.intercept(grpcTelemetry.newClientInterceptor()) } // <2>
241+
)
242+
}
243+
----
244+
245+
<1> **`newServerInterceptor()`:** Extracts the distributed trace context from incoming gRPC metadata. It creates a dedicated child span for the specific gRPC method execution, automatically recording its duration and status code when the call completes.
246+
<2> **`newClientInterceptor()`:** Grabs the active trace context (typically started by Jooby's underlying HTTP router) and injects it into the outgoing metadata on the internal loopback channel. This bridges the gap between the HTTP pipeline and the gRPC engine, ensuring a single, unbroken distributed trace.
247+
199248
==== HikariCP
200249

201250
Instruments all registered `HikariDataSource` instances to export critical pool metrics (active/idle connections, timeouts).

0 commit comments

Comments
 (0)