Skip to content

Fix instrumentation for ibm https url connection connect #13728

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

Merged
merged 1 commit into from
Apr 18, 2025

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Apr 17, 2025

Instrumentation of IBM implementation of https url connection fails when connect is called before getInputStream/getOutputStream with

java.lang.IllegalStateException: Already connected
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:3214)
at io.opentelemetry.javaagent.instrumentation.httpurlconnection.RequestPropertySetter.set(RequestPropertySetter.java:16)
at io.opentelemetry.javaagent.instrumentation.httpurlconnection.RequestPropertySetter.set(RequestPropertySetter.java:11)
at io.opentelemetry.javaagent.shaded.io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator.inject(W3CTraceContextPropagator.java:123)
at io.opentelemetry.javaagent.shaded.io.opentelemetry.context.propagation.MultiTextMapPropagator.inject(MultiTextMapPropagator.java:52)
at io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.PropagatingToDownstreamInstrumenter.start(PropagatingToDownstreamInstrumenter.java:28)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1545)
at com.ibm.net.ssl.www2.protocol.https.b.getInputStream(b.java:74)

because IBM implementation overrides the connect method and does not delegate to the jdk implementation. We don't instrument the connect in IBM class because it is not included in

So we end up attempting to start the span in getInputStream where headers can't be modified any more. This PR adds instrumentation for plainConnect method that is called from the connect in the IBM class.

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for including a test 👍

@laurit laurit marked this pull request as ready for review April 17, 2025 14:19
@laurit laurit requested a review from a team as a code owner April 17, 2025 14:19
@laurit laurit merged commit 60c7993 into open-telemetry:main Apr 18, 2025
86 checks passed
@laurit laurit deleted the ibm-https-url-connection branch April 18, 2025 05:09
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

Successfully merging this pull request may close these issues.

4 participants