Skip to content

Commit

Permalink
do not override existing url on request even with full url
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Jan 24, 2025
1 parent 28cb76a commit 28a7e56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ private void addRequestAttributesToScope(Attributes attributes, IScope scope) {
request.setMethod(requestMethod);
}

final @Nullable String urlFull = attributes.get(UrlAttributes.URL_FULL);
if (urlFull != null) {
final @NotNull UrlUtils.UrlDetails urlDetails = UrlUtils.parse(urlFull);
urlDetails.applyToRequest(request);
if (request.getUrl() == null) {
final @Nullable String urlFull = attributes.get(UrlAttributes.URL_FULL);
if (urlFull != null) {
final @NotNull UrlUtils.UrlDetails urlDetails = UrlUtils.parse(urlFull);
urlDetails.applyToRequest(request);
}
}

if (request.getUrl() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ class OpenTelemetryAttributesExtractorTest {
thenQueryIsSetTo("s=abc")
}

@Test
fun `when there is an existing request with url on scope it is kept with URL_FULL`() {
fixture.scope.request = Request().also {
it.url = "http://docs.sentry.io:3000/platform"
it.queryString = "s=abc"
}
givenAttributes(
mapOf(
UrlAttributes.URL_FULL to "https://io.sentry:8081/path/to/123?q=123456&b=X"
)
)

whenExtractingAttributes()

thenRequestIsSet()
thenUrlIsSetTo("http://docs.sentry.io:3000/platform")
thenQueryIsSetTo("s=abc")
}

@Test
fun `sets URL based on OTel attributes without port`() {
givenAttributes(
Expand Down

0 comments on commit 28a7e56

Please sign in to comment.