Skip to content

Commit

Permalink
Strip URL of network request of parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
bidetofevil committed Jul 11, 2024
1 parent f9ff3d8 commit cb9a840
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.embrace.android.embracesdk.network.EmbraceNetworkRequest
import io.embrace.android.embracesdk.payload.AppExitInfoData
import io.embrace.android.embracesdk.payload.NetworkCapturedCall
import io.embrace.android.embracesdk.utils.NetworkUtils.getValidTraceId
import io.embrace.android.embracesdk.utils.NetworkUtils.stripUrl
import io.opentelemetry.semconv.ErrorAttributes
import io.opentelemetry.semconv.HttpAttributes
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes
Expand Down Expand Up @@ -214,7 +215,7 @@ internal sealed class SchemaType(

internal class NetworkRequest(networkRequest: EmbraceNetworkRequest) : SchemaType(EmbType.Performance.Network) {
override val schemaAttributes = mapOf(
"url.full" to networkRequest.url,
"url.full" to stripUrl(networkRequest.url),
HttpAttributes.HTTP_REQUEST_METHOD.key to networkRequest.httpMethod,
HttpAttributes.HTTP_RESPONSE_STATUS_CODE.key to networkRequest.responseCode,
HttpIncubatingAttributes.HTTP_REQUEST_BODY_SIZE.key to networkRequest.bytesSent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.embrace.android.embracesdk.internal.network.http.NetworkCaptureData
import io.embrace.android.embracesdk.internal.payload.Span
import io.embrace.android.embracesdk.network.EmbraceNetworkRequest
import io.embrace.android.embracesdk.network.http.HttpMethod
import io.embrace.android.embracesdk.utils.NetworkUtils.stripUrl
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
Expand Down Expand Up @@ -146,6 +147,21 @@ internal class EmbraceNetworkLoggingServiceTest {
assertEquals(2, getNetworkSpans().size)
}

@Test
fun `URL parameters will be truncated`() {
val url = "https://www.example1.com/a?b=c"
logNetworkRequest(
url = url,
startTime = 100,
endTime = 200,
)

with(checkNotNull(getNetworkSpans().single())) {
assertEquals(stripUrl(url), attributes?.single { it.key == "url.full" }?.data)
}

}

private fun logNetworkRequest(
url: String,
startTime: Long = 100,
Expand Down

0 comments on commit cb9a840

Please sign in to comment.