Skip to content

Commit bfebcf2

Browse files
remobe old code and test for target mapping (Azure#23403)
1 parent ae0d4c8 commit bfebcf2

File tree

2 files changed

+0
-261
lines changed

2 files changed

+0
-261
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/HttpHelper.cs

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -8,92 +8,6 @@ namespace Azure.Monitor.OpenTelemetry.Exporter
88
{
99
internal static class HttpHelper
1010
{
11-
private const string SchemePostfix = "://";
12-
private const string Colon = ":";
13-
14-
/// <summary>
15-
/// This method follows OpenTelemetry specification to retrieve http URL.
16-
/// Reference: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#http-client.
17-
/// </summary>
18-
/// <param name="tagObjects">Activity Tags</param>
19-
/// <param name="url">URL</param>
20-
/// <param name="urlAuthority">Host name or IP address and the port number </param>
21-
internal static void GenerateUrlAndAuthority(this AzMonList tagObjects, out string url, out string urlAuthority)
22-
{
23-
urlAuthority = null;
24-
url = null;
25-
26-
var httpurl = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpUrl);
27-
28-
if (httpurl != null && Uri.TryCreate(httpurl.ToString(), UriKind.RelativeOrAbsolute, out var uri) && uri.IsAbsoluteUri)
29-
{
30-
url = uri.AbsoluteUri;
31-
urlAuthority = uri.Authority;
32-
return;
33-
}
34-
35-
var httpScheme = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpScheme)?.ToString();
36-
37-
if (!string.IsNullOrWhiteSpace(httpScheme))
38-
{
39-
var httpHost = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpHost)?.ToString();
40-
41-
if (!string.IsNullOrWhiteSpace(httpHost))
42-
{
43-
var httpPortAndTarget = AzMonList.GetTagValues(ref tagObjects, SemanticConventions.AttributeHttpHostPort, SemanticConventions.AttributeHttpTarget);
44-
45-
if (httpPortAndTarget[0] != null && httpPortAndTarget[0].ToString() != "80" && httpPortAndTarget[0].ToString() != "443")
46-
{
47-
var IsColon = (string.IsNullOrWhiteSpace(httpPortAndTarget[0].ToString()) ? null : Colon);
48-
url = $"{httpScheme}://{httpHost}{IsColon}{httpPortAndTarget[0]}{httpPortAndTarget[1]}";
49-
urlAuthority = $"{httpHost}{IsColon}{httpPortAndTarget[0]}";
50-
}
51-
else
52-
{
53-
url = $"{httpScheme}://{httpHost}{httpPortAndTarget[1]}";
54-
urlAuthority = $"{httpHost}";
55-
}
56-
57-
return;
58-
}
59-
60-
var netPeerName = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeNetPeerName)?.ToString();
61-
62-
if (!string.IsNullOrWhiteSpace(netPeerName))
63-
{
64-
var netPeerPortAndTarget = AzMonList.GetTagValues(ref tagObjects, SemanticConventions.AttributeNetPeerPort, SemanticConventions.AttributeHttpTarget);
65-
var IsColon = (string.IsNullOrWhiteSpace(netPeerPortAndTarget[0]?.ToString()) ? null : Colon);
66-
url = $"{httpScheme}{SchemePostfix}{netPeerName}{IsColon}{netPeerPortAndTarget[0]}{netPeerPortAndTarget[1]}";
67-
urlAuthority = $"{netPeerName}{IsColon}{netPeerPortAndTarget[0]}";
68-
return;
69-
}
70-
71-
var netPeerIP = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeNetPeerIp)?.ToString();
72-
73-
if (!string.IsNullOrWhiteSpace(netPeerIP))
74-
{
75-
var netPeerPortAndTarget = AzMonList.GetTagValues(ref tagObjects, SemanticConventions.AttributeNetPeerPort, SemanticConventions.AttributeHttpTarget);
76-
var IsColon = (string.IsNullOrWhiteSpace(netPeerPortAndTarget[0]?.ToString()) ? null : Colon);
77-
url = $"{httpScheme}{SchemePostfix}{netPeerIP}{IsColon}{netPeerPortAndTarget[0]}{netPeerPortAndTarget[1]}";
78-
urlAuthority = $"{netPeerIP}{IsColon}{netPeerPortAndTarget[0]}";
79-
return;
80-
}
81-
}
82-
83-
var host = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpHost)?.ToString();
84-
85-
if (!string.IsNullOrWhiteSpace(host))
86-
{
87-
var httpPortAndTarget = AzMonList.GetTagValues(ref tagObjects, SemanticConventions.AttributeHttpHostPort, SemanticConventions.AttributeHttpTarget);
88-
var IsColon = (string.IsNullOrWhiteSpace(httpPortAndTarget[0]?.ToString()) ? null : Colon);
89-
url = $"{host}{IsColon}{httpPortAndTarget[0]}{httpPortAndTarget[1]}";
90-
urlAuthority = $"{host}{IsColon}{httpPortAndTarget[0]}";
91-
return;
92-
}
93-
94-
url = string.IsNullOrWhiteSpace(url) ? null : url;
95-
}
96-
9711
///<summary>
9812
/// Gets http request url from activity tag objects.
9913
///</summary>

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/HttpHelperTests.cs

Lines changed: 0 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -8,181 +8,6 @@ namespace Azure.Monitor.OpenTelemetry.Exporter
88
{
99
public class HttpHelperTests
1010
{
11-
[Fact]
12-
public void GetUrl_Null()
13-
{
14-
var PartBTags = AzMonList.Initialize();
15-
16-
PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
17-
Assert.Null(url);
18-
Assert.Null(urlAuthority);
19-
}
20-
21-
[Theory]
22-
[InlineData(SemanticConventions.AttributeHttpUrl)]
23-
[InlineData(SemanticConventions.AttributeHttpScheme)]
24-
[InlineData(SemanticConventions.AttributeHttpHost)]
25-
public void GetUrl_NullOrEmpty(string attribute)
26-
{
27-
var PartBTags = AzMonList.Initialize();
28-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(attribute, null));
29-
30-
PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
31-
Assert.Null(url);
32-
Assert.Null(urlAuthority);
33-
34-
AzMonList.Clear(ref PartBTags);
35-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(attribute, string.Empty));
36-
PartBTags.GenerateUrlAndAuthority(out url, out urlAuthority);
37-
Assert.Null(url);
38-
Assert.Null(urlAuthority);
39-
}
40-
41-
[Fact]
42-
public void GetUrl_With_HttpScheme_And_Null_HttpHost()
43-
{
44-
var PartBTags = AzMonList.Initialize();
45-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpScheme, null));
46-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpHost, null));
47-
48-
PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
49-
Assert.Null(url);
50-
Assert.Null(urlAuthority);
51-
}
52-
53-
[Theory]
54-
[InlineData("https", null, null)]
55-
[InlineData("https", "", null)]
56-
[InlineData("https", "netpeername", null)]
57-
public void GetUrl_NetPeerName_NullOrEmpty(string scheme, string peerName, string peerPort)
58-
{
59-
var PartBTags = AzMonList.Initialize();
60-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpScheme, scheme));
61-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeNetPeerName, peerName));
62-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeNetPeerPort, peerPort));
63-
64-
PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
65-
66-
if (string.IsNullOrEmpty(peerName))
67-
{
68-
Assert.Null(url);
69-
Assert.Null(urlAuthority);
70-
}
71-
else
72-
{
73-
Assert.Equal("https://netpeername", url);
74-
Assert.Equal("netpeername", urlAuthority);
75-
}
76-
}
77-
78-
[Theory]
79-
[InlineData("https", "localhost", null)]
80-
[InlineData("https", "localhost", "80")]
81-
[InlineData("https", "localhost", "443")]
82-
public void GetUrl_HttpPort_NullEmptyOrDefault(string scheme, string httpHost, string hostPort)
83-
{
84-
var PartBTags = AzMonList.Initialize();
85-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpScheme, scheme));
86-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpHost, httpHost));
87-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpHostPort, hostPort));
88-
89-
PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
90-
91-
Assert.Equal("https://localhost", url);
92-
Assert.Equal("localhost", urlAuthority);
93-
}
94-
95-
[Theory]
96-
[InlineData("https", "localhost", "8888", null)]
97-
[InlineData("http", "localhost", "80", "/test")]
98-
[InlineData("https", "localhost", "443", "/test")]
99-
[InlineData("https", "localhost", "8888", "/test")]
100-
public void GetUrl_HttpPort_RandomPort_With_HttpTarget(string scheme, string httpHost, string hostPort, string target)
101-
{
102-
var PartBTags = AzMonList.Initialize();
103-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpScheme, scheme));
104-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpHost, httpHost));
105-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpHostPort, hostPort));
106-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpTarget, target));
107-
108-
PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
109-
110-
hostPort = hostPort == "8888" ? ":8888" : null;
111-
Assert.Equal($"{scheme}://localhost{hostPort}{target}", url);
112-
Assert.Equal($"localhost{hostPort}", urlAuthority);
113-
}
114-
115-
[Theory]
116-
[InlineData("https", "10.0.0.1", "443", null)]
117-
[InlineData("https", "10.0.0.1", "443", "/test")]
118-
public void GetUrl_NetPeerIP_Success(string scheme, string peerIp, string peerPort, string target)
119-
{
120-
var PartBTags = AzMonList.Initialize();
121-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpScheme, scheme));
122-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeNetPeerIp, peerIp));
123-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeNetPeerPort, peerPort));
124-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpTarget, target));
125-
126-
PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
127-
128-
Assert.Equal($"https://10.0.0.1:443{target}", url);
129-
Assert.Equal("10.0.0.1:443", urlAuthority);
130-
}
131-
132-
[Theory]
133-
[InlineData("https", "localhost", "443", null)]
134-
[InlineData("https", "localhost", "443", "/test")]
135-
public void GetUrl_NetPeerName_Success(string scheme, string peerName, string peerPort, string target)
136-
{
137-
var PartBTags = AzMonList.Initialize();
138-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpScheme, scheme));
139-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeNetPeerName, peerName));
140-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeNetPeerPort, peerPort));
141-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpTarget, target));
142-
143-
PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
144-
Assert.Equal($"https://localhost:443{target}", url);
145-
Assert.Equal($"localhost:443", urlAuthority);
146-
}
147-
148-
[Theory]
149-
[InlineData("localhost", "", "")]
150-
[InlineData("localhost", "8888", "")]
151-
[InlineData("localhost", "8888", "/test")]
152-
[InlineData("localhost", null, null)]
153-
public void GetUrl_HttpHost_Success(string httpHost, string hostPort, string target)
154-
{
155-
var PartBTags = AzMonList.Initialize();
156-
157-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpHost, httpHost));
158-
159-
if (hostPort != "")
160-
{
161-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpHostPort, hostPort));
162-
}
163-
164-
if (target != "")
165-
{
166-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpTarget, target));
167-
}
168-
169-
PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
170-
hostPort = hostPort == "8888" ? ":8888" : null;
171-
Assert.Equal($"localhost{hostPort}{target}", url);
172-
Assert.Equal($"localhost{hostPort}", urlAuthority);
173-
}
174-
175-
[Fact]
176-
public void GetUrl_HttpUrl_Success()
177-
{
178-
var PartBTags = AzMonList.Initialize();
179-
AzMonList.Add(ref PartBTags, new KeyValuePair<string, object>(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com"));
180-
181-
PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
182-
Assert.Equal("https://www.wiki.com/", url);
183-
Assert.Equal("www.wiki.com", urlAuthority);
184-
}
185-
18611
[Fact]
18712
public void HttpRequestUrlIsSetUsingHttpUrl()
18813
{

0 commit comments

Comments
 (0)