Skip to content

Conversation

@tylerbenson
Copy link
Member

Includes handling for attaching all the async stuff, but can't support everything the java agent does.

I could use help figuring out the right way to shadow all the necessary dependencies. I'm a bit rusty with our shadow usage. Depending on how aggressive we want to be, the dependency could be reversed so that :servlet-3.0:javaagent depends on this new module, but that's more aggressive. Perhaps shadow could prune unused classes (with minimize()) instead.

Once we get the modules figured out, I can work on adding some unit tests.

If we like this approach, it could probably be copied and modified pretty easily to support servlet 5, but I'm not familiar with that instrumentation.

Includes handling for attaching all the async stuff, but can't support everything the java agent does.

I could use help figuring out the right way to shadow all the necessary dependencies.  I'm a bit rusty with our shadow usage.
Depending on how aggressive we want to be, the dependency could be reversed so that `:servlet-3.0:javaagent` depends on this new module, but that's more aggressive.  Perhaps shadow could prune unused classes (with `minimize()`) instead.

Once we get the modules figured out, I can work on adding some unit tests.

If we like this approach, it could probably be copied and modified pretty easily to support servlet 5, but I'm not familiar with that instrumentation.
library("javax.servlet:javax.servlet-api:3.0.1")

// FIXME: These dependencies need to be shadowed into the library.
library(project(":instrumentation:servlet:servlet-3.0:javaagent"))
Copy link
Member

Choose a reason for hiding this comment

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

library instrumentations don't typically depend on javaagent instrumentation, could you move the helper into a common module or swap the dependency and have the javaagent depend on the library?

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand that isn't usually how it's done. I was trying to figure out if there was a simpler option besides moving everything around. There are a lot of related classes that would need to move, not just the helper class.

@laurit
Copy link
Contributor

laurit commented Oct 31, 2025

I could use help figuring out the right way to shadow all the necessary dependencies.

You shouldn't shadow anything. If you need to share code you can extract common code between the javaagent and library instrumentation into separate module or make javaagent module depend on the library module if that make sense. In your place I would focus on building a functioning instrumentation along with tests and explore options for sharing code later. It is quite possible that the agent code does things that don't make sense for the library instrumentation which could limit the amount of code that can be shared between them.

@@ -0,0 +1,43 @@
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0;

import static io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3Singletons.helper;
Copy link
Member Author

@tylerbenson tylerbenson Nov 3, 2025

Choose a reason for hiding this comment

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

@laurit I'm not sure how to handle the dependency on classes like io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseMutator from Servlet3Accessor referenced by Servlet3Singletons that seem to expect to be on the bootstrap classpath and are part of the javaagent-extension-api.

More and more it seems like there will be relatively little code that can be shared between the javaagent and library instrumentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

That one shouldn't be too hard to handle. You can easily remove that interface from Servlet3Accessor and have the usage in advice create a HttpServerResponseMutator that calls the appendHeader method in Servlet3Accessor.

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.

3 participants