in src/DotNetWorker.OpenTelemetry/FunctionsResourceDetector.cs [15:58]
public Resource Detect()
{
List<KeyValuePair<string, object>> attributeList = new(8);
try
{
string serviceName = Environment.GetEnvironmentVariable(OpenTelemetryConstants.SiteNameEnvVar);
string version = Assembly.GetEntryAssembly().GetName().Version.ToString();
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.ServiceVersion, version));
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.AISDKPrefix,
$@"{OpenTelemetryConstants.SDKPrefix}:{typeof(FunctionsResourceDetector).Assembly.GetName().Version}"));
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.ProcessId, Process.GetCurrentProcess().Id));
// 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 (!string.IsNullOrEmpty(azureResourceUri))
{
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.CloudResourceId, azureResourceUri));
}
}
else
{
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.ServiceName, Assembly.GetEntryAssembly().GetName().Name));
}
}
catch
{
// return empty resource.
return Resource.Empty;
}
return new Resource(attributeList);
}