-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure Monitor Exporter - Match HTTP URL retrieval to OpenTelemetry specification #14834
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f36e198
Add EventSource
rajkumar-rangaraj f3b7976
Add Changelog,readme
rajkumar-rangaraj 76304cc
Header to readme
rajkumar-rangaraj ddc78a7
Readme header change.
rajkumar-rangaraj e87111a
update readme
rajkumar-rangaraj b982866
Merge remote-tracking branch 'origin/master' into rajrang/sdkver
rajkumar-rangaraj 9cc4fdf
Add Sdkversion
rajkumar-rangaraj 64afaa5
Addressing PR feedback
rajkumar-rangaraj 4524d60
Handled exception in SdkVersionUtils
rajkumar-rangaraj d23978c
Fixed indent
rajkumar-rangaraj a3077ac
Tags parsing, duration fix for dependency.
rajkumar-rangaraj d5c8b97
Resolve conflict
rajkumar-rangaraj c2a1208
Renamed GetHttpUrl
rajkumar-rangaraj cf2749c
Merge remote-tracking branch 'origin/master' into rajrang/tags
rajkumar-rangaraj 830efa7
status change
rajkumar-rangaraj 271cde7
Modify to xunit
rajkumar-rangaraj 3994f8d
Merge
rajkumar-rangaraj 3101044
Added test for GetUrl
rajkumar-rangaraj e7e42bd
Merge remote-tracking branch 'origin/master' into rajrang/tags
rajkumar-rangaraj 21f0910
Incorporating PR comments
rajkumar-rangaraj 1fe5c3d
Revert extension/RDD change
rajkumar-rangaraj fef68a9
Merge remote-tracking branch 'origin/master' into rajrang/tags
rajkumar-rangaraj 3a33480
Add method summary.
rajkumar-rangaraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 17 additions & 0 deletions
17
sdk/monitor/OpenTelemetry.Exporter.AzureMonitor/src/PartBType.cs
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,17 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace OpenTelemetry.Exporter.AzureMonitor | ||
{ | ||
internal enum PartBType | ||
{ | ||
Unknown, | ||
Http, | ||
Db, | ||
Messaging, | ||
Rpc, | ||
FaaS, | ||
Net | ||
}; | ||
|
||
} |
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 |
---|---|---|
|
@@ -114,6 +114,7 @@ internal static class SemanticConventions | |
|
||
public const string AttributeFaasTrigger = "faas.trigger"; | ||
public const string AttributeFaasExecution = "faas.execution"; | ||
public const string AttributeFaasColdStart = "faas.coldstart"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: sort alphabetically to make it easier for future maintenance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whole file needs rearrangement will get this covered in different PR. |
||
public const string AttributeFaasDocumentCollection = "faas.document.collection"; | ||
public const string AttributeFaasDocumentOperation = "faas.document.operation"; | ||
public const string AttributeFaasDocumentTime = "faas.document.time"; | ||
|
81 changes: 81 additions & 0 deletions
81
sdk/monitor/OpenTelemetry.Exporter.AzureMonitor/src/TagsExtension.cs
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,81 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace OpenTelemetry.Exporter.AzureMonitor | ||
{ | ||
internal static class TagsExtension | ||
{ | ||
private static readonly IReadOnlyDictionary<string, PartBType> Part_B_Mapping = new Dictionary<string, PartBType>() | ||
{ | ||
[SemanticConventions.AttributeDbSystem] = PartBType.Db, | ||
[SemanticConventions.AttributeDbConnectionString] = PartBType.Db, | ||
[SemanticConventions.AttributeDbUser] = PartBType.Db, | ||
|
||
[SemanticConventions.AttributeHttpMethod] = PartBType.Http, | ||
[SemanticConventions.AttributeHttpUrl] = PartBType.Http, | ||
[SemanticConventions.AttributeHttpStatusCode] = PartBType.Http, | ||
[SemanticConventions.AttributeHttpScheme] = PartBType.Http, | ||
[SemanticConventions.AttributeHttpHost] = PartBType.Http, | ||
[SemanticConventions.AttributeHttpTarget] = PartBType.Http, | ||
|
||
[SemanticConventions.AttributeNetPeerName] = PartBType.Net, | ||
[SemanticConventions.AttributeNetPeerIp] = PartBType.Net, | ||
[SemanticConventions.AttributeNetPeerPort] = PartBType.Net, | ||
[SemanticConventions.AttributeNetTransport] = PartBType.Net, | ||
[SemanticConventions.AttributeNetHostIp] = PartBType.Net, | ||
[SemanticConventions.AttributeNetHostPort] = PartBType.Net, | ||
[SemanticConventions.AttributeNetHostName] = PartBType.Net, | ||
|
||
[SemanticConventions.AttributeRpcSystem] = PartBType.Rpc, | ||
[SemanticConventions.AttributeRpcService] = PartBType.Rpc, | ||
[SemanticConventions.AttributeRpcMethod] = PartBType.Rpc, | ||
|
||
[SemanticConventions.AttributeFaasTrigger] = PartBType.FaaS, | ||
[SemanticConventions.AttributeFaasExecution] = PartBType.FaaS, | ||
[SemanticConventions.AttributeFaasColdStart] = PartBType.FaaS, | ||
[SemanticConventions.AttributeFaasDocumentCollection] = PartBType.FaaS, | ||
[SemanticConventions.AttributeFaasDocumentOperation] = PartBType.FaaS, | ||
[SemanticConventions.AttributeFaasDocumentTime] = PartBType.FaaS, | ||
[SemanticConventions.AttributeFaasDocumentName] = PartBType.FaaS, | ||
[SemanticConventions.AttributeFaasCron] = PartBType.FaaS, | ||
[SemanticConventions.AttributeFaasTime] = PartBType.FaaS, | ||
|
||
[SemanticConventions.AttributeMessagingSystem] = PartBType.Messaging, | ||
[SemanticConventions.AttributeMessagingDestination] = PartBType.Messaging, | ||
[SemanticConventions.AttributeMessagingDestinationKind] = PartBType.Messaging, | ||
[SemanticConventions.AttributeMessagingTempDestination] = PartBType.Messaging, | ||
[SemanticConventions.AttributeMessagingUrl] = PartBType.Messaging | ||
}; | ||
|
||
internal static Dictionary<string, string> ToAzureMonitorTags(this IEnumerable<KeyValuePair<string, string>> tags, out PartBType activityType) | ||
{ | ||
Dictionary<string, string> partBTags = new Dictionary<string, string>(); | ||
activityType = PartBType.Unknown; | ||
|
||
foreach (var entry in tags) | ||
{ | ||
// TODO: May need to store unknown to write to properties as Part C | ||
if ((activityType == PartBType.Unknown || activityType == PartBType.Net) && !Part_B_Mapping.TryGetValue(entry.Key, out activityType)) | ||
{ | ||
if (activityType == PartBType.Net) | ||
{ | ||
partBTags.Add(entry.Key, entry.Value); | ||
activityType = PartBType.Unknown; | ||
} | ||
|
||
continue; | ||
} | ||
|
||
if (Part_B_Mapping.TryGetValue(entry.Key, out var tempActivityType) && (tempActivityType == activityType || tempActivityType == PartBType.Net)) | ||
{ | ||
partBTags.Add(entry.Key, entry.Value); | ||
} | ||
} | ||
|
||
return partBTags; | ||
} | ||
|
||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
sdk/monitor/OpenTelemetry.Exporter.AzureMonitor/src/UrlHelper.cs
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,72 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace OpenTelemetry.Exporter.AzureMonitor | ||
{ | ||
internal class UrlHelper | ||
{ | ||
private const string SchemePostfix = "://"; | ||
private const string Colon = ":"; | ||
|
||
/// <summary> | ||
/// This method follows OpenTelemetry specification to retrieve http URL. | ||
/// Reference: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#http-client. | ||
/// </summary> | ||
/// <param name="tags">Activity Tags</param> | ||
/// <returns></returns> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal static string GetUrl(Dictionary<string, string> tags) | ||
rajkumar-rangaraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (tags.TryGetValue(SemanticConventions.AttributeHttpUrl, out var url)) | ||
{ | ||
if (Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uri) && uri.IsAbsoluteUri) | ||
{ | ||
return url; | ||
} | ||
} | ||
|
||
if (tags.TryGetValue(SemanticConventions.AttributeHttpScheme, out var httpScheme)) | ||
{ | ||
tags.TryGetValue(SemanticConventions.AttributeHttpTarget, out var httpTarget); | ||
if (tags.TryGetValue(SemanticConventions.AttributeHttpHost, out var httpHost) && !string.IsNullOrWhiteSpace(httpHost)) | ||
{ | ||
tags.TryGetValue(SemanticConventions.AttributeHttpHostPort, out var httpPort); | ||
if (httpPort != null && httpPort != "80" && httpPort != "443") | ||
{ | ||
url = $"{httpScheme}{SchemePostfix}{httpHost}{Colon}{httpPort}{httpTarget}"; | ||
} | ||
else | ||
{ | ||
url = $"{httpScheme}{SchemePostfix}{httpHost}{httpTarget}"; | ||
} | ||
|
||
return url; | ||
} | ||
else if (tags.TryGetValue(SemanticConventions.AttributeNetPeerName, out var netPeerName) | ||
&& tags.TryGetValue(SemanticConventions.AttributeNetPeerPort, out var netPeerPort)) | ||
{ | ||
return string.IsNullOrWhiteSpace(netPeerName) ? null : $"{httpScheme}{SchemePostfix}{netPeerName}{(string.IsNullOrWhiteSpace(netPeerPort) ? null : Colon)}{netPeerPort}{httpTarget}"; | ||
} | ||
else if (tags.TryGetValue(SemanticConventions.AttributeNetPeerIp, out var netPeerIP) | ||
&& tags.TryGetValue(SemanticConventions.AttributeNetPeerPort, out netPeerPort)) | ||
{ | ||
return string.IsNullOrWhiteSpace(netPeerIP) ? null : $"{httpScheme}{SchemePostfix}{netPeerIP}{(string.IsNullOrWhiteSpace(netPeerPort) ? null : Colon)}{netPeerPort}{httpTarget}"; | ||
} | ||
} | ||
|
||
if (tags.TryGetValue(SemanticConventions.AttributeHttpHost, out var host) && !string.IsNullOrWhiteSpace(host)) | ||
{ | ||
tags.TryGetValue(SemanticConventions.AttributeHttpTarget, out var httpTarget); | ||
tags.TryGetValue(SemanticConventions.AttributeHttpHostPort, out var httpPort); | ||
url = $"{host}{(string.IsNullOrWhiteSpace(httpPort) ? null : Colon)}{httpPort}{httpTarget}"; | ||
return url; | ||
} | ||
|
||
return string.IsNullOrWhiteSpace(url) ? null : url; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be using TagObjects instead of Tags. Tags only contain a subset of TagObjects which are string value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a TODO section, will get this handled in a separate PR. This changes requires a custom serialization to generated classes.