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

Support Ktor (Okhttp engine) #1175

Open
ber4444 opened this issue Feb 16, 2025 · 5 comments
Open

Support Ktor (Okhttp engine) #1175

ber4444 opened this issue Feb 16, 2025 · 5 comments
Assignees

Comments

@ber4444
Copy link

ber4444 commented Feb 16, 2025

We are getting an exception when trying to use it with ktorTelemetry = "io.opentelemetry.instrumentation:opentelemetry-ktor-3.0:2.13.0-alpha":

java.lang.NoClassDefFoundError: Failed resolution of: Lio/opentelemetry/semconv/ResourceAttributes;
	at io.opentelemetry.android.AndroidResource.createDefault(AndroidResource.java:29)
	at io.opentelemetry.android.OpenTelemetryRumBuilder.<init>(OpenTelemetryRumBuilder.java:101)
	at io.opentelemetry.android.OpenTelemetryRum.builder(OpenTelemetryRum.java:46)
	at com.splunk.rum.RumInitializer.initialize(RumInitializer.java:108)
	at com.splunk.rum.SplunkRum.initialize(SplunkRum.java:111)
	at com.splunk.rum.SplunkRumBuilder.build(SplunkRumBuilder.java:348)

Usage should be something like this?

HttpClient(OkHttp) {
      install(KtorClientTelemetry) {
                        setOpenTelemetry(SplunkRum.getInstance().openTelemetry)
@ber4444
Copy link
Author

ber4444 commented Feb 24, 2025

We used to rely on createRumOkHttpCallFactory with Retrofit like so:

val builder = Retrofit.Builder()
...
builder.callFactory(SplunkRum.getInstance().createRumOkHttpCallFactory(httpClient)).build().create()

I saw that the Splunk SDK deprecated createRumOkHttpCallFactory but no replacement is offered.

@surbhiia
Copy link
Contributor

Hi @ber4444, For the first issue where ResourceAttributes class is not found:

java.lang.NoClassDefFoundError: Failed resolution of: Lio/opentelemetry/semconv/ResourceAttributes;
at io.opentelemetry.android.AndroidResource.createDefault(AndroidResource.java:29)
at io.opentelemetry.android.OpenTelemetryRumBuilder.(OpenTelemetryRumBuilder.java:101)
at io.opentelemetry.android.OpenTelemetryRum.builder(OpenTelemetryRum.java:46)
at com.splunk.rum.RumInitializer.initialize(RumInitializer.java:108)
at com.splunk.rum.SplunkRum.initialize(SplunkRum.java:111)
at com.splunk.rum.SplunkRumBuilder.build(SplunkRumBuilder.java:348)

The issue is with the version of opentelemetry-semconv library, the opentelemetry-ktor-3.0 version 2.13.0-alpha is bringing. In newer versions of opentelemetry-semconv the ResourceAttributes class is replaced with other classes. Therefore, opentelemetry-ktor-3.0 version 2.13.0-alpha is not compatible with current versions of splunk-otel-android. This won't be an issue in upcoming versions of splunk-otel-android.

@ber4444
Copy link
Author

ber4444 commented Mar 13, 2025

Please share a code sample showing Ktor integration.

Also please share what's offered to replace createRumOkHttpCallFactory

@SenNeonoveNoci SenNeonoveNoci self-assigned this Mar 14, 2025
@SenNeonoveNoci
Copy link

Hi @ber4444,

In the next release of the agent, we will introduce a new API and logic for the manual OkHttp instrumentation. It will no longer provide Call.Factory like the current implementation but will work on a slightly different principle.

It will utilize the addNetworkInterceptor(interceptor: Interceptor), which will be used to set a SplunkOkHttpInterceptor that handles all the work.

After the next release, your use case might look something like this:

val builder = Retrofit.Builder()  
...  
httpClient.addNetworkInterceptor(SplunkOkHttpInterceptor())  
builder.client(httpClient).build().create()

Changes:

  • Use addNetworkInterceptor(interceptor: Interceptor).
  • Use client(client: OkHttpClient) instead of callFactory(factory: Call.Factory).

Sorry for any inconvenience.

@ber4444
Copy link
Author

ber4444 commented Mar 14, 2025

Would KtorClientTelemetry be also supported or we would be forced to use the Okhttp engine with Ktor and configure telemetry with the Okhttp interceptor like you described? That works for us, it's just not supportive of the KMP world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants