Skip to content

Add try-catch logic for framework native instrumentation #16376

@steverao

Description

@steverao

Is your feature request related to a problem? Please describe.

Some instrumentations in this project are implemented by registering callbacks/handlers through extension points provided by the native frameworks (e.g., OkHttp's Interceptor chain, Feign's RequestInterceptor, etc.) rather than by bytecode-level instrumentation of the target method directly.

In such cases, if the instrumentation code injected via these extension points does not have proper try-catch protection around the call to the actual framework logic (e.g., chain.proceed(request)), any unexpected exception may influent user's request.
In our distro, we met a such case recently, the related stack trace looks like below(The problem caused by our distro related logic):

Caused by: XXXXException
	......
	at io.opentelemetry.sdk.trace.MultiSpanProcessor.onEnd(MultiSpanProcessor.java:54)
t io.opentelemetry.sdk.trace.SdkSpan.endInternal(SdkSpan.java:570)
	at io.opentelemetry.sdk.trace.SdkSpan.end(SdkSpan.java:539)
	at io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.Instrumenter.doEnd(Instrumenter.java:309)
	at io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.Instrumenter.end(Instrumenter.java:166)
	at io.opentelemetry.javaagent.shaded.instrumentation.okhttp.v3_0.internal.TracingInterceptor.intercept(TracingInterceptor.java:51)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:43)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)

Describe the solution you'd like

Add proper try-catch in common place in order to avoid any exception thrown from within the native extension point callback

Describe alternatives you've considered

No response

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestneeds triageNew issue that requires triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions