-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump OpenTelemetry version to 1.19 (#383)
- Loading branch information
Mateusz Rzeszutek
authored
Oct 13, 2022
1 parent
44469dd
commit f8ed61c
Showing
7 changed files
with
143 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
splunk-otel-android-volley/src/main/java/com/splunk/rum/UrlParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.splunk.rum; | ||
|
||
// Includes work from: | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
/** | ||
* Copy of | ||
* https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/710429029450855c051ce45c8a8857c95f1cb255/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/UrlParser.java | ||
*/ | ||
class UrlParser { | ||
|
||
@Nullable | ||
static String getHost(String url) { | ||
|
||
int schemeEndIndex = url.indexOf(':'); | ||
if (schemeEndIndex == -1) { | ||
// not a valid url | ||
return null; | ||
} | ||
|
||
int len = url.length(); | ||
if (len <= schemeEndIndex + 2 | ||
|| url.charAt(schemeEndIndex + 1) != '/' | ||
|| url.charAt(schemeEndIndex + 2) != '/') { | ||
// has no authority component | ||
return null; | ||
} | ||
|
||
// look for the end of the host: | ||
// ':' ==> start of port, or | ||
// '/', '?', '#' ==> start of path | ||
int index; | ||
for (index = schemeEndIndex + 3; index < len; index++) { | ||
char c = url.charAt(index); | ||
if (c == ':' || c == '/' || c == '?' || c == '#') { | ||
break; | ||
} | ||
} | ||
String host = url.substring(schemeEndIndex + 3, index); | ||
return host.isEmpty() ? null : host; | ||
} | ||
|
||
@Nullable | ||
static Integer getPort(String url) { | ||
|
||
int schemeEndIndex = url.indexOf(':'); | ||
if (schemeEndIndex == -1) { | ||
// not a valid url | ||
return null; | ||
} | ||
|
||
int len = url.length(); | ||
if (len <= schemeEndIndex + 2 | ||
|| url.charAt(schemeEndIndex + 1) != '/' | ||
|| url.charAt(schemeEndIndex + 2) != '/') { | ||
// has no authority component | ||
return null; | ||
} | ||
|
||
// look for the end of the host: | ||
// ':' ==> start of port, or | ||
// '/', '?', '#' ==> start of path | ||
int index; | ||
int portIndex = -1; | ||
for (index = schemeEndIndex + 3; index < len; index++) { | ||
char c = url.charAt(index); | ||
if (c == ':') { | ||
portIndex = index + 1; | ||
break; | ||
} | ||
if (c == '/' || c == '?' || c == '#') { | ||
break; | ||
} | ||
} | ||
|
||
if (portIndex == -1) { | ||
return null; | ||
} | ||
|
||
// look for the end of the port: | ||
// '/', '?', '#' ==> start of path | ||
for (index = portIndex; index < len; index++) { | ||
char c = url.charAt(index); | ||
if (c == '/' || c == '?' || c == '#') { | ||
break; | ||
} | ||
} | ||
String port = url.substring(portIndex, index); | ||
return port.isEmpty() ? null : safeParse(port); | ||
} | ||
|
||
@Nullable | ||
private static Integer safeParse(String port) { | ||
try { | ||
return Integer.valueOf(port); | ||
} catch (NumberFormatException e) { | ||
return null; | ||
} | ||
} | ||
|
||
private UrlParser() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters