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

Javaagent auth extension #4

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

Javaagent auth extension #4

wants to merge 17 commits into from

Conversation

psx95
Copy link
Owner

@psx95 psx95 commented Dec 18, 2024

DO NOT MERGE

This PR is only to gather reviews/feedback.

@psx95 psx95 force-pushed the javaagent-auth-extension branch from 50e113e to a55d826 Compare December 18, 2024 21:11
Copy link

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

Did you test this against the trace endpoint?

* @see AutoConfigurationCustomizerProvider
* @see GoogleCredentials
*/
@AutoService(AutoConfigurationCustomizerProvider.class)

Choose a reason for hiding this comment

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

It might be better to split the provider which adds resource attributes from the one which adds auth headers, so users can enable them individually.

Copy link
Owner Author

Choose a reason for hiding this comment

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

In this case, the gcp.project_id is essential for successful export, so I don't think giving users individual control would be beneficial.

The OpenTelemetry Java Agent Extension can be easily added to any Java application by modifying the startup command to the application.
For more information on Extensions, see the [documentation here](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/examples/extension/README.md).

Below is a snippet showing how to add the extension to a Java application using the Gradle build system.
Copy link

Choose a reason for hiding this comment

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

Do users typically configure the agent through gradle?

Copy link
Owner Author

@psx95 psx95 Dec 19, 2024

Choose a reason for hiding this comment

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

I'm not sure about the typical use case, however in this case, the command line args would look extremely similar.

The integration test showcases the agent configuration directly on command line.

Choose a reason for hiding this comment

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

Use cases vary as broadly as the ecosystem does.

I think it's good to include this here.

throw new GoogleAuthException(Reason.FAILED_ADC_REFRESH, e);
}
gcpHeaders.put(QUOTA_USER_PROJECT_HEADER, credentials.getQuotaProjectId());
gcpHeaders.put("Authorization", "Bearer " + credentials.getAccessToken().getTokenValue());
Copy link

Choose a reason for hiding this comment

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

Since the map is just made once, it seems like this won't support refresh?

Copy link
Owner Author

@psx95 psx95 Dec 18, 2024

Choose a reason for hiding this comment

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

No, the function getRequiredHeaderMap is invoked through a header supplier which means it gets recreated during export.

There might be some performance concerns about recreating Map on every export, which I intend to discuss in the SIG.

throw new RuntimeException(e);
}
backendServer.start();
Process p =
Copy link

Choose a reason for hiding this comment

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

Did you ever get the tests working?

Copy link
Owner Author

@psx95 psx95 Dec 18, 2024

Choose a reason for hiding this comment

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

Got it working now - for some unknown reason, I could not get the @WithSpan annotation to work, so I switched to a different library which I know is auto-instrumented.

PS - The tests on CI are failing due to absence of GCP credentials, still need to work around that, but the tests are passing locally.

The com.sun.net.httpserver does not seem to be auto-instrumented by the
Java Agent and @WithSpan was not producing a trace span for the handler.
This commit changes the test app to use Apache HttpServer client which
is auto-instrumented by the agent.
@psx95 psx95 force-pushed the javaagent-auth-extension branch from a55d826 to c6049e3 Compare December 18, 2024 23:38
@psx95
Copy link
Owner Author

psx95 commented Dec 19, 2024

Did you test this against the trace endpoint?

Yes, this was manually tested against the trace endpoint.

@psx95 psx95 force-pushed the javaagent-auth-extension branch from 3c61a96 to 250b108 Compare December 19, 2024 21:49
@psx95 psx95 force-pushed the javaagent-auth-extension branch from 2dd2e13 to 122c7d7 Compare December 20, 2024 20:47
@psx95 psx95 force-pushed the javaagent-auth-extension branch 2 times, most recently from 7b3ef22 to 942977b Compare December 27, 2024 03:49
@psx95 psx95 force-pushed the javaagent-auth-extension branch from 942977b to a267bbb Compare December 27, 2024 03:54
@psx95 psx95 force-pushed the javaagent-auth-extension branch 2 times, most recently from 9639551 to d7d4bf9 Compare December 27, 2024 04:20
@psx95 psx95 force-pushed the javaagent-auth-extension branch from d7d4bf9 to 6036833 Compare January 2, 2025 21:08
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