Skip to content

modified the repetitive get method calls #34742

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Tussle0410
Copy link
Contributor

I've modified the DefaultClientRequestObservationConvention.class to reduce redundant calls to getCarrier() and getResponse() in ClientRequestObservationContext.

Previously, getCarrier() was called 8 times and getResponse() was called 3 times throughout the code.

I've modified the implementation to retrieve the ClientHttpRequest and ClientHttpResponse objects just once per method and then use these references for subsequent operations, making the code more efficient and easier to maintain.

	protected KeyValue clientName(ClientRequestObservationContext context) {
		if (context.getCarrier() != null && context.getCarrier().getURI().getHost() != null) {
			return KeyValue.of(LowCardinalityKeyNames.CLIENT_NAME, context.getCarrier().getURI().getHost());
		}
		return CLIENT_NAME_NONE;
	}

I've modified the existing code as shown below.

	protected KeyValue clientName(ClientRequestObservationContext context) {
		ClientHttpRequest request = getClientHttpRequest(context);
		if (request != null && request.getURI().getHost() != null) {
			return KeyValue.of(LowCardinalityKeyNames.CLIENT_NAME, request.getURI().getHost());
		}
		return CLIENT_NAME_NONE;
	}

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants