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

Add support for java's jdk.httpserver module #13216

Open
SentryMan opened this issue Feb 5, 2025 · 4 comments
Open

Add support for java's jdk.httpserver module #13216

SentryMan opened this issue Feb 5, 2025 · 4 comments
Labels
contribution welcome Request makes sense, maintainers probably won't have time, contribution would be welcome enhancement New feature or request new instrumentation

Comments

@SentryMan
Copy link

SentryMan commented Feb 5, 2025

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

Currently, there is no support for the humble jdk.httpserver.

Describe the solution you'd like

A new instrumentation should be added

Describe alternatives you've considered

No response

Additional context

Since Java 21, virtual threads allow for some decent performance using this server, so it would be nice if we could have native instrumentation.

@SentryMan SentryMan added enhancement New feature or request needs triage New issue that requires triage labels Feb 5, 2025
@laurit
Copy link
Contributor

laurit commented Feb 5, 2025

@laurit laurit added contribution welcome Request makes sense, maintainers probably won't have time, contribution would be welcome new instrumentation and removed needs triage New issue that requires triage labels Feb 5, 2025
@SentryMan
Copy link
Author

I see, what resources would you recommend in order for me to gain the knowledge required to implement? Or should I try to copy an existing impl like jetty and try to reverse engineer?

@trask
Copy link
Member

trask commented Feb 5, 2025

@laurit
Copy link
Contributor

laurit commented Feb 5, 2025

Or should I try to copy an existing impl like jetty and try to reverse engineer?

I think jetty isn't the best choice to copy from as it only has the agent instrumentation and it interacts with servlet instrumentation. You could start from https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/armeria/armeria-1.3/library
We provide 2 kinds of instrumentations, the agent instrumentation that is in the javaagent directory and manual instrumentation libraries that can be used without agent by including the library in your application. The manual instrumentation libraries are in the library directory. It should be easier to start with the manual instrumentation library as this is just plain java without bytecode modifications. Unfortunately building the library instrumentation isn't always feasible. So one of the first decisions should be deciding whether you can build one. Here I think you can build one using a https://docs.oracle.com/en/java/javase/23/docs/api/jdk.httpserver/com/sun/net/httpserver/Filter.html You can copy paste most of the stuff. The parts you need to implement are https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextGetter.java This class is used to read request headers, used for context propagation. https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java span/metric attributes are filled based on the info from this class. If some info is not available you can return null.

this method sets up the tracing, it is framework specific. You probably could return a filter that does the tracing. Have a look at other ServerTelemetry classes to gather ideas. For testing use https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerTest.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome Request makes sense, maintainers probably won't have time, contribution would be welcome enhancement New feature or request new instrumentation
Projects
None yet
Development

No branches or pull requests

3 participants