|
| 1 | +# Library Instrumentation for Ratpack version 1.7 and higher |
| 2 | + |
| 3 | +Provides OpenTelemetry instrumentation for [Ratpack](https://ratpack.io/), enabling CLIENT and SERVER spans. |
| 4 | + |
| 5 | +## Quickstart |
| 6 | + |
| 7 | +### Add these dependencies to your project |
| 8 | + |
| 9 | +Replace `OPENTELEMETRY_VERSION` with the [latest release](https://central.sonatype.com/artifact/io.opentelemetry.instrumentation/opentelemetry-ratpack-1.7). |
| 10 | + |
| 11 | +For Maven, add to your `pom.xml` dependencies: |
| 12 | + |
| 13 | +```xml |
| 14 | +<dependencies> |
| 15 | + <dependency> |
| 16 | + <groupId>io.opentelemetry.instrumentation</groupId> |
| 17 | + <artifactId>opentelemetry-ratpack-1.7</artifactId> |
| 18 | + <version>OPENTELEMETRY_VERSION</version> |
| 19 | + </dependency> |
| 20 | +</dependencies> |
| 21 | +``` |
| 22 | + |
| 23 | +For Gradle, add to your dependencies: |
| 24 | + |
| 25 | +```kotlin |
| 26 | +implementation("io.opentelemetry.instrumentation:opentelemetry-ratpack-1.7:OPENTELEMETRY_VERSION") |
| 27 | +``` |
| 28 | + |
| 29 | +### Usage |
| 30 | + |
| 31 | +```java |
| 32 | +import io.opentelemetry.api.OpenTelemetry; |
| 33 | +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackServerTelemetry; |
| 34 | +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackClientTelemetry; |
| 35 | +import ratpack.server.RatpackServer; |
| 36 | +import ratpack.http.client.HttpClient; |
| 37 | + |
| 38 | +public class RatpackExample { |
| 39 | + public static void main(String[] args) throws Exception { |
| 40 | + OpenTelemetry openTelemetry = OpenTelemetry.noop(); |
| 41 | + |
| 42 | + // Server instrumentation |
| 43 | + RatpackServerTelemetry serverTelemetry = RatpackServerTelemetry.create(openTelemetry); |
| 44 | + RatpackServer.start(server -> { |
| 45 | + server.registryOf(serverTelemetry::configureRegistry); |
| 46 | + server.handlers(chain -> |
| 47 | + chain.get(ctx -> ctx.render("Hello, World!")) |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + // Client instrumentation |
| 52 | + RatpackClientTelemetry clientTelemetry = RatpackClientTelemetry.create(openTelemetry); |
| 53 | + HttpClient instrumentedHttpClient = clientTelemetry.instrument(HttpClient.of(spec -> {})); |
| 54 | + } |
| 55 | +} |
| 56 | +``` |
0 commit comments