Skip to content

opentelemetry-http: fix url extraction #3274

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

Merged

Conversation

bryce-anderson
Copy link
Contributor

@bryce-anderson bryce-anderson commented May 22, 2025

Motivation:

Our url extraction is wrong in that it doesn't consider possible absolute-form request targets.

Modifications:

Fix the extraction.

Motivation:

Our url extraction is wrong in that it doesn't consider possible
absolute-form request targets. We also don't allow users to set
a host and port in the common case that it's using origin-form
request targets and we can't extract a host name or port.

Modifications:

Fix the extraction and make it possible to provide a host and port.
@bryce-anderson bryce-anderson changed the title opentelemetry-http: fox url extraction opentelemetry-http: fix url extraction May 22, 2025
@bryce-anderson bryce-anderson requested a review from mgodave May 22, 2025 18:16
return null;
}
String scheme = request.scheme();
if (scheme == null) {
scheme = HTTP_SCHEME;
scheme = effectiveHostAndPort.port() == 443 ? HTTPS_SCHEME : HTTP_SCHEME;
Copy link
Member

Choose a reason for hiding this comment

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

Just a note for anyone else looking at the PR: this is best effort. At client level, we don't know if the actually connection will be secure or not and therefore can not reliably detect scheme other than relying on standard port convention.

To make it work correctly, we may consider other options in the future. Some ideas are:

  1. Exposing client configuration for filters
  2. Using connection-level filter to attach scheme attribute to the current span after connection is selected

sb.append(requestTarget);
return sb.toString();
String authoritySeparator = requestTarget.startsWith("/") ? "" : "/";
return scheme + "://" + authority + authoritySeparator + requestTarget;
Copy link
Member

Choose a reason for hiding this comment

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

Could you remind me what we decided on our last discussion: should we use path() or requestTarget()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We decided to use path but I didn't change that behavior here: I think it's worth a separate PR and a bit more discussion since it will diverge from what OTEL specifies.

Copy link
Member

@idelpivnitskiy idelpivnitskiy May 30, 2025

Choose a reason for hiding this comment

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

I see io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractor has stripSensitiveData method, but it's private. They simply hardcoded some well-known parameters, like AWSAccessKeyId or Signature, without a way to extend it 😕

@bryce-anderson bryce-anderson merged commit a5a6ee0 into apple:main May 30, 2025
11 checks passed
@bryce-anderson bryce-anderson deleted the bl_anderson/OtelUrlExtraction branch May 30, 2025 15:12
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.

2 participants