1
1
# OpenTelemetry-Ktor Demo
2
2
3
- ## Running
4
-
5
- ** Note:** You need to have [ Docker] ( https://www.docker.com/ ) installed and running to run the sample.
6
-
7
- To run a sample, first, execute the following command in an ` opentelemetry ` directory:
8
-
9
- ``` bash
10
- ./gradlew :runWithDocker
11
- ```
12
-
13
- It will start a ` Jaeger ` in the docker container (` Jaeger UI ` available on http://localhost:16686/search ) and
14
- then it will start a ` server ` on http://localhost:8080/
15
-
16
- Then, to run the client, which will send requests to a server, you can execute the following command in
17
- an ` opentelemetry ` directory:
18
-
19
- ``` bash
20
- ./gradlew :client:run
21
- ```
22
-
23
- [ OpenTelemetry] ( https://opentelemetry.io/ ) has support for ` Ktor ` , you can find source
24
- code [ here] ( https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/ktor ) .
25
- It contains plugins for client and server: ` KtorClientTracing ` and ` KtorServerTracing ` .
26
-
27
- ** Note:** In this example, we use
28
- an [ Autoconfiguration OpenTelemetry instance] ( https://opentelemetry.io/docs/languages/java/instrumentation/#automatic-configuration ) ,
29
- we set environment variables ` OTEL_METRICS_EXPORTER ` and ` OTEL_EXPORTER_OTLP_ENDPOINT `
30
- in [ build.gradle.kts] ( ./build.gradle.kts ) file.
31
- You can find more information about these environment variables
32
- in the [ OpenTelemetry documentation] ( https://opentelemetry.io/docs/languages/sdk-configuration/ ) .
3
+ [ OpenTelemetry] ( https://opentelemetry.io/ ) provides support for Ktor with the ` KtorClientTracing ` and ` KtorServerTracing `
4
+ plugins for the Ktor client and server respectively. For the source code, see
5
+ the [ repository on GitHub] ( https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/ktor ) .
33
6
34
- ## Motivation
7
+ This project contains extension functions for plugins that allow you to write code in the Ktor DSL style.
35
8
36
- This project contains extension functions for plugins that allow you to write code in the Ktor DSL style. \
37
- For example, you can rewrite the next code:
9
+ Take the following code as an example:
38
10
39
11
``` kotlin
40
12
install(KtorServerTracing ) {
@@ -56,7 +28,7 @@ install(KtorServerTracing) {
56
28
}
57
29
```
58
30
59
- To a more readable for ` Ktor ` style :
31
+ Rewritten in Ktor DSL style, it looks like the following :
60
32
61
33
``` kotlin
62
34
install(KtorServerTracing ) {
@@ -75,14 +47,41 @@ the [extractions](./client/src/main/kotlin/opentelemetry/ktor/example/plugins/op
75
47
And you can find all extensions for the server plugin ` KtorServerTracing ` in
76
48
the [ extractions] ( ./server/src/main/kotlin/opentelemetry/ktor/example/plugins/opentelemetry/extractions/ ) folder.
77
49
78
- ## Examples
50
+ ## Running
51
+
52
+ ** Note:** You need to have [ Docker] ( https://www.docker.com/ ) installed and running to run the sample.
53
+
54
+ To run this sample, execute the following command from the ` opentelemetry ` directory::
55
+
56
+ ``` bash
57
+ ./gradlew :runWithDocker
58
+ ```
59
+
60
+ It will start a ` Jaeger ` in the docker container (` Jaeger UI ` available on http://localhost:16686/search ) and
61
+ then it will start a ` server ` on http://localhost:8080/
62
+
63
+ Then, to run the client, which will send requests to a server, you can execute the following command in
64
+ an ` opentelemetry ` directory:
65
+
66
+ ``` bash
67
+ ./gradlew :client:run
68
+ ```
69
+
70
+ ** Note:** In this example, we use
71
+ an [ Autoconfiguration OpenTelemetry instance] ( https://opentelemetry.io/docs/languages/java/instrumentation/#automatic-configuration ) ,
72
+ we set environment variables ` OTEL_METRICS_EXPORTER ` and ` OTEL_EXPORTER_OTLP_ENDPOINT `
73
+ in [ build.gradle.kts] ( ./build.gradle.kts ) file.
74
+ You can find more information about these environment variables
75
+ in the [ OpenTelemetry documentation] ( https://opentelemetry.io/docs/languages/sdk-configuration/ ) .
79
76
80
- Let's see what we will see in the ` Jaeger UI ` after running the server (with Docker) and client:
77
+ Let's check what we will see in the ` Jaeger UI ` after running the server (with Docker) and the client:
81
78
82
- 1 . We can see two services that send opentelemetry data: ` opentelemetry-ktor-sample-server `
83
- and ` opentelemetry-ktor-sample-client ` :
79
+ 1 . We can see two our services that send opentelemetry data: ` opentelemetry-ktor-sample-server `
80
+ and ` opentelemetry-ktor-sample-client ` , and service ` jaeger-all-in-one ` , it's ` Jaeger ` tracing some of
81
+ its components:
84
82
![ img.png] ( images/1.png )
85
- 2 . If we choose ` opentelemetry-ktor-sample-server ` service, we will see the next traces:
83
+ 2 . If you select ` opentelemetry-ktor-sample-server ` service and click on ** Find traces ** , you will see a list of traces:
86
84
![ img.png] ( images/2.png )
87
- 3 . And if we choose one of the traces:
85
+ 3 . If you click on one of those traces, you will be navigated to a screen providing detailed information about the
86
+ selected trace:
88
87
![ img.png] ( images/3.png )
0 commit comments