-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Flex] Adding support for OpenTelemetry (#10094)
* OpenTelemetry support (#9985) Adding support for OpenTelemetry --------- Co-authored-by: Jacob Viau <javia@microsoft.com> Co-authored-by: Shyju Krishnankutty <connectshyju@gmail.com> Co-authored-by: Daniel Castro <castro.daniel@microsoft.com> * Updating Otel nuget packages. (#10014) * Updating Otel nuget packages. * Update Azure.Identity to 1.11.2 (#10037) * Update Microsoft.Identity.Client to 4.60.3 * Update Azure.Identity to 1.11.2 * Remove Microsoft.Identity.Client * Update WebJobs package in test projects (#10061) * Update PowerShell workers to latest (#10016) * Update Python Worker Version to 4.28.0 (#10009) Co-authored-by: AzureFunctionsPython <funcdisc@microsoft.com> * Update Node.js Worker to 3.10.0 (#9999) * Update Node.js Worker to 3.10.0 * Add PR reference * Update Python Worker Version to 4.28.1 (#10028) Co-authored-by: AzureFunctionsPython <funcdisc@microsoft.com> --------- Co-authored-by: Jacob Viau <javia@microsoft.com> Co-authored-by: andystaples <77818326+andystaples@users.noreply.github.com> Co-authored-by: gavin-aguiar <80794152+gavin-aguiar@users.noreply.github.com> Co-authored-by: AzureFunctionsPython <funcdisc@microsoft.com> Co-authored-by: Daniel Castro <castro.daniel@microsoft.com>
- Loading branch information
1 parent
018e67c
commit ee32ce6
Showing
44 changed files
with
1,622 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<Project> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Azure.Functions.PythonWorker" Version="4.27.0" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.PythonWorker" Version="4.28.1" /> | ||
</ItemGroup> | ||
</Project> |
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
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
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
38 changes: 38 additions & 0 deletions
38
src/WebJobs.Script/Diagnostics/OpenTelemetry/ActivitySanitizingProcessor.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,38 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using Microsoft.Azure.WebJobs.Logging; | ||
using OpenTelemetry; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Diagnostics.OpenTelemetry | ||
{ | ||
internal class ActivitySanitizingProcessor : BaseProcessor<Activity> | ||
{ | ||
private static readonly IReadOnlyCollection<string> TagsToSanitize = new HashSet<string> { ResourceSemanticConventions.QueryUrl, ResourceSemanticConventions.FullUrl }; | ||
|
||
private ActivitySanitizingProcessor() { } | ||
|
||
public static ActivitySanitizingProcessor Instance { get; } = new ActivitySanitizingProcessor(); | ||
|
||
public override void OnEnd(Activity data) | ||
{ | ||
Sanitize(data); | ||
|
||
base.OnEnd(data); | ||
} | ||
|
||
private static void Sanitize(Activity data) | ||
{ | ||
foreach (var t in TagsToSanitize) | ||
{ | ||
if (data.GetTagItem(t) is string s and not null) | ||
{ | ||
var sanitizedValue = Sanitizer.Sanitize(s); | ||
data.SetTag(t, sanitizedValue); | ||
} | ||
} | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/WebJobs.Script/Diagnostics/OpenTelemetry/FunctionsResourceDetector.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,71 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using OpenTelemetry.Resources; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Diagnostics.OpenTelemetry | ||
{ | ||
internal sealed class FunctionsResourceDetector : IResourceDetector | ||
{ | ||
public Resource Detect() | ||
{ | ||
List<KeyValuePair<string, object>> attributeList = new(9); | ||
try | ||
{ | ||
string serviceName = Environment.GetEnvironmentVariable(OpenTelemetryConstants.SiteNameEnvVar); | ||
string version = typeof(ScriptHost).Assembly.GetName().Version.ToString(); | ||
|
||
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.ServiceVersion, version)); | ||
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.AISDKPrefix, $@"{OpenTelemetryConstants.SDKPrefix}:{version}")); | ||
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.ProcessId, Process.GetCurrentProcess().Id)); | ||
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.FaaSVersion, version)); | ||
|
||
// Add these attributes only if running in Azure. | ||
if (!string.IsNullOrEmpty(serviceName)) | ||
{ | ||
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.ServiceName, serviceName)); | ||
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.CloudProvider, OpenTelemetryConstants.AzureCloudProviderValue)); | ||
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.CloudPlatform, OpenTelemetryConstants.AzurePlatformValue)); | ||
|
||
string region = Environment.GetEnvironmentVariable(OpenTelemetryConstants.RegionNameEnvVar); | ||
if (!string.IsNullOrEmpty(region)) | ||
{ | ||
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.CloudRegion, region)); | ||
} | ||
|
||
var azureResourceUri = GetAzureResourceURI(serviceName); | ||
if (azureResourceUri != null) | ||
{ | ||
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.CloudResourceId, azureResourceUri)); | ||
} | ||
} | ||
} | ||
catch | ||
{ | ||
// return empty resource. | ||
return Resource.Empty; | ||
} | ||
|
||
return new Resource(attributeList); | ||
} | ||
|
||
private static string GetAzureResourceURI(string websiteSiteName) | ||
{ | ||
string websiteResourceGroup = Environment.GetEnvironmentVariable(OpenTelemetryConstants.ResourceGroupEnvVar); | ||
string websiteOwnerName = Environment.GetEnvironmentVariable(OpenTelemetryConstants.OwnerNameEnvVar) ?? string.Empty; | ||
int idx = websiteOwnerName.IndexOf('+', StringComparison.Ordinal); | ||
string subscriptionId = idx > 0 ? websiteOwnerName.Substring(0, idx) : websiteOwnerName; | ||
|
||
if (string.IsNullOrEmpty(websiteResourceGroup) || string.IsNullOrEmpty(subscriptionId)) | ||
{ | ||
return null; | ||
} | ||
|
||
return $"/subscriptions/{subscriptionId}/resourceGroups/{websiteResourceGroup}/providers/Microsoft.Web/sites/{websiteSiteName}"; | ||
} | ||
} | ||
} |
Oops, something went wrong.