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

Implement mechanism to apply custom api path #1859

Merged

Conversation

MazizEsa
Copy link
Contributor

This comes in handy when another monitoring tool is being used, for instance new relic, which doesn't not require path in its tracing api.

Context as of feb 19, new relic doesn't accept request to its tracing api endpoint with path. Previous it was fine, now it will throw 404 erro.

…eUrl.

This comes in handy when another monitoring tool is being used, for instance new relic, which doesn't not require path in its tracing api.
Copy link
Contributor

@marcingrzejszczak marcingrzejszczak left a comment

Choose a reason for hiding this comment

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

LGTM apart from small changes. Could you also please update the documentation and mention the new apiPath somewhere around here https://docs.spring.io/spring-cloud-sleuth/docs/2.2.7.RELEASE/reference/html/#sending-spans-to-zipkin ? Once it's done then @Buzzardo would review it.

@@ -77,6 +81,16 @@ else if (this.encoding == Encoding.JSON) {
this.messageEncoder = BytesMessageEncoder.forEncoding(this.encoding);
}

private String buildUrlWithCustomPathIfNecessary(final String baseUrl,
final String customApiPath, final String defaultUrl) {
if (Objects.nonNull(customApiPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually we could call StringUtils.hasText(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marcingrzejszczak , using nonNull was the intention. This is to cater cases where:

  1. Null (when the apiPath is not configured at all, use the default
  2. NonBlank (any text) as the custom api path
  3. Blank (empty string) this is for cases no path needed at all (one example newrelic)

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. apiPath should default to api/v2/spans - that way we're simplifying the cases.
  2. Makes sense
  3. Shouldn't it be then / ?

Copy link
Contributor Author

@MazizEsa MazizEsa Feb 25, 2021

Choose a reason for hiding this comment

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

@marcingrzejszczak
We can't default to api/v2/spans in the apiPath because within RestTemplate the path is different between JSON2, PROTO and JSON. JSON is using v1. So I wanted to ensure that part of logic within the RestTemplateSender constructor being maintained.

For 3, at least for new relic case, there's no /. If you include /, tracing api will return 404. So for the path it must be empty. This approach also give flexibility to include / or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, now I understand! You're right 👍

@@ -84,6 +91,14 @@ public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}

public String getApiPath() {
return apiPath;
Copy link
Contributor

Choose a reason for hiding this comment

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

return this.apiPath - let's be consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will include in the next push. Thanks @marcingrzejszczak

@@ -37,6 +37,13 @@
*/
private String baseUrl = "http://localhost:9411/";

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @Buzzardo - can you please check this out?

@@ -37,6 +37,13 @@
*/
private String baseUrl = "http://localhost:9411/";

/**
* Api path that will be appended to baseUrl above as suffix This is applicable if you
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to:

The API path to append to the baseUrl (above) as a suffix. This applies if you

@@ -37,6 +37,13 @@
*/
private String baseUrl = "http://localhost:9411/";

/**
* Api path that will be appended to baseUrl above as suffix This is applicable if you
* are using other monitoring tools. IE, new relic, the trace api doesn't need api
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to:

use other monitoring tools, such as New Relic. The trace API doesn't need the API

/**
* Api path that will be appended to baseUrl above as suffix This is applicable if you
* are using other monitoring tools. IE, new relic, the trace api doesn't need api
* path, so this can be set to blank ("") in the config.
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to:

path, so you can set it to blank ("") in the configuration.

Copy link
Contributor

@Buzzardo Buzzardo left a comment

Choose a reason for hiding this comment

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

Thank you.

@MazizEsa
Copy link
Contributor Author

@marcingrzejszczak @Buzzardo made the changes as well in the main documentation de23b6e . Thanks.

@marcingrzejszczak marcingrzejszczak merged commit 10ff663 into spring-cloud:2.2.x Feb 27, 2021
@marcingrzejszczak
Copy link
Contributor

Thanks @MazizEsa for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants