From f20605c3e89bc4a31605b7e07823c5d8d5334ce3 Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Wed, 11 Sep 2024 13:20:45 +0200 Subject: [PATCH 1/9] add support for Container App Jobs Fixes #2036 --- .../AzureContainerAppsResourceDetector.cs | 52 +++++++++++++------ .../ResourceAttributeConstants.cs | 3 ++ .../AzureResourceDetectorTests.cs | 38 ++++++++++++-- 3 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/OpenTelemetry.Resources.Azure/AzureContainerAppsResourceDetector.cs b/src/OpenTelemetry.Resources.Azure/AzureContainerAppsResourceDetector.cs index 97339af6e9..58c11aa2bd 100644 --- a/src/OpenTelemetry.Resources.Azure/AzureContainerAppsResourceDetector.cs +++ b/src/OpenTelemetry.Resources.Azure/AzureContainerAppsResourceDetector.cs @@ -10,35 +10,38 @@ namespace OpenTelemetry.Resources.Azure; /// internal sealed class AzureContainerAppsResourceDetector : IResourceDetector { - internal static readonly IReadOnlyDictionary AzureContainerResourceAttributes = new Dictionary + internal static readonly IReadOnlyDictionary AzureContainerAppResourceAttributes = new Dictionary { { ResourceSemanticConventions.AttributeServiceInstance, ResourceAttributeConstants.AzureContainerAppsReplicaNameEnvVar }, { ResourceSemanticConventions.AttributeServiceVersion, ResourceAttributeConstants.AzureContainerAppsRevisionEnvVar }, }; + internal static readonly IReadOnlyDictionary AzureContainerAppJobResourceAttributes = new Dictionary + { + { ResourceSemanticConventions.AttributeServiceInstance, ResourceAttributeConstants.AzureContainerAppsReplicaNameEnvVar }, + { ResourceSemanticConventions.AttributeServiceVersion, ResourceAttributeConstants.AzureContainerAppJobExecutionNameEnvVar }, + }; + /// public Resource Detect() { - List> attributeList = new(); - + List> attributeList = new List>(); try { var containerAppName = Environment.GetEnvironmentVariable(ResourceAttributeConstants.AzureContainerAppsNameEnvVar); + var containerAppJobName = Environment.GetEnvironmentVariable(ResourceAttributeConstants.AzureContainerAppJobNameEnvVar); if (containerAppName != null) { - attributeList.Add(new KeyValuePair(ResourceSemanticConventions.AttributeServiceName, containerAppName)); - attributeList.Add(new KeyValuePair(ResourceSemanticConventions.AttributeCloudProvider, ResourceAttributeConstants.AzureCloudProviderValue)); - attributeList.Add(new KeyValuePair(ResourceSemanticConventions.AttributeCloudPlatform, ResourceAttributeConstants.AzureContainerAppsPlatformValue)); - - foreach (var kvp in AzureContainerResourceAttributes) - { - var attributeValue = Environment.GetEnvironmentVariable(kvp.Value); - if (attributeValue != null) - { - attributeList.Add(new KeyValuePair(kvp.Key, attributeValue)); - } - } + AddBaseAttributes(attributeList, containerAppName); + + AddResourceAttributes(attributeList, AzureContainerAppResourceAttributes); + } + else if (containerAppJobName != null) + { + AddBaseAttributes(attributeList, containerAppJobName); + + AddResourceAttributes(attributeList, AzureContainerAppJobResourceAttributes); } } catch @@ -49,4 +52,23 @@ public Resource Detect() return new Resource(attributeList); } + + private static void AddResourceAttributes(List> attributeList, IReadOnlyDictionary resourceAttributes) + { + foreach (var kvp in resourceAttributes) + { + var attributeValue = Environment.GetEnvironmentVariable(kvp.Value); + if (attributeValue != null) + { + attributeList.Add(new KeyValuePair(kvp.Key, attributeValue)); + } + } + } + + private static void AddBaseAttributes(List> attributeList, string serviceName) + { + attributeList.Add(new KeyValuePair(ResourceSemanticConventions.AttributeServiceName, serviceName)); + attributeList.Add(new KeyValuePair(ResourceSemanticConventions.AttributeCloudProvider, ResourceAttributeConstants.AzureCloudProviderValue)); + attributeList.Add(new KeyValuePair(ResourceSemanticConventions.AttributeCloudPlatform, ResourceAttributeConstants.AzureContainerAppsPlatformValue)); + } } diff --git a/src/OpenTelemetry.Resources.Azure/ResourceAttributeConstants.cs b/src/OpenTelemetry.Resources.Azure/ResourceAttributeConstants.cs index 3a4a669a08..41515803cd 100644 --- a/src/OpenTelemetry.Resources.Azure/ResourceAttributeConstants.cs +++ b/src/OpenTelemetry.Resources.Azure/ResourceAttributeConstants.cs @@ -27,6 +27,9 @@ internal sealed class ResourceAttributeConstants internal const string AzureContainerAppsReplicaNameEnvVar = "CONTAINER_APP_REPLICA_NAME"; internal const string AzureContainerAppsRevisionEnvVar = "CONTAINER_APP_REVISION"; + internal const string AzureContainerAppJobNameEnvVar = "CONTAINER_APP_JOB_NAME"; + internal const string AzureContainerAppJobExecutionNameEnvVar = "CONTAINER_APP_JOB_EXECUTION_NAME"; + // Azure resource attributes constant values internal const string AzureAppServicePlatformValue = "azure_app_service"; internal const string AzureCloudProviderValue = "azure"; diff --git a/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs b/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs index 3e226d5d8e..a3bde23068 100644 --- a/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs +++ b/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs @@ -97,7 +97,7 @@ public void AzureContainerAppsResourceDetectorReturnsResourceWithAttributes() { try { - foreach (var kvp in AzureContainerAppsResourceDetector.AzureContainerResourceAttributes) + foreach (var kvp in AzureContainerAppsResourceDetector.AzureContainerAppResourceAttributes) { Environment.SetEnvironmentVariable(kvp.Value, kvp.Key); } @@ -113,7 +113,34 @@ public void AzureContainerAppsResourceDetectorReturnsResourceWithAttributes() Assert.Contains(new KeyValuePair(ResourceSemanticConventions.AttributeServiceName, "containerAppName"), resource.Attributes); - foreach (var kvp in AzureContainerAppsResourceDetector.AzureContainerResourceAttributes) + foreach (var kvp in AzureContainerAppsResourceDetector.AzureContainerAppResourceAttributes) + { + Assert.Contains(new KeyValuePair(kvp.Key, kvp.Key), resource.Attributes); + } + } + + [Fact] + public void AzureContainerAppsJobResourceDetectorReturnsResourceWithAttributes() + { + try + { + foreach (var kvp in AzureContainerAppsResourceDetector.AzureContainerAppJobResourceAttributes) + { + Environment.SetEnvironmentVariable(kvp.Value, kvp.Key); + } + + Environment.SetEnvironmentVariable(ResourceAttributeConstants.AzureContainerAppJobNameEnvVar, "containerAppName"); + } + catch + { + } + + var resource = ResourceBuilder.CreateEmpty().AddAzureContainerAppsDetector().Build(); + Assert.NotNull(resource); + + Assert.Contains(new KeyValuePair(ResourceSemanticConventions.AttributeServiceName, "containerAppName"), resource.Attributes); + + foreach (var kvp in AzureContainerAppsResourceDetector.AzureContainerAppJobResourceAttributes) { Assert.Contains(new KeyValuePair(kvp.Key, kvp.Key), resource.Attributes); } @@ -126,7 +153,12 @@ public void Dispose() Environment.SetEnvironmentVariable(kvp.Value, null); } - foreach (var kvp in AzureContainerAppsResourceDetector.AzureContainerResourceAttributes) + foreach (var kvp in AzureContainerAppsResourceDetector.AzureContainerAppResourceAttributes) + { + Environment.SetEnvironmentVariable(kvp.Value, null); + } + + foreach (var kvp in AzureContainerAppsResourceDetector.AzureContainerAppJobResourceAttributes) { Environment.SetEnvironmentVariable(kvp.Value, null); } From fa5e93888c72ab74cc4fc5a4d022d8f0c35b4d5e Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Wed, 11 Sep 2024 15:43:04 +0200 Subject: [PATCH 2/9] Update channgelog and readme --- src/OpenTelemetry.Resources.Azure/CHANGELOG.md | 3 +++ src/OpenTelemetry.Resources.Azure/README.md | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Resources.Azure/CHANGELOG.md b/src/OpenTelemetry.Resources.Azure/CHANGELOG.md index 538efdf078..445f6f14fa 100644 --- a/src/OpenTelemetry.Resources.Azure/CHANGELOG.md +++ b/src/OpenTelemetry.Resources.Azure/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Added support for [Azure Container Apps jobs](https://learn.microsoft.com/en-us/azure/container-apps/jobs?tabs=azure-cli). + ([#2064](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2064)) + ## 1.0.0-beta.8 Released 2024-Jun-18 diff --git a/src/OpenTelemetry.Resources.Azure/README.md b/src/OpenTelemetry.Resources.Azure/README.md index a5850289ac..4e290c528a 100644 --- a/src/OpenTelemetry.Resources.Azure/README.md +++ b/src/OpenTelemetry.Resources.Azure/README.md @@ -98,7 +98,7 @@ using var meterProvider = Sdk.CreateMeterProviderBuilder() ## Azure Container Apps Resource Detector -Adds resource attributes for the applications running in Azure Container Apps. +Adds resource attributes for the applications running in Azure Container Apps or Azure Container App jobs. The following example shows how to add `AzureContainerAppsResourceDetector` to the `ResourceBuilder`. @@ -122,5 +122,5 @@ using var meterProvider = Sdk.CreateMeterProviderBuilder() | cloud.platform | The cloud platform. Here, it's always "azure_container_apps". | | cloud.provider | The cloud service provider. In this context, it's always "azure". | | service.instance.id | Represents the specific instance ID of Azure Container Apps, useful in scaled-out configurations. | -| service.name | The name of the Azure Container Apps. | -| service.version | The current revision or version of Azure Container Apps. | +| service.name | The name of the Azure Container Apps or Azure Container Apps job. | +| service.version | The current revision or version of Azure Container Apps, or in case of a Azure Container Apps job - the job execution name. | From d75fa62e42837760a7a17aa6a8bafccf6216c374 Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Wed, 11 Sep 2024 17:17:00 +0200 Subject: [PATCH 3/9] Fix line length in markdown --- src/OpenTelemetry.Resources.Azure/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Resources.Azure/README.md b/src/OpenTelemetry.Resources.Azure/README.md index 4e290c528a..d35976575e 100644 --- a/src/OpenTelemetry.Resources.Azure/README.md +++ b/src/OpenTelemetry.Resources.Azure/README.md @@ -98,9 +98,9 @@ using var meterProvider = Sdk.CreateMeterProviderBuilder() ## Azure Container Apps Resource Detector -Adds resource attributes for the applications running in Azure Container Apps or Azure Container App jobs. -The following example shows how to add `AzureContainerAppsResourceDetector` to -the `ResourceBuilder`. +Adds resource attributes for the applications running in Azure Container Apps +or Azure Container App jobs. The following example shows how to add +`AzureContainerAppsResourceDetector` to the `ResourceBuilder`. ```csharp using OpenTelemetry; From 07dd52026ba37b6d0a24ac97702bf2bc86bd2341 Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Wed, 11 Sep 2024 17:17:05 +0200 Subject: [PATCH 4/9] Fix test --- .../AzureResourceDetectorTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs b/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs index a3bde23068..4102a0646b 100644 --- a/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs +++ b/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs @@ -129,7 +129,7 @@ public void AzureContainerAppsJobResourceDetectorReturnsResourceWithAttributes() Environment.SetEnvironmentVariable(kvp.Value, kvp.Key); } - Environment.SetEnvironmentVariable(ResourceAttributeConstants.AzureContainerAppJobNameEnvVar, "containerAppName"); + Environment.SetEnvironmentVariable(ResourceAttributeConstants.AzureContainerAppJobNameEnvVar, "containerAppJobName"); } catch { @@ -138,7 +138,7 @@ public void AzureContainerAppsJobResourceDetectorReturnsResourceWithAttributes() var resource = ResourceBuilder.CreateEmpty().AddAzureContainerAppsDetector().Build(); Assert.NotNull(resource); - Assert.Contains(new KeyValuePair(ResourceSemanticConventions.AttributeServiceName, "containerAppName"), resource.Attributes); + Assert.Contains(new KeyValuePair(ResourceSemanticConventions.AttributeServiceName, "containerAppJobName"), resource.Attributes); foreach (var kvp in AzureContainerAppsResourceDetector.AzureContainerAppJobResourceAttributes) { From 9789fb6b831f008d5fedb00b19864d3da3c40c9e Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Thu, 12 Sep 2024 09:46:11 +0200 Subject: [PATCH 5/9] Label environment variables for Azure Container Apps Jobs Co-authored-by: Timothy Mothra --- src/OpenTelemetry.Resources.Azure/ResourceAttributeConstants.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenTelemetry.Resources.Azure/ResourceAttributeConstants.cs b/src/OpenTelemetry.Resources.Azure/ResourceAttributeConstants.cs index 41515803cd..98a2ab3d75 100644 --- a/src/OpenTelemetry.Resources.Azure/ResourceAttributeConstants.cs +++ b/src/OpenTelemetry.Resources.Azure/ResourceAttributeConstants.cs @@ -27,6 +27,7 @@ internal sealed class ResourceAttributeConstants internal const string AzureContainerAppsReplicaNameEnvVar = "CONTAINER_APP_REPLICA_NAME"; internal const string AzureContainerAppsRevisionEnvVar = "CONTAINER_APP_REVISION"; + // Azure Container Apps Jobs environment variables internal const string AzureContainerAppJobNameEnvVar = "CONTAINER_APP_JOB_NAME"; internal const string AzureContainerAppJobExecutionNameEnvVar = "CONTAINER_APP_JOB_EXECUTION_NAME"; From 31dd016859edcf50f0f581522c28f9c6c50548ce Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Thu, 12 Sep 2024 16:18:41 +0200 Subject: [PATCH 6/9] Add sample app to show the ContainerAppJob detection behavior --- .../Example.ContainerAppJob.csproj | 28 +++++++ .../IHostApplicationBuilderExtensions.cs | 76 +++++++++++++++++++ .../OpenTelemetryDiagnostics.cs | 12 +++ .../Azure/Example.ContainerAppJob/Program.cs | 14 ++++ .../Properties/launchSettings.json | 12 +++ .../Azure/Example.ContainerAppJob/README.md | 43 +++++++++++ .../Azure/Example.ContainerAppJob/Worker.cs | 49 ++++++++++++ .../appsettings.Development.json | 8 ++ .../Example.ContainerAppJob/appsettings.json | 8 ++ opentelemetry-dotnet-contrib.sln | 30 +++++--- 10 files changed, 270 insertions(+), 10 deletions(-) create mode 100644 examples/Azure/Example.ContainerAppJob/Example.ContainerAppJob.csproj create mode 100644 examples/Azure/Example.ContainerAppJob/IHostApplicationBuilderExtensions.cs create mode 100644 examples/Azure/Example.ContainerAppJob/OpenTelemetryDiagnostics.cs create mode 100644 examples/Azure/Example.ContainerAppJob/Program.cs create mode 100644 examples/Azure/Example.ContainerAppJob/Properties/launchSettings.json create mode 100644 examples/Azure/Example.ContainerAppJob/README.md create mode 100644 examples/Azure/Example.ContainerAppJob/Worker.cs create mode 100644 examples/Azure/Example.ContainerAppJob/appsettings.Development.json create mode 100644 examples/Azure/Example.ContainerAppJob/appsettings.json diff --git a/examples/Azure/Example.ContainerAppJob/Example.ContainerAppJob.csproj b/examples/Azure/Example.ContainerAppJob/Example.ContainerAppJob.csproj new file mode 100644 index 0000000000..38dd22914c --- /dev/null +++ b/examples/Azure/Example.ContainerAppJob/Example.ContainerAppJob.csproj @@ -0,0 +1,28 @@ + + + + net8.0 + enable + enable + dotnet-Example.ContainerAppJob-78bba48b-2c15-4a83-b45a-be47cf7bfe82 + + true + true + opentelemetry-containerapp-job + + + + + + + + + + + + + + + + + diff --git a/examples/Azure/Example.ContainerAppJob/IHostApplicationBuilderExtensions.cs b/examples/Azure/Example.ContainerAppJob/IHostApplicationBuilderExtensions.cs new file mode 100644 index 0000000000..4c720fa413 --- /dev/null +++ b/examples/Azure/Example.ContainerAppJob/IHostApplicationBuilderExtensions.cs @@ -0,0 +1,76 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using Azure.Monitor.OpenTelemetry.AspNetCore; +using OpenTelemetry; +using OpenTelemetry.Metrics; +using OpenTelemetry.Resources.Azure; +using OpenTelemetry.Trace; + +namespace Example.ContainerAppJob; + +public static class IHostApplicationBuilderExtensions +{ + public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder) + { + builder.AddAzureContainerAppsDetector(); + + builder.Logging.AddOpenTelemetry(logging => + { + logging.IncludeFormattedMessage = true; + logging.IncludeScopes = true; + }); + + builder.Services.AddOpenTelemetry() + .WithMetrics(metrics => + { + metrics.AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation() + .AddRuntimeInstrumentation(); + }) + .WithTracing(tracing => + { + tracing.AddSource("Example.ContainerAppJob") + .AddAspNetCoreInstrumentation() + + // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) + // .AddGrpcClientInstrumentation() + .AddHttpClientInstrumentation(); + }); + + builder.AddOpenTelemetryExporters(); + + return builder; + } + + private static IHostApplicationBuilder AddAzureContainerAppsDetector(this IHostApplicationBuilder builder) + { + // Using AzureContainerAppsResourceDetector here requires adding the InternalsVisibleTo attribute in the OpenTelemetry.Resources.Azure package. + builder.Services.AddSingleton(); + + builder.Services.AddOpenTelemetry() + .ConfigureResource(builder => builder + .AddDetector(sp => + sp.GetRequiredService())); + + return builder; + } + + private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostApplicationBuilder builder) + { + var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); + + if (useOtlpExporter) + { + builder.Services.AddOpenTelemetry().UseOtlpExporter(); + } + + if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"])) + { + builder.Services.AddOpenTelemetry() + .UseAzureMonitor(); + } + + return builder; + } +} diff --git a/examples/Azure/Example.ContainerAppJob/OpenTelemetryDiagnostics.cs b/examples/Azure/Example.ContainerAppJob/OpenTelemetryDiagnostics.cs new file mode 100644 index 0000000000..6993068bde --- /dev/null +++ b/examples/Azure/Example.ContainerAppJob/OpenTelemetryDiagnostics.cs @@ -0,0 +1,12 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using System.Diagnostics; + +namespace Example.ContainerAppJob; + +public static class OpenTelemetryDiagnostics +{ + public const string SourceName = "Example.ContainerAppJob"; + public static readonly ActivitySource ActivitySource = new ActivitySource(SourceName); +} diff --git a/examples/Azure/Example.ContainerAppJob/Program.cs b/examples/Azure/Example.ContainerAppJob/Program.cs new file mode 100644 index 0000000000..031b389bb0 --- /dev/null +++ b/examples/Azure/Example.ContainerAppJob/Program.cs @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using Example.ContainerAppJob; + +var builder = Host.CreateApplicationBuilder(args); + +builder.ConfigureOpenTelemetry(); + +builder.Services.AddHttpClient(); +builder.Services.AddHostedService(); + +var host = builder.Build(); +host.Run(); diff --git a/examples/Azure/Example.ContainerAppJob/Properties/launchSettings.json b/examples/Azure/Example.ContainerAppJob/Properties/launchSettings.json new file mode 100644 index 0000000000..c34539800d --- /dev/null +++ b/examples/Azure/Example.ContainerAppJob/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "Example.ContainerAppJob": { + "commandName": "Project", + "dotnetRunMessages": true, + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + } + } +} diff --git a/examples/Azure/Example.ContainerAppJob/README.md b/examples/Azure/Example.ContainerAppJob/README.md new file mode 100644 index 0000000000..ecab32c2ef --- /dev/null +++ b/examples/Azure/Example.ContainerAppJob/README.md @@ -0,0 +1,43 @@ +# Example.ContainerAppJob + +This example demonstrates the working of the `AzureContainerAppsResourceDetector` +in the context of an Azure Container Apps job. + +It is intended to run the container image in an Azure Container Apps job. +It expects the `AZURE_APPINSIGHTS_CONNECTION_STRING` environment variable +to be set with the connection string of an Azure Application Insights resource. + +## Building it + +To build this app, run the following command from the project directory: + +```shell +dotnet publish -c Release -r linux-x64 -p:PublishProfile=DefaultContainer +``` + +Upload it to your container registry: + +```shell +az acr login --name +docker tag opentelemetry-containerapp-job .azurecr.io/opentelemetry-containerapp-job +docker push .azurecr.io/opentelemetry-containerapp-job +``` + +## Prerequisites + +- Resources in Azure: + + - Azure Container Apps job + - Azure Container Registry + - Azure Application Insights + +- Building the code requires + - adding the `InternalsVisibleTo` attribute in `AssemblyInfo.cs` + in the the `OpenTelemetry.Resources.Azure` project because the + `AzureContainerAppsResourceDetector` class is marked `internal`. + + ```csharp + [assembly: InternalsVisibleTo("Example.ContainerAppJob")] + ``` + + - running docker or podman on the machine diff --git a/examples/Azure/Example.ContainerAppJob/Worker.cs b/examples/Azure/Example.ContainerAppJob/Worker.cs new file mode 100644 index 0000000000..73286f42ac --- /dev/null +++ b/examples/Azure/Example.ContainerAppJob/Worker.cs @@ -0,0 +1,49 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using System.Collections; +using OpenTelemetry.Trace; + +namespace Example.ContainerAppJob; + +public class Worker(IHostApplicationLifetime hostApplicationLifetime, IHttpClientFactory httpClientFactory) : BackgroundService +{ + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + using (var exampleActivity = OpenTelemetryDiagnostics.ActivitySource.StartActivity("Example activity")) + { + try + { + await Task.Delay(1000, stoppingToken); + exampleActivity?.AddEvent(new System.Diagnostics.ActivityEvent("Example event")); + + var client = httpClientFactory.CreateClient(); + var testUri = new Uri("https://www.microsoft.com/"); + var result = await client.GetAsync(testUri, stoppingToken); + + // Loop over environment variables and add them as tags + foreach (DictionaryEntry envVar in (IDictionary)Environment.GetEnvironmentVariables()) + { + if (envVar.Key is null) + { + continue; + } + + exampleActivity?.SetTag(envVar.Key.ToString()!, envVar.Value?.ToString()); + } + + await Task.Delay(1000, stoppingToken); + + // Simulate an exception. + throw new Exception("Example exception"); + } + catch (Exception ex) + { + exampleActivity?.RecordException(ex); + } + } + + // When completed, the entire app host will stop. + hostApplicationLifetime.StopApplication(); + } +} diff --git a/examples/Azure/Example.ContainerAppJob/appsettings.Development.json b/examples/Azure/Example.ContainerAppJob/appsettings.Development.json new file mode 100644 index 0000000000..b2dcdb6742 --- /dev/null +++ b/examples/Azure/Example.ContainerAppJob/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/examples/Azure/Example.ContainerAppJob/appsettings.json b/examples/Azure/Example.ContainerAppJob/appsettings.json new file mode 100644 index 0000000000..b2dcdb6742 --- /dev/null +++ b/examples/Azure/Example.ContainerAppJob/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/opentelemetry-dotnet-contrib.sln b/opentelemetry-dotnet-contrib.sln index 635826b25b..8cad305cc8 100644 --- a/opentelemetry-dotnet-contrib.sln +++ b/opentelemetry-dotnet-contrib.sln @@ -392,6 +392,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "kafka", "kafka", "{3A464E7A EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.ConfluentKafka", "examples\kafka\Examples.ConfluentKafka.csproj", "{9B994669-E839-4C42-A0F1-DF9DD058C1DC}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Azure", "Azure", "{93B1028C-4FA7-4F63-8262-09CFD38930A5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.ContainerAppJob", "examples\Azure\Example.ContainerAppJob\Example.ContainerAppJob.csproj", "{BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -722,6 +726,14 @@ Global {A5EF701C-439E-407F-8BB4-394166000C6D}.Debug|Any CPU.Build.0 = Debug|Any CPU {A5EF701C-439E-407F-8BB4-394166000C6D}.Release|Any CPU.ActiveCfg = Release|Any CPU {A5EF701C-439E-407F-8BB4-394166000C6D}.Release|Any CPU.Build.0 = Release|Any CPU + {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Release|Any CPU.Build.0 = Release|Any CPU + {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Release|Any CPU.Build.0 = Release|Any CPU {033CA8D4-1529-413A-B244-07958D5F9A48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {033CA8D4-1529-413A-B244-07958D5F9A48}.Debug|Any CPU.Build.0 = Debug|Any CPU {033CA8D4-1529-413A-B244-07958D5F9A48}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -806,14 +818,10 @@ Global {9B994669-E839-4C42-A0F1-DF9DD058C1DC}.Debug|Any CPU.Build.0 = Debug|Any CPU {9B994669-E839-4C42-A0F1-DF9DD058C1DC}.Release|Any CPU.ActiveCfg = Release|Any CPU {9B994669-E839-4C42-A0F1-DF9DD058C1DC}.Release|Any CPU.Build.0 = Release|Any CPU - {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Release|Any CPU.Build.0 = Release|Any CPU - {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Debug|Any CPU.Build.0 = Debug|Any CPU - {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Release|Any CPU.ActiveCfg = Release|Any CPU - {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Release|Any CPU.Build.0 = Release|Any CPU + {BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -913,6 +921,8 @@ Global {2A51E621-BCFA-4D52-96D0-E16AFF48CBE5} = {2097345F-4DD3-477D-BC54-A922F9B2B402} {A5FCDD8F-20FF-4657-804E-707EAD4FE31D} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63} {A5EF701C-439E-407F-8BB4-394166000C6D} = {2097345F-4DD3-477D-BC54-A922F9B2B402} + {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63} + {62B7060A-C35B-4D49-A0C2-3BF02880A200} = {2097345F-4DD3-477D-BC54-A922F9B2B402} {033CA8D4-1529-413A-B244-07958D5F9A48} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63} {36271347-2055-438E-9659-B71542A17A73} = {2097345F-4DD3-477D-BC54-A922F9B2B402} {7AD707F9-DC6D-430A-8834-D5DCD517BF6E} = {2097345F-4DD3-477D-BC54-A922F9B2B402} @@ -938,8 +948,8 @@ Global {BE40900A-2859-471D-8802-21DFD73DDAA7} = {2097345F-4DD3-477D-BC54-A922F9B2B402} {3A464E7A-42F3-44B0-B8D7-80521A7704A6} = {B75EE478-97F7-4E9F-9A5A-DB3D0988EDEA} {9B994669-E839-4C42-A0F1-DF9DD058C1DC} = {3A464E7A-42F3-44B0-B8D7-80521A7704A6} - {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63} - {62B7060A-C35B-4D49-A0C2-3BF02880A200} = {2097345F-4DD3-477D-BC54-A922F9B2B402} + {93B1028C-4FA7-4F63-8262-09CFD38930A5} = {B75EE478-97F7-4E9F-9A5A-DB3D0988EDEA} + {BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6} = {93B1028C-4FA7-4F63-8262-09CFD38930A5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B0816796-CDB3-47D7-8C3C-946434DE3B66} From 5fad1c61f3535a31786e0617d99a3e89e50f8682 Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Fri, 13 Sep 2024 14:29:45 +0200 Subject: [PATCH 7/9] remove example containerappjob project --- .../Example.ContainerAppJob.csproj | 28 ------- .../IHostApplicationBuilderExtensions.cs | 76 ------------------- .../OpenTelemetryDiagnostics.cs | 12 --- .../Azure/Example.ContainerAppJob/Program.cs | 14 ---- .../Properties/launchSettings.json | 12 --- .../Azure/Example.ContainerAppJob/README.md | 43 ----------- .../Azure/Example.ContainerAppJob/Worker.cs | 49 ------------ .../appsettings.Development.json | 8 -- .../Example.ContainerAppJob/appsettings.json | 8 -- opentelemetry-dotnet-contrib.sln | 30 +++----- 10 files changed, 10 insertions(+), 270 deletions(-) delete mode 100644 examples/Azure/Example.ContainerAppJob/Example.ContainerAppJob.csproj delete mode 100644 examples/Azure/Example.ContainerAppJob/IHostApplicationBuilderExtensions.cs delete mode 100644 examples/Azure/Example.ContainerAppJob/OpenTelemetryDiagnostics.cs delete mode 100644 examples/Azure/Example.ContainerAppJob/Program.cs delete mode 100644 examples/Azure/Example.ContainerAppJob/Properties/launchSettings.json delete mode 100644 examples/Azure/Example.ContainerAppJob/README.md delete mode 100644 examples/Azure/Example.ContainerAppJob/Worker.cs delete mode 100644 examples/Azure/Example.ContainerAppJob/appsettings.Development.json delete mode 100644 examples/Azure/Example.ContainerAppJob/appsettings.json diff --git a/examples/Azure/Example.ContainerAppJob/Example.ContainerAppJob.csproj b/examples/Azure/Example.ContainerAppJob/Example.ContainerAppJob.csproj deleted file mode 100644 index 38dd22914c..0000000000 --- a/examples/Azure/Example.ContainerAppJob/Example.ContainerAppJob.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net8.0 - enable - enable - dotnet-Example.ContainerAppJob-78bba48b-2c15-4a83-b45a-be47cf7bfe82 - - true - true - opentelemetry-containerapp-job - - - - - - - - - - - - - - - - - diff --git a/examples/Azure/Example.ContainerAppJob/IHostApplicationBuilderExtensions.cs b/examples/Azure/Example.ContainerAppJob/IHostApplicationBuilderExtensions.cs deleted file mode 100644 index 4c720fa413..0000000000 --- a/examples/Azure/Example.ContainerAppJob/IHostApplicationBuilderExtensions.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -using Azure.Monitor.OpenTelemetry.AspNetCore; -using OpenTelemetry; -using OpenTelemetry.Metrics; -using OpenTelemetry.Resources.Azure; -using OpenTelemetry.Trace; - -namespace Example.ContainerAppJob; - -public static class IHostApplicationBuilderExtensions -{ - public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder) - { - builder.AddAzureContainerAppsDetector(); - - builder.Logging.AddOpenTelemetry(logging => - { - logging.IncludeFormattedMessage = true; - logging.IncludeScopes = true; - }); - - builder.Services.AddOpenTelemetry() - .WithMetrics(metrics => - { - metrics.AddAspNetCoreInstrumentation() - .AddHttpClientInstrumentation() - .AddRuntimeInstrumentation(); - }) - .WithTracing(tracing => - { - tracing.AddSource("Example.ContainerAppJob") - .AddAspNetCoreInstrumentation() - - // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) - // .AddGrpcClientInstrumentation() - .AddHttpClientInstrumentation(); - }); - - builder.AddOpenTelemetryExporters(); - - return builder; - } - - private static IHostApplicationBuilder AddAzureContainerAppsDetector(this IHostApplicationBuilder builder) - { - // Using AzureContainerAppsResourceDetector here requires adding the InternalsVisibleTo attribute in the OpenTelemetry.Resources.Azure package. - builder.Services.AddSingleton(); - - builder.Services.AddOpenTelemetry() - .ConfigureResource(builder => builder - .AddDetector(sp => - sp.GetRequiredService())); - - return builder; - } - - private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostApplicationBuilder builder) - { - var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); - - if (useOtlpExporter) - { - builder.Services.AddOpenTelemetry().UseOtlpExporter(); - } - - if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"])) - { - builder.Services.AddOpenTelemetry() - .UseAzureMonitor(); - } - - return builder; - } -} diff --git a/examples/Azure/Example.ContainerAppJob/OpenTelemetryDiagnostics.cs b/examples/Azure/Example.ContainerAppJob/OpenTelemetryDiagnostics.cs deleted file mode 100644 index 6993068bde..0000000000 --- a/examples/Azure/Example.ContainerAppJob/OpenTelemetryDiagnostics.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -using System.Diagnostics; - -namespace Example.ContainerAppJob; - -public static class OpenTelemetryDiagnostics -{ - public const string SourceName = "Example.ContainerAppJob"; - public static readonly ActivitySource ActivitySource = new ActivitySource(SourceName); -} diff --git a/examples/Azure/Example.ContainerAppJob/Program.cs b/examples/Azure/Example.ContainerAppJob/Program.cs deleted file mode 100644 index 031b389bb0..0000000000 --- a/examples/Azure/Example.ContainerAppJob/Program.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -using Example.ContainerAppJob; - -var builder = Host.CreateApplicationBuilder(args); - -builder.ConfigureOpenTelemetry(); - -builder.Services.AddHttpClient(); -builder.Services.AddHostedService(); - -var host = builder.Build(); -host.Run(); diff --git a/examples/Azure/Example.ContainerAppJob/Properties/launchSettings.json b/examples/Azure/Example.ContainerAppJob/Properties/launchSettings.json deleted file mode 100644 index c34539800d..0000000000 --- a/examples/Azure/Example.ContainerAppJob/Properties/launchSettings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "profiles": { - "Example.ContainerAppJob": { - "commandName": "Project", - "dotnetRunMessages": true, - "environmentVariables": { - "DOTNET_ENVIRONMENT": "Development" - } - } - } -} diff --git a/examples/Azure/Example.ContainerAppJob/README.md b/examples/Azure/Example.ContainerAppJob/README.md deleted file mode 100644 index ecab32c2ef..0000000000 --- a/examples/Azure/Example.ContainerAppJob/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Example.ContainerAppJob - -This example demonstrates the working of the `AzureContainerAppsResourceDetector` -in the context of an Azure Container Apps job. - -It is intended to run the container image in an Azure Container Apps job. -It expects the `AZURE_APPINSIGHTS_CONNECTION_STRING` environment variable -to be set with the connection string of an Azure Application Insights resource. - -## Building it - -To build this app, run the following command from the project directory: - -```shell -dotnet publish -c Release -r linux-x64 -p:PublishProfile=DefaultContainer -``` - -Upload it to your container registry: - -```shell -az acr login --name -docker tag opentelemetry-containerapp-job .azurecr.io/opentelemetry-containerapp-job -docker push .azurecr.io/opentelemetry-containerapp-job -``` - -## Prerequisites - -- Resources in Azure: - - - Azure Container Apps job - - Azure Container Registry - - Azure Application Insights - -- Building the code requires - - adding the `InternalsVisibleTo` attribute in `AssemblyInfo.cs` - in the the `OpenTelemetry.Resources.Azure` project because the - `AzureContainerAppsResourceDetector` class is marked `internal`. - - ```csharp - [assembly: InternalsVisibleTo("Example.ContainerAppJob")] - ``` - - - running docker or podman on the machine diff --git a/examples/Azure/Example.ContainerAppJob/Worker.cs b/examples/Azure/Example.ContainerAppJob/Worker.cs deleted file mode 100644 index 73286f42ac..0000000000 --- a/examples/Azure/Example.ContainerAppJob/Worker.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -using System.Collections; -using OpenTelemetry.Trace; - -namespace Example.ContainerAppJob; - -public class Worker(IHostApplicationLifetime hostApplicationLifetime, IHttpClientFactory httpClientFactory) : BackgroundService -{ - protected override async Task ExecuteAsync(CancellationToken stoppingToken) - { - using (var exampleActivity = OpenTelemetryDiagnostics.ActivitySource.StartActivity("Example activity")) - { - try - { - await Task.Delay(1000, stoppingToken); - exampleActivity?.AddEvent(new System.Diagnostics.ActivityEvent("Example event")); - - var client = httpClientFactory.CreateClient(); - var testUri = new Uri("https://www.microsoft.com/"); - var result = await client.GetAsync(testUri, stoppingToken); - - // Loop over environment variables and add them as tags - foreach (DictionaryEntry envVar in (IDictionary)Environment.GetEnvironmentVariables()) - { - if (envVar.Key is null) - { - continue; - } - - exampleActivity?.SetTag(envVar.Key.ToString()!, envVar.Value?.ToString()); - } - - await Task.Delay(1000, stoppingToken); - - // Simulate an exception. - throw new Exception("Example exception"); - } - catch (Exception ex) - { - exampleActivity?.RecordException(ex); - } - } - - // When completed, the entire app host will stop. - hostApplicationLifetime.StopApplication(); - } -} diff --git a/examples/Azure/Example.ContainerAppJob/appsettings.Development.json b/examples/Azure/Example.ContainerAppJob/appsettings.Development.json deleted file mode 100644 index b2dcdb6742..0000000000 --- a/examples/Azure/Example.ContainerAppJob/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/examples/Azure/Example.ContainerAppJob/appsettings.json b/examples/Azure/Example.ContainerAppJob/appsettings.json deleted file mode 100644 index b2dcdb6742..0000000000 --- a/examples/Azure/Example.ContainerAppJob/appsettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/opentelemetry-dotnet-contrib.sln b/opentelemetry-dotnet-contrib.sln index 8cad305cc8..635826b25b 100644 --- a/opentelemetry-dotnet-contrib.sln +++ b/opentelemetry-dotnet-contrib.sln @@ -392,10 +392,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "kafka", "kafka", "{3A464E7A EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.ConfluentKafka", "examples\kafka\Examples.ConfluentKafka.csproj", "{9B994669-E839-4C42-A0F1-DF9DD058C1DC}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Azure", "Azure", "{93B1028C-4FA7-4F63-8262-09CFD38930A5}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.ContainerAppJob", "examples\Azure\Example.ContainerAppJob\Example.ContainerAppJob.csproj", "{BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -726,14 +722,6 @@ Global {A5EF701C-439E-407F-8BB4-394166000C6D}.Debug|Any CPU.Build.0 = Debug|Any CPU {A5EF701C-439E-407F-8BB4-394166000C6D}.Release|Any CPU.ActiveCfg = Release|Any CPU {A5EF701C-439E-407F-8BB4-394166000C6D}.Release|Any CPU.Build.0 = Release|Any CPU - {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Release|Any CPU.Build.0 = Release|Any CPU - {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Debug|Any CPU.Build.0 = Debug|Any CPU - {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Release|Any CPU.ActiveCfg = Release|Any CPU - {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Release|Any CPU.Build.0 = Release|Any CPU {033CA8D4-1529-413A-B244-07958D5F9A48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {033CA8D4-1529-413A-B244-07958D5F9A48}.Debug|Any CPU.Build.0 = Debug|Any CPU {033CA8D4-1529-413A-B244-07958D5F9A48}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -818,10 +806,14 @@ Global {9B994669-E839-4C42-A0F1-DF9DD058C1DC}.Debug|Any CPU.Build.0 = Debug|Any CPU {9B994669-E839-4C42-A0F1-DF9DD058C1DC}.Release|Any CPU.ActiveCfg = Release|Any CPU {9B994669-E839-4C42-A0F1-DF9DD058C1DC}.Release|Any CPU.Build.0 = Release|Any CPU - {BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6}.Release|Any CPU.Build.0 = Release|Any CPU + {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1}.Release|Any CPU.Build.0 = Release|Any CPU + {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62B7060A-C35B-4D49-A0C2-3BF02880A200}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -921,8 +913,6 @@ Global {2A51E621-BCFA-4D52-96D0-E16AFF48CBE5} = {2097345F-4DD3-477D-BC54-A922F9B2B402} {A5FCDD8F-20FF-4657-804E-707EAD4FE31D} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63} {A5EF701C-439E-407F-8BB4-394166000C6D} = {2097345F-4DD3-477D-BC54-A922F9B2B402} - {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63} - {62B7060A-C35B-4D49-A0C2-3BF02880A200} = {2097345F-4DD3-477D-BC54-A922F9B2B402} {033CA8D4-1529-413A-B244-07958D5F9A48} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63} {36271347-2055-438E-9659-B71542A17A73} = {2097345F-4DD3-477D-BC54-A922F9B2B402} {7AD707F9-DC6D-430A-8834-D5DCD517BF6E} = {2097345F-4DD3-477D-BC54-A922F9B2B402} @@ -948,8 +938,8 @@ Global {BE40900A-2859-471D-8802-21DFD73DDAA7} = {2097345F-4DD3-477D-BC54-A922F9B2B402} {3A464E7A-42F3-44B0-B8D7-80521A7704A6} = {B75EE478-97F7-4E9F-9A5A-DB3D0988EDEA} {9B994669-E839-4C42-A0F1-DF9DD058C1DC} = {3A464E7A-42F3-44B0-B8D7-80521A7704A6} - {93B1028C-4FA7-4F63-8262-09CFD38930A5} = {B75EE478-97F7-4E9F-9A5A-DB3D0988EDEA} - {BAEA2D8A-78CA-47EF-ABE7-25EB54C564B6} = {93B1028C-4FA7-4F63-8262-09CFD38930A5} + {F8E9EC7E-85A1-4C97-9C05-7EA82C1513A1} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63} + {62B7060A-C35B-4D49-A0C2-3BF02880A200} = {2097345F-4DD3-477D-BC54-A922F9B2B402} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B0816796-CDB3-47D7-8C3C-946434DE3B66} From 8a5cc323502c52e0961f014695e79e01284c1556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 16 Sep 2024 07:35:28 +0200 Subject: [PATCH 8/9] md-lint fix --- src/OpenTelemetry.Resources.Azure/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Resources.Azure/CHANGELOG.md b/src/OpenTelemetry.Resources.Azure/CHANGELOG.md index d507e67164..9a62044dde 100644 --- a/src/OpenTelemetry.Resources.Azure/CHANGELOG.md +++ b/src/OpenTelemetry.Resources.Azure/CHANGELOG.md @@ -4,7 +4,7 @@ * Added support for [Azure Container Apps jobs](https://learn.microsoft.com/en-us/azure/container-apps/jobs?tabs=azure-cli). ([#2064](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2064)) - + * Added direct reference to `System.Text.Encodings.Web` with minimum version of `4.7.2` in response to [CVE-2021-26701](https://github.com/dotnet/runtime/issues/49377). ([#2056](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2056)) From f6ecf3a3ea5c17a13cf4962c53ba3c715cb1ae64 Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Fri, 20 Sep 2024 23:23:00 +0200 Subject: [PATCH 9/9] Clear the container apps app / job name env vars between tests --- .../AzureResourceDetectorTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs b/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs index 4102a0646b..cbe8ce70c1 100644 --- a/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs +++ b/test/OpenTelemetry.Resources.Azure.Tests/AzureResourceDetectorTests.cs @@ -162,5 +162,8 @@ public void Dispose() { Environment.SetEnvironmentVariable(kvp.Value, null); } + + Environment.SetEnvironmentVariable(ResourceAttributeConstants.AzureContainerAppsNameEnvVar, null); + Environment.SetEnvironmentVariable(ResourceAttributeConstants.AzureContainerAppJobNameEnvVar, null); } }