getsentry / getsentry/sentry-java

Ktor 3 Sentry OpenTelemetry Agentless ClassNotFoundException

Abierto
#4,345 5 comentarios 1 reacción 0 asignados Ver en GitHub
Bug Java Spans
Lenguaje dominante
Kotlin
Estrellas
1.4k
Forks
478
Merge medio
2 d 23 h
PR fusionados (30 d)
67

Descripción

### Environment

SaaS ([https://sentry.io/]())

### Steps to Reproduce

Potentially relevant used plugin versions:

Ktor Server version `3.1.2`
Kotlin `2.1.20`
Sentry jvm gradle plugin `5.3.0`

I added the following to my `dependencies { .. }` block in my `build.gradle.kts`

```
implementation(platform("io.sentry:sentry-bom:8.8.0"))
implementation("io.sentry:sentry")
implementation("io.sentry:sentry-opentelemetry-agentless")

implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-3.0:2.15.0-alpha")
```

I start sentry in my Ktor application and then configure the ktor 3 plugin in the following way:

```
fun Application.configureMonitoring() {

install(KtorServerTelemetry) {
val openTelemetry = createOpenTelemetry()
setOpenTelemetry(openTelemetry)

attributesExtractor {
onStart {
attributes.put("start-time", Clock.System.now().toEpochMilliseconds())
}
onEnd {
attributes.put("end-time", Clock.System.now().toEpochMilliseconds())
}
}
}
}

private fun createOpenTelemetry(): OpenTelemetry =
AutoConfiguredOpenTelemetrySdk.builder().addResourceCustomizer { oldResource, _ ->
oldResource.toBuilder()
.putAll(oldResource.attributes)
.put(ServiceAttributes.SERVICE_NAME, "my-app-backend")
.build()
}
.build()
.openTelemetrySdk
```

This was what I came up with based on this [Ktor opentelemetry example]() and the [Sentry Agentless Opentelemetry docs]().

### Expected Result

The app starts and reports the traces to Sentry cloud.

### Actual Result

My application doesn't come up, I see the following crash in my logs:

```
java.lang.ClassNotFoundException: io.opentelemetry.api.incubator.events.EventLoggerProvider
at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk.builder(AutoConfiguredOpenTelemetrySdk.java:44)
at io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk.initialize(AutoConfiguredOpenTelemetrySdk.java:36)
at myktorapp.com.plugins.MonitoringKt.configureMonitoring$lambda$3(Monitoring.kt:28)
at io.ktor.server.application.CreatePluginUtilsKt.createRouteScopedPluginInstance(CreatePluginUtils.kt:277)
at io.ktor.server.application.CreatePluginUtilsKt.access$createRouteScopedPluginInstance(CreatePluginUtils.kt:1)
at io.ktor.server.application.RouteScopedPluginImpl.install(CreatePluginUtils.kt:182)
at io.ktor.server.application.RouteScopedPluginImpl.install(CreatePluginUtils.kt:164)
at io.ktor.server.application.ApplicationPluginKt.install(ApplicationPlugin.kt:121)
at myktorapp.com.plugins.MonitoringKt.configureMonitoring(Monitoring.kt:26)
at myktorapp.com.ApplicationKt.module(Application.kt:51)
at myktorapp.com.ApplicationKt.module$default(Application.kt:43)
at myktorapp.com.ApplicationKt.initialize(Application.kt:30)
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.lang.reflect.Method.invoke(Method.java:578)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:106)
at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:207)
at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:112)
at io.ktor.server.engine.internal.CallableUtilsKt.callFunctionWithInjection(CallableUtils.kt:127)
at io.ktor.server.engine.internal.CallableUtilsKt.executeModuleFunction(CallableUtils.kt:40)
at io.ktor.server.engine.EmbeddedServer.launchModuleByName$lambda$32(EmbeddedServerJvm.kt:422)
at io.ktor.server.engine.EmbeddedServer.avoidingDoubleStartupFor(EmbeddedServerJvm.kt:446)
at io.ktor.server.engine.EmbeddedServer.launchModuleByName(EmbeddedServerJvm.kt:421)
at io.ktor.server.engine.EmbeddedServer.dynamicModule$lambda$26(EmbeddedServerJvm.kt:381)
at io.ktor.server.engine.EmbeddedServer.instantiateAndConfigureApplication$lambda$25(EmbeddedServerJvm.kt:371)
at io.ktor.server.engine.EmbeddedServer.avoidingDoubleStartup(EmbeddedServerJvm.kt:428)
at io.ktor.server.engine.EmbeddedServer.instantiateAndConfigureApplication(EmbeddedServerJvm.kt:370)
at io.ktor.server.engine.EmbeddedServer.createApplication(EmbeddedServerJvm.kt:171)
at io.ktor.server.engine.EmbeddedServer.start(EmbeddedServerJvm.kt:301)
at io.ktor.server.netty.EngineMain.main(EngineMain.kt:25)
at myktorapp.com.ApplicationKt.main(Application.kt:17)
java.lang.NoClassDefFoundError: io/opentelemetry/api/incubator/events/EventLoggerProvider
at io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk.builder(AutoConfiguredOpenTelemetrySdk.java:44)
at io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk.initialize(AutoConfiguredOpenTelemetrySdk.java:36)
at myktorapp.com.plugins.MonitoringKt.configureMonitoring$lambda$3(Monitoring.kt:28)
at io.ktor.server.application.CreatePluginUtilsKt.createRouteScopedPluginInstance(CreatePluginUtils.kt:277)
at io.ktor.server.application.CreatePluginUtilsKt.access$createRouteScopedPluginInstance(CreatePluginUtils.kt:1)
at io.ktor.server.application.RouteScopedPluginImpl.install(CreatePluginUtils.kt:182)
at io.ktor.server.application.RouteScopedPluginImpl.install(CreatePluginUtils.kt:164)
at io.ktor.server.application.ApplicationPluginKt.install(ApplicationPlugin.kt:121)
at myktorapp.com.plugins.MonitoringKt.configureMonitoring(Monitoring.kt:26)
at myktorapp.com.ApplicationKt.module(Application.kt:51)
at myktorapp.com.ApplicationKt.module$default(Application.kt:43)
at myktorapp.com.ApplicationKt.initialize(Application.kt:30)
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.lang.reflect.Method.invoke(Method.java:578)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:106)
at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:207)
at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:112)
at io.ktor.server.engine.internal.CallableUtilsKt.callFunctionWithInjection(CallableUtils.kt:127)
at io.ktor.server.engine.internal.CallableUtilsKt.executeModuleFunction(CallableUtils.kt:40)
at io.ktor.server.engine.EmbeddedServer.launchModuleByName$lambda$32(EmbeddedServerJvm.kt:422)
at io.ktor.server.engine.EmbeddedServer.avoidingDoubleStartupFor(EmbeddedServerJvm.kt:446)
at io.ktor.server.engine.EmbeddedServer.launchModuleByName(EmbeddedServerJvm.kt:421)
at io.ktor.server.engine.EmbeddedServer.dynamicModule$lambda$26(EmbeddedServerJvm.kt:381)
at io.ktor.server.engine.EmbeddedServer.instantiateAndConfigureApplication$lambda$25(EmbeddedServerJvm.kt:371)
at io.ktor.server.engine.EmbeddedServer.avoidingDoubleStartup(EmbeddedServerJvm.kt:428)
at io.ktor.server.engine.EmbeddedServer.instantiateAndConfigureApplication(EmbeddedServerJvm.kt:370)
at io.ktor.server.engine.EmbeddedServer.createApplication(EmbeddedServerJvm.kt:171)
at io.ktor.server.engine.EmbeddedServer.start(EmbeddedServerJvm.kt:301)
at io.ktor.server.netty.EngineMain.main(EngineMain.kt:25)
at myktorapp.com.ApplicationKt.main(Application.kt:17)
```

### Product Area

Performance

### Link

*No response*

### DSN

*No response*

### Version

*No response*

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.