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

How to extend Xray Apache HTTP ClientBuilder? #321

Open
kjhok1811 opened this issue Feb 22, 2022 · 3 comments
Open

How to extend Xray Apache HTTP ClientBuilder? #321

kjhok1811 opened this issue Feb 22, 2022 · 3 comments

Comments

@kjhok1811
Copy link

I want to customize Metadata properties when instrumenting with Xray Apache HTTP ClientBuilder. What should I do?

@srprash
Copy link
Contributor

srprash commented Feb 28, 2022

Hi @kjhok1811
From my understanding, currently it is not possible to get access to the subsegment created by the X-Ray SDK for instrumented HTTP client. @willarmiros Can you confirm this?

For your instrumented HTTP client, are you looking to modifying existing metadata or add new ones? If you want to add new metedata, one workaround could be to create custom subsegment around the http client call and add metadata to this subsegment.

@kjhok1811
Copy link
Author

um...
Is there a way to customize the Xray Apache HTTP ClientBuilder?
@srprash

@srprash
Copy link
Contributor

srprash commented Mar 10, 2022

Is there a way to customize the Xray Apache HTTP ClientBuilder?

Unfortunately, the provided HttpClientBuilder cannot be customized.

However, I was wrong in saying

From my understanding, currently it is not possible to get access to the subsegment created by the X-Ray SDK for instrumented HTTP client.

There's a way (a bit convoluted though) you can modify the subsegments for HTTP calls using the SegmentListener interface.
You can implement this interface (let's call it MySegmentListener for example) and override it's beforeEndSubsegment method. Here you can check if this is the subsegment you want to modify and then customize its properties. You will need to add the MySegmentListener to your AWSXRayRecorder by doing something like this:

AWSXRayRecorderBuilder builder = AWSXRayRecorderBuilder.standard().withSegmentListener(mySegmentListener);
AWSXRay.setGlobalRecorder(builder.build());

Be advised that this may degrade some performance as the SegmentListener will be invoked for every Segment/Subsegment created in your application.

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

No branches or pull requests

2 participants