File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
sdk-platform-java/gax-java/gax/src
main/java/com/google/api/gax/tracing
test/java/com/google/api/gax/tracing Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -207,9 +207,13 @@ private void endAttempt() {
207207
208208 @ Override
209209 public void requestUrlResolved (String url ) {
210- if (attemptSpan != null && url != null ) {
211- attemptSpan .setAttribute (
212- ObservabilityAttributes .HTTP_URL_FULL_ATTRIBUTE , ObservabilityUtils .sanitizeUrlFull (url ));
210+ if (attemptSpan == null ) {
211+ return ;
212+ }
213+ String sanitizedUrlString = ObservabilityUtils .sanitizeUrlFull (url );
214+ if (sanitizedUrlString .isEmpty ()) {
215+ return ;
213216 }
217+ attemptSpan .setAttribute (ObservabilityAttributes .HTTP_URL_FULL_ATTRIBUTE , sanitizedUrlString );
214218 }
215219}
Original file line number Diff line number Diff line change 3232import static com .google .common .truth .Truth .assertThat ;
3333import static org .mockito .ArgumentMatchers .any ;
3434import static org .mockito .ArgumentMatchers .anyString ;
35+ import static org .mockito .ArgumentMatchers .eq ;
36+ import static org .mockito .Mockito .never ;
3537import static org .mockito .Mockito .verify ;
3638import static org .mockito .Mockito .when ;
3739
@@ -259,4 +261,15 @@ void testRequestUrlResolved_setsAttribute() {
259261 ObservabilityAttributes .HTTP_URL_FULL_ATTRIBUTE ,
260262 "https://example.com?api_key=REDACTED" );
261263 }
264+
265+ @ Test
266+ void testRequestUrlResolved_badUrl_notSet () {
267+ spanTracer .attemptStarted (new Object (), 1 );
268+
269+ String rawUrl = "htps:::://the-example" ;
270+ spanTracer .requestUrlResolved (rawUrl );
271+
272+ verify (span , never ())
273+ .setAttribute (eq (ObservabilityAttributes .HTTP_URL_FULL_ATTRIBUTE ), anyString ());
274+ }
262275}
You can’t perform that action at this time.
0 commit comments