Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update opentelemetry example #202

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 5 additions & 41 deletions opentelemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,12 @@
plugins for the Ktor client and server respectively. For the source code, see
the [repository on GitHub](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/ktor).

This project contains extension functions for plugins that allow you to write code in the Ktor DSL style.
This project contains examples of how to use the `KtorClientTracing` and `KtorServerTracing` plugins.

Take the following code as an example:

```kotlin
install(KtorServerTracing) {
...
addAttributeExtractor(
object : AttributesExtractor<ApplicationRequest, ApplicationResponse> {
override fun onEnd(
attributes: AttributesBuilder,
context: Context,
request: ApplicationRequest,
response: ApplicationResponse?,
error: Throwable?
) {
attributes.put("end-time", Instant.now().toEpochMilli())
}
}
)
...
}
```

Rewritten in Ktor DSL style, it looks like the following:

```kotlin
install(KtorServerTracing) {
...
attributeExtractor {
onEnd {
attributes.put("end-time", Instant.now().toEpochMilli())
}
}
...
}
```

You can find all extensions for the client plugin `KtorClientTracing` in
the [extractions](./client/src/main/kotlin/opentelemetry/ktor/example/plugins/opentelemetry/extractions/) folder. \
And you can find all extensions for the server plugin `KtorServerTracing` in
the [extractions](./server/src/main/kotlin/opentelemetry/ktor/example/plugins/opentelemetry/extractions/) folder.
You can find examples for the client plugin `KtorClientTracing` in
the [extractions](./client/src/main/kotlin/opentelemetry/ktor/example/plugins/opentelemetry) folder. \
And you can find examples for the server plugin `KtorServerTracing` in
the [extractions](./server/src/main/kotlin/opentelemetry/ktor/example/plugins/opentelemetry) folder.

## Running

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description = "OpenTelemetry-Ktor example"

plugins {
id("com.avast.gradle.docker-compose") version "0.14.0"
id("com.avast.gradle.docker-compose") version "0.17.1"
}

subprojects {
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry/client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ dependencies {
implementation("io.ktor:ktor-client-websockets:$ktor_version")
implementation("ch.qos.logback:logback-classic:$logback_version")

implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-2.0:$opentelemetry_version-alpha")
implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-3.0:$opentelemetry_version-alpha")
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package opentelemetry.ktor.example.plugins.opentelemetry
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.http.*
import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracing
import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTracing
import opentelemetry.ktor.example.CUSTOM_HEADER
import opentelemetry.ktor.example.CUSTOM_METHOD
import opentelemetry.ktor.example.getOpenTelemetry
import opentelemetry.ktor.example.plugins.opentelemetry.extractions.*

/**
* Install OpenTelemetry on the client.
Expand Down
8 changes: 5 additions & 3 deletions opentelemetry/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
ktor_version=3.0.1
kotlin_version=2.0.20
logback_version=1.4.11
logback_version=1.5.12
kotlin.code.style=official

opentelemetry_version=1.32.0
opentelemetry_semconv_version=1.21.0-alpha
opentelemetry_version=2.10.0
opentelemetry_semconv_version=1.21.0-alpha
opentelemetry_exporter_otlp_version=1.44.1
opentelemetry_sdk_extension_autoconfigure_version=1.44.1
2 changes: 1 addition & 1 deletion opentelemetry/server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ dependencies {
implementation("io.ktor:ktor-server-websockets:$ktor_version")
implementation("ch.qos.logback:logback-classic:$logback_version")

implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-2.0:$opentelemetry_version-alpha")
implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-3.0:$opentelemetry_version-alpha")
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import io.ktor.server.request.*
import io.opentelemetry.api.OpenTelemetry
import io.opentelemetry.api.trace.SpanKind
import io.opentelemetry.api.trace.StatusCode
import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracing
import io.opentelemetry.instrumentation.ktor.v3_0.server.KtorServerTracing
import opentelemetry.ktor.example.CUSTOM_HEADER
import opentelemetry.ktor.example.CUSTOM_METHOD
import opentelemetry.ktor.example.getOpenTelemetry
import opentelemetry.ktor.example.plugins.opentelemetry.extractions.*
import java.time.Instant

const val serviceName = "opentelemetry-ktor-sample-server"
Expand Down
Loading
Loading