Skip to content

Commit 28a7e56

Browse files
committed
do not override existing url on request even with full url
1 parent 28cb76a commit 28a7e56

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OpenTelemetryAttributesExtractor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ private void addRequestAttributesToScope(Attributes attributes, IScope scope) {
3535
request.setMethod(requestMethod);
3636
}
3737

38-
final @Nullable String urlFull = attributes.get(UrlAttributes.URL_FULL);
39-
if (urlFull != null) {
40-
final @NotNull UrlUtils.UrlDetails urlDetails = UrlUtils.parse(urlFull);
41-
urlDetails.applyToRequest(request);
38+
if (request.getUrl() == null) {
39+
final @Nullable String urlFull = attributes.get(UrlAttributes.URL_FULL);
40+
if (urlFull != null) {
41+
final @NotNull UrlUtils.UrlDetails urlDetails = UrlUtils.parse(urlFull);
42+
urlDetails.applyToRequest(request);
43+
}
4244
}
4345

4446
if (request.getUrl() == null) {

sentry-opentelemetry/sentry-opentelemetry-core/src/test/kotlin/OpenTelemetryAttributesExtractorTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ class OpenTelemetryAttributesExtractorTest {
9595
thenQueryIsSetTo("s=abc")
9696
}
9797

98+
@Test
99+
fun `when there is an existing request with url on scope it is kept with URL_FULL`() {
100+
fixture.scope.request = Request().also {
101+
it.url = "http://docs.sentry.io:3000/platform"
102+
it.queryString = "s=abc"
103+
}
104+
givenAttributes(
105+
mapOf(
106+
UrlAttributes.URL_FULL to "https://io.sentry:8081/path/to/123?q=123456&b=X"
107+
)
108+
)
109+
110+
whenExtractingAttributes()
111+
112+
thenRequestIsSet()
113+
thenUrlIsSetTo("http://docs.sentry.io:3000/platform")
114+
thenQueryIsSetTo("s=abc")
115+
}
116+
98117
@Test
99118
fun `sets URL based on OTel attributes without port`() {
100119
givenAttributes(

0 commit comments

Comments
 (0)