Skip to content

Commit 17a0bde

Browse files
authored
Library readmes - batch 2 (#14631)
1 parent fbc58a1 commit 17a0bde

File tree

5 files changed

+303
-0
lines changed

5 files changed

+303
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Library Instrumentation for JMX Metrics
2+
3+
Provides OpenTelemetry instrumentation for [Java Management Extensions (JMX)](https://docs.oracle.com/javase/tutorial/jmx/).
4+
5+
This instrumentation collects JMX-based metrics and exports them as OpenTelemetry metrics.
6+
7+
## Quickstart
8+
9+
### Add these dependencies to your project
10+
11+
Replace `OPENTELEMETRY_VERSION` with the [latest release](https://central.sonatype.com/artifact/io.opentelemetry.instrumentation/opentelemetry-jmx-metrics).
12+
13+
For Maven, add to your `pom.xml` dependencies:
14+
15+
```xml
16+
<dependencies>
17+
<dependency>
18+
<groupId>io.opentelemetry.instrumentation</groupId>
19+
<artifactId>opentelemetry-jmx-metrics</artifactId>
20+
<version>OPENTELEMETRY_VERSION</version>
21+
</dependency>
22+
</dependencies>
23+
```
24+
25+
For Gradle, add to your dependencies:
26+
27+
```kotlin
28+
implementation("io.opentelemetry.instrumentation:opentelemetry-jmx-metrics:OPENTELEMETRY_VERSION")
29+
```
30+
31+
### Usage
32+
33+
```java
34+
import io.opentelemetry.api.OpenTelemetry;
35+
import io.opentelemetry.instrumentation.jmx.engine.JmxMetricInsight;
36+
import io.opentelemetry.instrumentation.jmx.engine.MetricConfiguration;
37+
38+
// Get an OpenTelemetry instance
39+
OpenTelemetry openTelemetry = ...;
40+
41+
JmxMetricInsight jmxMetricInsight = JmxMetricInsight.createService(openTelemetry, 5000);
42+
43+
// Configure your JMX metrics
44+
MetricConfiguration config = new MetricConfiguration();
45+
46+
jmxMetricInsight.startLocal(config);
47+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Library Instrumentation for Lettuce version 5.1 and higher
2+
3+
Provides OpenTelemetry instrumentation for [Lettuce](https://lettuce.io/), enabling database client
4+
spans and metrics.
5+
6+
## Quickstart
7+
8+
### Add these dependencies to your project
9+
10+
Replace `OPENTELEMETRY_VERSION` with the [latest release](https://central.sonatype.com/artifact/io.opentelemetry.instrumentation/opentelemetry-lettuce-5.1).
11+
12+
For Maven, add to your `pom.xml` dependencies:
13+
14+
```xml
15+
<dependencies>
16+
<dependency>
17+
<groupId>io.opentelemetry.instrumentation</groupId>
18+
<artifactId>opentelemetry-lettuce-5.1</artifactId>
19+
<version>OPENTELEMETRY_VERSION</version>
20+
</dependency>
21+
</dependencies>
22+
```
23+
24+
For Gradle, add to your dependencies:
25+
26+
```kotlin
27+
implementation("io.opentelemetry.instrumentation:opentelemetry-lettuce-5.1:OPENTELEMETRY_VERSION")
28+
```
29+
30+
### Usage
31+
32+
```java
33+
import io.lettuce.core.RedisClient;
34+
import io.lettuce.core.api.StatefulRedisConnection;
35+
import io.lettuce.core.resource.ClientResources;
36+
import io.opentelemetry.api.OpenTelemetry;
37+
import io.opentelemetry.instrumentation.lettuce.v5_1.LettuceTelemetry;
38+
39+
// Get an OpenTelemetry instance
40+
OpenTelemetry openTelemetry = ...;
41+
42+
LettuceTelemetry lettuceTelemetry = LettuceTelemetry.create(openTelemetry);
43+
44+
ClientResources clientResources = ClientResources.builder()
45+
.tracing(lettuceTelemetry.newTracing())
46+
.build();
47+
48+
RedisClient redisClient = RedisClient.create(clientResources, "redis://localhost:6379");
49+
StatefulRedisConnection<String, String> connection = redisClient.connect();
50+
```
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Library Instrumentation for Netty version 4.1 and higher
2+
3+
Provides OpenTelemetry instrumentation for [Netty](https://netty.io/), enabling HTTP client and
4+
server spans and metrics.
5+
6+
## Quickstart
7+
8+
### Add these dependencies to your project
9+
10+
Replace `OPENTELEMETRY_VERSION` with the [latest release](https://central.sonatype.com/artifact/io.opentelemetry.instrumentation/opentelemetry-netty-4.1).
11+
12+
For Maven, add to your `pom.xml` dependencies:
13+
14+
```xml
15+
<dependencies>
16+
<dependency>
17+
<groupId>io.opentelemetry.instrumentation</groupId>
18+
<artifactId>opentelemetry-netty-4.1</artifactId>
19+
<version>OPENTELEMETRY_VERSION</version>
20+
</dependency>
21+
</dependencies>
22+
```
23+
24+
For Gradle, add to your dependencies:
25+
26+
```kotlin
27+
implementation("io.opentelemetry.instrumentation:opentelemetry-netty-4.1:OPENTELEMETRY_VERSION")
28+
```
29+
30+
### Usage
31+
32+
#### HTTP Client
33+
34+
```java
35+
import io.netty.bootstrap.Bootstrap;
36+
import io.netty.channel.Channel;
37+
import io.netty.channel.ChannelInitializer;
38+
import io.netty.channel.EventLoopGroup;
39+
import io.netty.channel.socket.SocketChannel;
40+
import io.netty.handler.codec.http.HttpClientCodec;
41+
import io.opentelemetry.api.OpenTelemetry;
42+
import io.opentelemetry.context.Context;
43+
import io.opentelemetry.instrumentation.netty.v4_1.NettyClientTelemetry;
44+
45+
// Get an OpenTelemetry instance
46+
OpenTelemetry openTelemetry = ...;
47+
48+
NettyClientTelemetry clientTelemetry = NettyClientTelemetry.create(openTelemetry);
49+
50+
EventLoopGroup eventLoopGroup = ...; // Use appropriate EventLoopGroup for your platform
51+
Class<? extends Channel> channelClass = ...; // Use appropriate Channel class for your platform
52+
53+
Bootstrap bootstrap = new Bootstrap();
54+
bootstrap.group(eventLoopGroup)
55+
.channel(channelClass)
56+
.handler(new ChannelInitializer<SocketChannel>() {
57+
@Override
58+
protected void initChannel(SocketChannel ch) {
59+
ch.pipeline()
60+
.addLast(new HttpClientCodec())
61+
.addLast(clientTelemetry.createCombinedHandler())
62+
.addLast(new YourClientHandler()); // Your application handler
63+
}
64+
});
65+
66+
Channel channel = bootstrap.connect("localhost", 8080).sync().channel();
67+
NettyClientTelemetry.setChannelContext(channel, Context.current());
68+
```
69+
70+
#### HTTP Server
71+
72+
```java
73+
import io.netty.bootstrap.ServerBootstrap;
74+
import io.netty.channel.ChannelInitializer;
75+
import io.netty.channel.EventLoopGroup;
76+
import io.netty.channel.ServerChannel;
77+
import io.netty.channel.socket.SocketChannel;
78+
import io.netty.handler.codec.http.HttpServerCodec;
79+
import io.opentelemetry.api.OpenTelemetry;
80+
import io.opentelemetry.instrumentation.netty.v4_1.NettyServerTelemetry;
81+
82+
// Get an OpenTelemetry instance
83+
OpenTelemetry openTelemetry = ...;
84+
85+
NettyServerTelemetry serverTelemetry = NettyServerTelemetry.create(openTelemetry);
86+
87+
EventLoopGroup bossGroup = ...; // Use appropriate EventLoopGroup for your platform
88+
EventLoopGroup workerGroup = ...; // Use appropriate EventLoopGroup for your platform
89+
Class<? extends ServerChannel> serverChannelClass = ...; // Use appropriate ServerChannel class for your platform
90+
91+
ServerBootstrap bootstrap = new ServerBootstrap();
92+
bootstrap.group(bossGroup, workerGroup)
93+
.channel(serverChannelClass)
94+
.childHandler(new ChannelInitializer<SocketChannel>() {
95+
@Override
96+
protected void initChannel(SocketChannel ch) {
97+
ch.pipeline()
98+
.addLast(new HttpServerCodec())
99+
.addLast(serverTelemetry.createCombinedHandler())
100+
.addLast(new YourServerHandler()); // Your application handler
101+
}
102+
});
103+
104+
bootstrap.bind(8080).sync();
105+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Library Instrumentation for OSHI version 5.3.1 and higher
2+
3+
Provides OpenTelemetry instrumentation for [OSHI](https://github.com/oshi/oshi).
4+
5+
This instrumentation collects system metrics such as memory usage, network I/O, and disk operations.
6+
7+
## Quickstart
8+
9+
### Add these dependencies to your project
10+
11+
Replace `OPENTELEMETRY_VERSION` with the [latest release](https://central.sonatype.com/artifact/io.opentelemetry.instrumentation/opentelemetry-oshi).
12+
13+
For Maven, add to your `pom.xml` dependencies:
14+
15+
```xml
16+
<dependencies>
17+
<dependency>
18+
<groupId>io.opentelemetry.instrumentation</groupId>
19+
<artifactId>opentelemetry-oshi</artifactId>
20+
<version>OPENTELEMETRY_VERSION</version>
21+
</dependency>
22+
</dependencies>
23+
```
24+
25+
For Gradle, add to your dependencies:
26+
27+
```kotlin
28+
implementation("io.opentelemetry.instrumentation:opentelemetry-oshi:OPENTELEMETRY_VERSION")
29+
```
30+
31+
### Usage
32+
33+
```java
34+
import io.opentelemetry.api.OpenTelemetry;
35+
import io.opentelemetry.instrumentation.oshi.SystemMetrics;
36+
import java.util.List;
37+
38+
// Get an OpenTelemetry instance
39+
OpenTelemetry openTelemetry = ...;
40+
41+
List<AutoCloseable> observables = SystemMetrics.registerObservers(openTelemetry);
42+
43+
// The observers will automatically collect and export system metrics
44+
// Close the observables when shutting down your application
45+
observables.forEach(observable -> {
46+
try {
47+
observable.close();
48+
} catch (Exception e) {
49+
// Handle exception
50+
}
51+
});
52+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Library Instrumentation for Quartz version 2.0 and higher
2+
3+
Provides OpenTelemetry instrumentation for [Quartz Scheduler](https://www.quartz-scheduler.org/),
4+
enabling job execution spans.
5+
6+
## Quickstart
7+
8+
### Add these dependencies to your project
9+
10+
Replace `OPENTELEMETRY_VERSION` with the [latest release](https://central.sonatype.com/artifact/io.opentelemetry.instrumentation/opentelemetry-quartz-2.0).
11+
12+
For Maven, add to your `pom.xml` dependencies:
13+
14+
```xml
15+
<dependencies>
16+
<dependency>
17+
<groupId>io.opentelemetry.instrumentation</groupId>
18+
<artifactId>opentelemetry-quartz-2.0</artifactId>
19+
<version>OPENTELEMETRY_VERSION</version>
20+
</dependency>
21+
</dependencies>
22+
```
23+
24+
For Gradle, add to your dependencies:
25+
26+
```kotlin
27+
implementation("io.opentelemetry.instrumentation:opentelemetry-quartz-2.0:OPENTELEMETRY_VERSION")
28+
```
29+
30+
### Usage
31+
32+
```java
33+
import io.opentelemetry.api.OpenTelemetry;
34+
import io.opentelemetry.instrumentation.quartz.v2_0.QuartzTelemetry;
35+
import org.quartz.Scheduler;
36+
import org.quartz.SchedulerException;
37+
import org.quartz.impl.StdSchedulerFactory;
38+
39+
// Get an OpenTelemetry instance
40+
OpenTelemetry openTelemetry = ...;
41+
42+
QuartzTelemetry quartzTelemetry = QuartzTelemetry.create(openTelemetry);
43+
44+
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
45+
quartzTelemetry.configure(scheduler);
46+
47+
scheduler.start();
48+
// Schedule your jobs - they will now be traced with OpenTelemetry
49+
```

0 commit comments

Comments
 (0)