From bc7fd36366e630c0aaef436b3fb12ecbdec7bace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 29 Mar 2023 18:10:22 +0200 Subject: [PATCH 01/16] Issue Templates - lowercase labels (#1118) --- ...instrumentation_AspNet.md => comp_instrumentation_aspnet.md} | 2 +- ...le.md => comp_instrumentation_aspnet.telemetryhttpmodule.md} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename .github/ISSUE_TEMPLATE/{comp_instrumentation_AspNet.md => comp_instrumentation_aspnet.md} (96%) rename .github/ISSUE_TEMPLATE/{comp_instrumentation_AspNet.TelemetryHttpModule.md => comp_instrumentation_aspnet.telemetryhttpmodule.md} (95%) diff --git a/.github/ISSUE_TEMPLATE/comp_instrumentation_AspNet.md b/.github/ISSUE_TEMPLATE/comp_instrumentation_aspnet.md similarity index 96% rename from .github/ISSUE_TEMPLATE/comp_instrumentation_AspNet.md rename to .github/ISSUE_TEMPLATE/comp_instrumentation_aspnet.md index 80efb79cd1..9942824b40 100644 --- a/.github/ISSUE_TEMPLATE/comp_instrumentation_AspNet.md +++ b/.github/ISSUE_TEMPLATE/comp_instrumentation_aspnet.md @@ -1,7 +1,7 @@ --- name: OpenTelemetry.Instrumentation.AspNet about: Issue with OpenTelemetry.Instrumentation.AspNet -labels: comp:instrumentation.AspNet +labels: comp:instrumentation.aspnet --- # Issue with OpenTelemetry.Instrumentation.AspNet diff --git a/.github/ISSUE_TEMPLATE/comp_instrumentation_AspNet.TelemetryHttpModule.md b/.github/ISSUE_TEMPLATE/comp_instrumentation_aspnet.telemetryhttpmodule.md similarity index 95% rename from .github/ISSUE_TEMPLATE/comp_instrumentation_AspNet.TelemetryHttpModule.md rename to .github/ISSUE_TEMPLATE/comp_instrumentation_aspnet.telemetryhttpmodule.md index 150414bf0a..d9cefb6957 100644 --- a/.github/ISSUE_TEMPLATE/comp_instrumentation_AspNet.TelemetryHttpModule.md +++ b/.github/ISSUE_TEMPLATE/comp_instrumentation_aspnet.telemetryhttpmodule.md @@ -1,7 +1,7 @@ --- name: OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule about: Issue with OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule -labels: comp:instrumentation.AspNet.TelemetryHttpModule +labels: comp:instrumentation.aspnet.telemetryhttpmodule --- # Issue with OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule From a1e612550caf94074d83e759f137b869d016fc0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 29 Mar 2023 22:57:00 +0200 Subject: [PATCH 02/16] Bump test dependencies (#1116) --- build/Common.nonprod.props | 9 ++++----- build/Common.props | 2 +- build/process-codecoverage.ps1 | 2 +- ...penTelemetry.Contrib.Instrumentation.AWS.Tests.csproj | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props index a8ec7107cb..528ff99e26 100644 --- a/build/Common.nonprod.props +++ b/build/Common.nonprod.props @@ -24,14 +24,13 @@ [3.2.0,4.0.0) [2.3.1,3.0) [5.0.0,7.0) - [17.3.2,18.0) - [4.18.3,5.0) - [4.17.2,5.0) + [17.5.0,18.0) + [4.18.4,5.0) $(OpenTelemetryCoreLatestVersion) $(OpenTelemetryCoreLatestPrereleaseVersion) - [2.4.3,3.0) + [2.4.5,3.0) [2.4.2,3.0) - [1.5.20,2.0) + [1.5.21,2.0) diff --git a/build/Common.props b/build/Common.props index 49b7ac1f3f..fd517f699f 100644 --- a/build/Common.props +++ b/build/Common.props @@ -27,7 +27,7 @@ Refer to https://docs.microsoft.com/en-us/nuget/concepts/package-versioning for semver syntax. --> [4.2.0,5.0) - [17.3.2] + [17.5.0] [2.1.0,5.0) [3.1.0,) [1.0.3,2.0) diff --git a/build/process-codecoverage.ps1 b/build/process-codecoverage.ps1 index f2df16b80c..ff0bdf6d8f 100644 --- a/build/process-codecoverage.ps1 +++ b/build/process-codecoverage.ps1 @@ -6,7 +6,7 @@ $files = Get-ChildItem "TestResults" -Filter "*.coverage" -Recurse Write-Host $env:USERPROFILE foreach ($file in $files) { - $command = $env:USERPROFILE+ '\.nuget\packages\microsoft.codecoverage\' + $microsoftCodeCoveragePkgVer + '\build\netstandard1.0\CodeCoverage\CodeCoverage.exe analyze /output:' + $file.DirectoryName + '\' + $file.Name + '.xml '+ $file.FullName + $command = $env:USERPROFILE+ '\.nuget\packages\microsoft.codecoverage\' + $microsoftCodeCoveragePkgVer + '\build\netstandard2.0\CodeCoverage\CodeCoverage.exe analyze /output:' + $file.DirectoryName + '\' + $file.Name + '.xml '+ $file.FullName Write-Host $command Invoke-Expression $command } diff --git a/test/OpenTelemetry.Contrib.Instrumentation.AWS.Tests/OpenTelemetry.Contrib.Instrumentation.AWS.Tests.csproj b/test/OpenTelemetry.Contrib.Instrumentation.AWS.Tests/OpenTelemetry.Contrib.Instrumentation.AWS.Tests.csproj index 8df48f35a5..3a88d8a22a 100644 --- a/test/OpenTelemetry.Contrib.Instrumentation.AWS.Tests/OpenTelemetry.Contrib.Instrumentation.AWS.Tests.csproj +++ b/test/OpenTelemetry.Contrib.Instrumentation.AWS.Tests/OpenTelemetry.Contrib.Instrumentation.AWS.Tests.csproj @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers From 8e0b8bdc984aaa886e0e0c6f525617a4a00e77d0 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai Date: Wed, 29 Mar 2023 14:57:39 -0700 Subject: [PATCH 03/16] [Exporter.Geneva] Update CHANGELOG for 1.5.0-alpha.2 version (#1121) --- src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md index b0393e7ea0..e66996a40a 100644 --- a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md @@ -2,12 +2,16 @@ ## Unreleased +## 1.5.0-alpha.2 + +Released 2023-Mar-29 + * Fix a bug where metrics without exemplars were not getting exported. ([#1099](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1099)) * Relaxed table name mapping validation rules to restore the previous behavior - from version 1.3.0. - ([#1109](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/1109)) + from version 1.3.0. ([Issue + #1105](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/1105)) * Add support for exporting metrics to more than a single account/namespace combination using a single GenevaMetricExporter instance. Users can now export @@ -16,8 +20,8 @@ `_microsoft_metrics_account` and providing a `string` value for it as the account name. * A metric namespace of their choice by adding the dimension - `_microsoft_metrics_namespace` and providing a `string` value for it as the - namespace name. + `_microsoft_metrics_namespace` and providing a `string` value for it as the + namespace name. ([#1111](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1111)) * Fix a bug in TldTraceExporter for incorrect serialization of special tags. From bf9089aef56308f14e623fe5dcbde3089ce518c3 Mon Sep 17 00:00:00 2001 From: Soheil Alizadeh Date: Thu, 30 Mar 2023 09:01:00 +0200 Subject: [PATCH 04/16] [Instrumentation.Cassandra] Release 1.0.0-beta.1 (#1119) --- src/OpenTelemetry.Instrumentation.Cassandra/CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.Cassandra/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Cassandra/CHANGELOG.md index 63bfc986bd..d3add35586 100644 --- a/src/OpenTelemetry.Instrumentation.Cassandra/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Cassandra/CHANGELOG.md @@ -2,4 +2,8 @@ ## Unreleased -Initial release. +## 1.0.0-beta.1 + +Released 2023-Mar-30 + +- Initial release From 57adc16022cf23ee34e52586e4ae3ec0836bf6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 30 Mar 2023 20:13:10 +0200 Subject: [PATCH 05/16] [ResourceDetectors.Container] Rename Container package (#1123) --- ...md => comp_resourcedetectors_container.md} | 8 +- .github/component_owners.yml | 8 +- ...> package-ResourceDetectors.Container.yml} | 6 +- opentelemetry-dotnet-contrib.sln | 13 +-- .../.publicApi/net462/PublicAPI.Unshipped.txt | 3 - .../netstandard2.0/PublicAPI.Unshipped.txt | 3 - .../.publicApi/net462/PublicAPI.Shipped.txt | 0 .../.publicApi/net462/PublicAPI.Unshipped.txt | 3 + .../netstandard2.0/PublicAPI.Shipped.txt | 0 .../netstandard2.0/PublicAPI.Unshipped.txt | 3 + .../AssemblyInfo.cs | 4 +- .../CHANGELOG.md | 13 +++ .../ContainerExtensionsEventSource.cs} | 10 +-- .../ContainerResourceDetector.cs} | 28 +++---- .../ContainerSemanticConventions.cs} | 8 +- ...emetry.ResourceDetectors.Container.csproj} | 4 +- .../README.md | 18 ++-- .../Utils/EncodingUtils.cs | 6 +- .../ContainerResourceDetectorTests.cs} | 83 +++++++++---------- ....ResourceDetectors.Container.Tests.csproj} | 8 +- .../TempFile.cs | 20 ++--- 21 files changed, 130 insertions(+), 119 deletions(-) rename .github/ISSUE_TEMPLATE/{comp_extensions_docker.md => comp_resourcedetectors_container.md} (82%) rename .github/workflows/{package-Extensions.Docker.yml => package-ResourceDetectors.Container.yml} (91%) delete mode 100644 src/OpenTelemetry.Extensions.Docker/.publicApi/net462/PublicAPI.Unshipped.txt delete mode 100644 src/OpenTelemetry.Extensions.Docker/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt rename src/{OpenTelemetry.Extensions.Docker => OpenTelemetry.ResourceDetectors.Container}/.publicApi/net462/PublicAPI.Shipped.txt (100%) create mode 100644 src/OpenTelemetry.ResourceDetectors.Container/.publicApi/net462/PublicAPI.Unshipped.txt rename src/{OpenTelemetry.Extensions.Docker => OpenTelemetry.ResourceDetectors.Container}/.publicApi/netstandard2.0/PublicAPI.Shipped.txt (100%) create mode 100644 src/OpenTelemetry.ResourceDetectors.Container/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt rename src/{OpenTelemetry.Extensions.Docker => OpenTelemetry.ResourceDetectors.Container}/AssemblyInfo.cs (60%) rename src/{OpenTelemetry.Extensions.Docker => OpenTelemetry.ResourceDetectors.Container}/CHANGELOG.md (51%) rename src/{OpenTelemetry.Extensions.Docker/DockerExtensionsEventSource.cs => OpenTelemetry.ResourceDetectors.Container/ContainerExtensionsEventSource.cs} (84%) rename src/{OpenTelemetry.Extensions.Docker/Resources/DockerResourceDetector.cs => OpenTelemetry.ResourceDetectors.Container/ContainerResourceDetector.cs} (84%) rename src/{OpenTelemetry.Extensions.Docker/Resources/DockerSemanticConventions.cs => OpenTelemetry.ResourceDetectors.Container/ContainerSemanticConventions.cs} (70%) rename src/{OpenTelemetry.Extensions.Docker/OpenTelemetry.Extensions.Docker.csproj => OpenTelemetry.ResourceDetectors.Container/OpenTelemetry.ResourceDetectors.Container.csproj} (80%) rename src/{OpenTelemetry.Extensions.Docker => OpenTelemetry.ResourceDetectors.Container}/README.md (54%) rename src/{OpenTelemetry.Extensions.Docker => OpenTelemetry.ResourceDetectors.Container}/Utils/EncodingUtils.cs (89%) rename test/{OpenTelemetry.Extensions.Docker.Tests/Resources/DockerResourceDetectorTests.cs => OpenTelemetry.ResourceDetectors.Container.Tests/ContainerResourceDetectorTests.cs} (70%) rename test/{OpenTelemetry.Extensions.Docker.Tests/OpenTelemetry.Extensions.Docker.Tests.csproj => OpenTelemetry.ResourceDetectors.Container.Tests/OpenTelemetry.ResourceDetectors.Container.Tests.csproj} (76%) rename test/{OpenTelemetry.Extensions.Docker.Tests/Resources => OpenTelemetry.ResourceDetectors.Container.Tests}/TempFile.cs (71%) diff --git a/.github/ISSUE_TEMPLATE/comp_extensions_docker.md b/.github/ISSUE_TEMPLATE/comp_resourcedetectors_container.md similarity index 82% rename from .github/ISSUE_TEMPLATE/comp_extensions_docker.md rename to .github/ISSUE_TEMPLATE/comp_resourcedetectors_container.md index bb88ba26f2..2a2d04bd8e 100644 --- a/.github/ISSUE_TEMPLATE/comp_extensions_docker.md +++ b/.github/ISSUE_TEMPLATE/comp_resourcedetectors_container.md @@ -1,10 +1,10 @@ --- -name: OpenTelemetry.Extensions.Docker -about: Issue with OpenTelemetry.Extensions.Docker -labels: comp:extensions.docker +name: OpenTelemetry.ResourceDetectors.Container +about: Issue with OpenTelemetry.ResourceDetectors.Container +labels: comp:resourcedetectors.container --- -# Issue with OpenTelemetry.Extensions.Docker +# Issue with OpenTelemetry.ResourceDetectors.Container List of [all OpenTelemetry NuGet packages](https://www.nuget.org/profiles/OpenTelemetry) and version that you are diff --git a/.github/component_owners.yml b/.github/component_owners.yml index f7b647ef1a..acf4632141 100644 --- a/.github/component_owners.yml +++ b/.github/component_owners.yml @@ -27,8 +27,6 @@ components: src/OpenTelemetry.Extensions.AzureMonitor/: - rajkumar-rangaraj - vishweshbankwar - src/OpenTelemetry.Extensions.Docker/: - - iskiselev src/OpenTelemetry.Extensions.Enrichment/: - xakep139 src/OpenTelemetry.PersistentStorage.Abstractions/: @@ -65,6 +63,8 @@ components: src/OpenTelemetry.ResourceDetectors.Azure/: - rajkumar-rangaraj - vishweshbankwar + src/OpenTelemetry.ResourceDetectors.Container/: + - iskiselev src/OpenTelemetry.Sampler.AWS/: - srprash test/OpenTelemetry.Contrib.Extensions.AWSXRay.Tests/: @@ -108,8 +108,6 @@ components: test/OpenTelemetry.Extensions.AzureMonitor.Tests/: - rajkumar-rangaraj - vishweshbankwar - test/OpenTelemetry.Extensions.Docker.Tests/: - - iskiselev test/OpenTelemetry.Extensions.Enrichment.Tests/: - xakep139 test/OpenTelemetry.PersistentStorage.FileSystem.Tests/: @@ -142,5 +140,7 @@ components: test/OpenTelemetry.ResourceDetectors.Azure.Tests/: - rajkumar-rangaraj - vishweshbankwar + test/OpenTelemetry.ResourceDetectors.Container.Tests/: + - iskiselev test/OpenTelemetry.Sampler.AWS.Tests/: - srprash diff --git a/.github/workflows/package-Extensions.Docker.yml b/.github/workflows/package-ResourceDetectors.Container.yml similarity index 91% rename from .github/workflows/package-Extensions.Docker.yml rename to .github/workflows/package-ResourceDetectors.Container.yml index cdb3390e4c..ee307b95f5 100644 --- a/.github/workflows/package-Extensions.Docker.yml +++ b/.github/workflows/package-ResourceDetectors.Container.yml @@ -1,4 +1,4 @@ -name: Pack OpenTelemetry.Extensions.Docker +name: Pack OpenTelemetry.ResourceDetectors.Container on: workflow_dispatch: @@ -9,7 +9,7 @@ on: default: 'warning' push: tags: - - 'Extensions.Docker-*' # trigger when we create a tag with prefix "Extensions.Docker-" + - 'ResourceDetectors.Container-*' # trigger when we create a tag with prefix "ResourceDetectors.Container-" jobs: build-test-pack: @@ -17,7 +17,7 @@ jobs: permissions: contents: write env: - PROJECT: OpenTelemetry.Extensions.Docker + PROJECT: OpenTelemetry.ResourceDetectors.Container strategy: matrix: diff --git a/opentelemetry-dotnet-contrib.sln b/opentelemetry-dotnet-contrib.sln index a1c0b69b94..d03f11d7c4 100644 --- a/opentelemetry-dotnet-contrib.sln +++ b/opentelemetry-dotnet-contrib.sln @@ -177,9 +177,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Tests", "test\OpenTelemetry.Extensions.Tests\OpenTelemetry.Extensions.Tests.csproj", "{2117F4E3-6612-4E4D-A757-27271EEB7783}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Docker", "src\OpenTelemetry.Extensions.Docker\OpenTelemetry.Extensions.Docker.csproj", "{498A6808-C0DF-441F-A764-51A3BC4B8FC5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.Container", "src\OpenTelemetry.ResourceDetectors.Container\OpenTelemetry.ResourceDetectors.Container.csproj", "{498A6808-C0DF-441F-A764-51A3BC4B8FC5}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Docker.Tests", "test\OpenTelemetry.Extensions.Docker.Tests\OpenTelemetry.Extensions.Docker.Tests.csproj", "{FB41E19E-2682-4D07-BA59-FD5205AFA71E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.Container.Tests", "test\OpenTelemetry.ResourceDetectors.Container.Tests\OpenTelemetry.ResourceDetectors.Container.Tests.csproj", "{FB41E19E-2682-4D07-BA59-FD5205AFA71E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Geneva", "src\OpenTelemetry.Exporter.Geneva\OpenTelemetry.Exporter.Geneva.csproj", "{1105C814-31DA-4214-BEA8-6DB5FC12C808}" EndProject @@ -235,9 +235,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "process-instrumentation", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.EventCounters", "examples\event-counters\Examples.EventCounters\Examples.EventCounters.csproj", "{BA58CC8B-F5CA-4DC7-A3A8-D01B2E10731E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Instrumentation.Cassandra", "src\OpenTelemetry.Instrumentation.Cassandra\OpenTelemetry.Instrumentation.Cassandra.csproj", "{3313F7DF-E3A5-4A7F-965D-86807A017131}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.Cassandra", "src\OpenTelemetry.Instrumentation.Cassandra\OpenTelemetry.Instrumentation.Cassandra.csproj", "{3313F7DF-E3A5-4A7F-965D-86807A017131}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.Cassandra.Tests", "test\OpenTelemetry.Instrumentation.Cassandra.Tests\OpenTelemetry.Instrumentation.Cassandra.Tests.csproj", "{FB48DC44-8C56-4329-9988-AEDF931E81E8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Instrumentation.Cassandra.Tests", "test\OpenTelemetry.Instrumentation.Cassandra.Tests\OpenTelemetry.Instrumentation.Cassandra.Tests.csproj", "{FB48DC44-8C56-4329-9988-AEDF931E81E8}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.Azure", "src\OpenTelemetry.ResourceDetectors.Azure\OpenTelemetry.ResourceDetectors.Azure.csproj", "{B07DC3CB-F724-40A5-889A-DA6601F462F3}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.Azure.Tests", "test\OpenTelemetry.ResourceDetectors.Azure.Tests\OpenTelemetry.ResourceDetectors.Azure.Tests.csproj", "{DFC6A4A9-5262-4507-B747-CC6B814205E6}" @@ -256,9 +257,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.PersistentSto EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.PersistentStorage.FileSystem.Tests", "test\OpenTelemetry.PersistentStorage.FileSystem.Tests\OpenTelemetry.PersistentStorage.FileSystem.Tests.csproj", "{C7215B69-0D77-4D52-AFBB-A6662249B3AC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Sampler.AWS", "src\OpenTelemetry.Sampler.AWS\OpenTelemetry.Sampler.AWS.csproj", "{54002B08-F6AE-4B2B-AB0C-86E5A05926A3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Sampler.AWS", "src\OpenTelemetry.Sampler.AWS\OpenTelemetry.Sampler.AWS.csproj", "{54002B08-F6AE-4B2B-AB0C-86E5A05926A3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Sampler.AWS.Tests", "test\OpenTelemetry.Sampler.AWS.Tests\OpenTelemetry.Sampler.AWS.Tests.csproj", "{48C29501-3FA2-46A7-B5BA-D282EA8F1274}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Sampler.AWS.Tests", "test\OpenTelemetry.Sampler.AWS.Tests\OpenTelemetry.Sampler.AWS.Tests.csproj", "{48C29501-3FA2-46A7-B5BA-D282EA8F1274}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.OneCollector.Benchmarks", "test\OpenTelemetry.Exporter.OneCollector.Benchmarks\OpenTelemetry.Exporter.OneCollector.Benchmarks.csproj", "{C42868C8-968A-473F-AC39-AC97C5D47E84}" EndProject diff --git a/src/OpenTelemetry.Extensions.Docker/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Extensions.Docker/.publicApi/net462/PublicAPI.Unshipped.txt deleted file mode 100644 index e97a3917d4..0000000000 --- a/src/OpenTelemetry.Extensions.Docker/.publicApi/net462/PublicAPI.Unshipped.txt +++ /dev/null @@ -1,3 +0,0 @@ -OpenTelemetry.Extensions.Docker.Resources.DockerResourceDetector -OpenTelemetry.Extensions.Docker.Resources.DockerResourceDetector.Detect() -> OpenTelemetry.Resources.Resource! -OpenTelemetry.Extensions.Docker.Resources.DockerResourceDetector.DockerResourceDetector() -> void diff --git a/src/OpenTelemetry.Extensions.Docker/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Extensions.Docker/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt deleted file mode 100644 index e97a3917d4..0000000000 --- a/src/OpenTelemetry.Extensions.Docker/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ /dev/null @@ -1,3 +0,0 @@ -OpenTelemetry.Extensions.Docker.Resources.DockerResourceDetector -OpenTelemetry.Extensions.Docker.Resources.DockerResourceDetector.Detect() -> OpenTelemetry.Resources.Resource! -OpenTelemetry.Extensions.Docker.Resources.DockerResourceDetector.DockerResourceDetector() -> void diff --git a/src/OpenTelemetry.Extensions.Docker/.publicApi/net462/PublicAPI.Shipped.txt b/src/OpenTelemetry.ResourceDetectors.Container/.publicApi/net462/PublicAPI.Shipped.txt similarity index 100% rename from src/OpenTelemetry.Extensions.Docker/.publicApi/net462/PublicAPI.Shipped.txt rename to src/OpenTelemetry.ResourceDetectors.Container/.publicApi/net462/PublicAPI.Shipped.txt diff --git a/src/OpenTelemetry.ResourceDetectors.Container/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.ResourceDetectors.Container/.publicApi/net462/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..9da4e0d8d8 --- /dev/null +++ b/src/OpenTelemetry.ResourceDetectors.Container/.publicApi/net462/PublicAPI.Unshipped.txt @@ -0,0 +1,3 @@ +OpenTelemetry.ResourceDetectors.Container.ContainerResourceDetector +OpenTelemetry.ResourceDetectors.Container.ContainerResourceDetector.ContainerResourceDetector() -> void +OpenTelemetry.ResourceDetectors.Container.ContainerResourceDetector.Detect() -> OpenTelemetry.Resources.Resource! diff --git a/src/OpenTelemetry.Extensions.Docker/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.ResourceDetectors.Container/.publicApi/netstandard2.0/PublicAPI.Shipped.txt similarity index 100% rename from src/OpenTelemetry.Extensions.Docker/.publicApi/netstandard2.0/PublicAPI.Shipped.txt rename to src/OpenTelemetry.ResourceDetectors.Container/.publicApi/netstandard2.0/PublicAPI.Shipped.txt diff --git a/src/OpenTelemetry.ResourceDetectors.Container/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.ResourceDetectors.Container/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..9da4e0d8d8 --- /dev/null +++ b/src/OpenTelemetry.ResourceDetectors.Container/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -0,0 +1,3 @@ +OpenTelemetry.ResourceDetectors.Container.ContainerResourceDetector +OpenTelemetry.ResourceDetectors.Container.ContainerResourceDetector.ContainerResourceDetector() -> void +OpenTelemetry.ResourceDetectors.Container.ContainerResourceDetector.Detect() -> OpenTelemetry.Resources.Resource! diff --git a/src/OpenTelemetry.Extensions.Docker/AssemblyInfo.cs b/src/OpenTelemetry.ResourceDetectors.Container/AssemblyInfo.cs similarity index 60% rename from src/OpenTelemetry.Extensions.Docker/AssemblyInfo.cs rename to src/OpenTelemetry.ResourceDetectors.Container/AssemblyInfo.cs index a6a0089eba..874cf880ac 100644 --- a/src/OpenTelemetry.Extensions.Docker/AssemblyInfo.cs +++ b/src/OpenTelemetry.ResourceDetectors.Container/AssemblyInfo.cs @@ -17,7 +17,7 @@ using System.Runtime.CompilerServices; #if SIGNED -[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.Docker.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] +[assembly: InternalsVisibleTo("OpenTelemetry.ResourceDetectors.Container.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010051c1562a090fb0c9f391012a32198b5e5d9a60e9b80fa2d7b434c9e5ccb7259bd606e66f9660676afc6692b8cdc6793d190904551d2103b7b22fa636dcbb8208839785ba402ea08fc00c8f1500ccef28bbf599aa64ffb1e1d5dc1bf3420a3777badfe697856e9d52070a50c3ea5821c80bef17ca3acffa28f89dd413f096f898")] #else -[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.Docker.Tests")] +[assembly: InternalsVisibleTo("OpenTelemetry.ResourceDetectors.Container.Tests")] #endif diff --git a/src/OpenTelemetry.Extensions.Docker/CHANGELOG.md b/src/OpenTelemetry.ResourceDetectors.Container/CHANGELOG.md similarity index 51% rename from src/OpenTelemetry.Extensions.Docker/CHANGELOG.md rename to src/OpenTelemetry.ResourceDetectors.Container/CHANGELOG.md index 65b8ae1498..f3e5bf6ec8 100644 --- a/src/OpenTelemetry.Extensions.Docker/CHANGELOG.md +++ b/src/OpenTelemetry.ResourceDetectors.Container/CHANGELOG.md @@ -2,6 +2,19 @@ ## Unreleased +* Going forward the NuGet package will be + [`OpenTelemetry.ResourceDetectors.Container`](https://www.nuget.org/packages/OpenTelemetry.ResourceDetectors.Container). + Older versions will remain at + [`OpenTelemetry.Extensions.Docker`](https://www.nuget.org/packages/OpenTelemetry.Extensions.Docker) + [(#881)](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/881) + + Migration: + + * In code update namespaces (eg `using + OpenTelemetry.Extensions.Docker.Resources` -> `using + OpenTelemetry.ResourceDetectors.Container`) + and the class name (`DockerResourceDetector` to `ContainerResourceDetector`). + ([#1123](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1123)) * Updates to 1.4.0 of OpenTelemetry SDK. ([#1038](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1038)) diff --git a/src/OpenTelemetry.Extensions.Docker/DockerExtensionsEventSource.cs b/src/OpenTelemetry.ResourceDetectors.Container/ContainerExtensionsEventSource.cs similarity index 84% rename from src/OpenTelemetry.Extensions.Docker/DockerExtensionsEventSource.cs rename to src/OpenTelemetry.ResourceDetectors.Container/ContainerExtensionsEventSource.cs index 0478b5bdb6..6e2eda010b 100644 --- a/src/OpenTelemetry.Extensions.Docker/DockerExtensionsEventSource.cs +++ b/src/OpenTelemetry.ResourceDetectors.Container/ContainerExtensionsEventSource.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,12 @@ using System.Globalization; using System.Threading; -namespace OpenTelemetry.Extensions.Docker; +namespace OpenTelemetry.ResourceDetectors.Container; -[EventSource(Name = "OpenTelemetry-Extensions-Docker")] -internal class DockerExtensionsEventSource : EventSource +[EventSource(Name = "OpenTelemetry-ResourceDetectors-Container")] +internal class ContainerExtensionsEventSource : EventSource { - public static DockerExtensionsEventSource Log = new DockerExtensionsEventSource(); + public static ContainerExtensionsEventSource Log = new(); [NonEvent] public void ExtractResourceAttributesException(string format, Exception ex) diff --git a/src/OpenTelemetry.Extensions.Docker/Resources/DockerResourceDetector.cs b/src/OpenTelemetry.ResourceDetectors.Container/ContainerResourceDetector.cs similarity index 84% rename from src/OpenTelemetry.Extensions.Docker/Resources/DockerResourceDetector.cs rename to src/OpenTelemetry.ResourceDetectors.Container/ContainerResourceDetector.cs index 4c96171049..c0acba8b91 100644 --- a/src/OpenTelemetry.Extensions.Docker/Resources/DockerResourceDetector.cs +++ b/src/OpenTelemetry.ResourceDetectors.Container/ContainerResourceDetector.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,19 +18,19 @@ using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; -using OpenTelemetry.Extensions.Docker.Utils; +using OpenTelemetry.ResourceDetectors.Container.Utils; using OpenTelemetry.Resources; -namespace OpenTelemetry.Extensions.Docker.Resources; +namespace OpenTelemetry.ResourceDetectors.Container; /// -/// Resource detector for application running in Docker environment. +/// Resource detector for application running in Container environment. /// -public class DockerResourceDetector : IResourceDetector +public class ContainerResourceDetector : IResourceDetector { - private const string FILEPATH = "/proc/self/cgroup"; - private const string FILEPATHV2 = "/proc/self/mountinfo"; - private const string HOSTNAME = "hostname"; + private const string Filepath = "/proc/self/cgroup"; + private const string FilepathV2 = "/proc/self/mountinfo"; + private const string Hostname = "hostname"; /// /// CGroup Parse Versions. @@ -49,15 +49,15 @@ internal enum ParseMode } /// - /// Detects the resource attributes from Docker. + /// Detects the resource attributes from Container. /// /// Resource with key-value pairs of resource attributes. public Resource Detect() { - var cGroupBuild = this.BuildResource(FILEPATH, ParseMode.V1); + var cGroupBuild = this.BuildResource(Filepath, ParseMode.V1); if (cGroupBuild == Resource.Empty) { - cGroupBuild = this.BuildResource(FILEPATHV2, ParseMode.V2); + cGroupBuild = this.BuildResource(FilepathV2, ParseMode.V2); } return cGroupBuild; @@ -79,7 +79,7 @@ internal Resource BuildResource(string path, ParseMode cgroupVersion) } else { - return new Resource(new List>(1) { new(DockerSemanticConventions.AttributeContainerID, containerId!) }); + return new Resource(new List>(1) { new(ContainerSemanticConventions.AttributeContainerId, containerId!) }); } } @@ -169,7 +169,7 @@ private static string RemovePrefixAndSuffixIfNeeded(string input, int startIndex { containerId = GetIdFromLineV1(line); } - else if (cgroupVersion == ParseMode.V2 && line.Contains(HOSTNAME)) + else if (cgroupVersion == ParseMode.V2 && line.Contains(Hostname)) { containerId = GetIdFromLineV2(line); } @@ -183,7 +183,7 @@ private static string RemovePrefixAndSuffixIfNeeded(string input, int startIndex } catch (Exception ex) { - DockerExtensionsEventSource.Log.ExtractResourceAttributesException($"{nameof(DockerResourceDetector)} : Failed to extract Container id from path", ex); + ContainerExtensionsEventSource.Log.ExtractResourceAttributesException($"{nameof(ContainerResourceDetector)} : Failed to extract Container id from path", ex); } return null; diff --git a/src/OpenTelemetry.Extensions.Docker/Resources/DockerSemanticConventions.cs b/src/OpenTelemetry.ResourceDetectors.Container/ContainerSemanticConventions.cs similarity index 70% rename from src/OpenTelemetry.Extensions.Docker/Resources/DockerSemanticConventions.cs rename to src/OpenTelemetry.ResourceDetectors.Container/ContainerSemanticConventions.cs index 0b554a79d0..2400ecc61b 100644 --- a/src/OpenTelemetry.Extensions.Docker/Resources/DockerSemanticConventions.cs +++ b/src/OpenTelemetry.ResourceDetectors.Container/ContainerSemanticConventions.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +14,9 @@ // limitations under the License. // -namespace OpenTelemetry.Extensions.Docker.Resources; +namespace OpenTelemetry.ResourceDetectors.Container; -internal static class DockerSemanticConventions +internal static class ContainerSemanticConventions { - public const string AttributeContainerID = "container.id"; + public const string AttributeContainerId = "container.id"; } diff --git a/src/OpenTelemetry.Extensions.Docker/OpenTelemetry.Extensions.Docker.csproj b/src/OpenTelemetry.ResourceDetectors.Container/OpenTelemetry.ResourceDetectors.Container.csproj similarity index 80% rename from src/OpenTelemetry.Extensions.Docker/OpenTelemetry.Extensions.Docker.csproj rename to src/OpenTelemetry.ResourceDetectors.Container/OpenTelemetry.ResourceDetectors.Container.csproj index 3f82d2a3cc..da126da3d5 100644 --- a/src/OpenTelemetry.Extensions.Docker/OpenTelemetry.Extensions.Docker.csproj +++ b/src/OpenTelemetry.ResourceDetectors.Container/OpenTelemetry.ResourceDetectors.Container.csproj @@ -2,8 +2,8 @@ netstandard2.0;net462 - OpenTelemetry Extensions - Container Resource Detector from Docker environment. - Extensions.Docker- + OpenTelemetry Extensions - Container Resource Detector from Container environment. + ResourceDetectors.Container- enable diff --git a/src/OpenTelemetry.Extensions.Docker/README.md b/src/OpenTelemetry.ResourceDetectors.Container/README.md similarity index 54% rename from src/OpenTelemetry.Extensions.Docker/README.md rename to src/OpenTelemetry.ResourceDetectors.Container/README.md index 1d8b0ed735..3c6f251b42 100644 --- a/src/OpenTelemetry.Extensions.Docker/README.md +++ b/src/OpenTelemetry.ResourceDetectors.Container/README.md @@ -1,37 +1,37 @@ -# Docker Resource Detectors +# Container Resource Detectors ## Getting Started You need to install the -`OpenTelemetry.Extensions.Docker` to be able to use the -Docker Resource Detectors. It detects container.id from -Docker environment. +`OpenTelemetry.ResourceDetectors.Container` to be able to use the +Container Resource Detectors. It detects container.id from +Container environment. ```shell -dotnet add package OpenTelemetry.Extensions.Docker +dotnet add package OpenTelemetry.ResourceDetectors.Container --prerelease ``` ## Usage -You can configure Docker resource detector to +You can configure Container resource detector to the `TracerProvider` with the following example below. ```csharp using OpenTelemetry; -using OpenTelemetry.Extensions.Docker.Resources; +using OpenTelemetry.ResourceDetectors.Container; var tracerProvider = Sdk.CreateTracerProviderBuilder() // other configurations .SetResourceBuilder(ResourceBuilder .CreateEmpty() - .AddDetector(new DockerResourceDetector())) + .AddDetector(new ContainerResourceDetector())) .Build(); ``` The resource detectors will record the following metadata based on where your application is running: -- **DockerResourceDetector**: container.id. +- **ContainerResourceDetector**: container.id. ## References diff --git a/src/OpenTelemetry.Extensions.Docker/Utils/EncodingUtils.cs b/src/OpenTelemetry.ResourceDetectors.Container/Utils/EncodingUtils.cs similarity index 89% rename from src/OpenTelemetry.Extensions.Docker/Utils/EncodingUtils.cs rename to src/OpenTelemetry.ResourceDetectors.Container/Utils/EncodingUtils.cs index 28bd35bc38..eb258ef92f 100644 --- a/src/OpenTelemetry.Extensions.Docker/Utils/EncodingUtils.cs +++ b/src/OpenTelemetry.ResourceDetectors.Container/Utils/EncodingUtils.cs @@ -17,7 +17,7 @@ using System.Collections.Generic; using System.Linq; -namespace OpenTelemetry.Extensions.Docker.Utils; +namespace OpenTelemetry.ResourceDetectors.Container.Utils; internal class EncodingUtils { @@ -28,9 +28,9 @@ internal class EncodingUtils /// true if valid else false. public static bool IsValidHexString(IEnumerable hexString) { - return hexString.Select(currentCharacter => + return hexString.All(currentCharacter => (currentCharacter >= '0' && currentCharacter <= '9') || (currentCharacter >= 'a' && currentCharacter <= 'f') || - (currentCharacter >= 'A' && currentCharacter <= 'F')).All(isHexCharacter => isHexCharacter); + (currentCharacter >= 'A' && currentCharacter <= 'F')); } } diff --git a/test/OpenTelemetry.Extensions.Docker.Tests/Resources/DockerResourceDetectorTests.cs b/test/OpenTelemetry.ResourceDetectors.Container.Tests/ContainerResourceDetectorTests.cs similarity index 70% rename from test/OpenTelemetry.Extensions.Docker.Tests/Resources/DockerResourceDetectorTests.cs rename to test/OpenTelemetry.ResourceDetectors.Container.Tests/ContainerResourceDetectorTests.cs index c5b6120819..18740e0226 100644 --- a/test/OpenTelemetry.Extensions.Docker.Tests/Resources/DockerResourceDetectorTests.cs +++ b/test/OpenTelemetry.ResourceDetectors.Container.Tests/ContainerResourceDetectorTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,166 +17,165 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using OpenTelemetry.Extensions.Docker.Resources; using OpenTelemetry.Resources; using Xunit; -namespace OpenTelemetry.Extensions.Docker.Tests; +namespace OpenTelemetry.ResourceDetectors.Container.Tests; -public class DockerResourceDetectorTests +public class ContainerResourceDetectorTests { private readonly List testValidCasesV1 = new() { - new TestCase() + new TestCase { Name = "cgroupv1 with prefix", Line = "13:name=systemd:/podruntime/docker/kubepods/crio-e2cc29debdf85dde404998aa128997a819ff", ExpectedContainerId = "e2cc29debdf85dde404998aa128997a819ff", - CgroupVersion = DockerResourceDetector.ParseMode.V1, + CgroupVersion = ContainerResourceDetector.ParseMode.V1, }, - new TestCase() + new TestCase { Name = "cgroupv1 with suffix", Line = "13:name=systemd:/podruntime/docker/kubepods/ac679f8a8319c8cf7d38e1adf263bc08d23.aaaa", ExpectedContainerId = "ac679f8a8319c8cf7d38e1adf263bc08d23", - CgroupVersion = DockerResourceDetector.ParseMode.V1, + CgroupVersion = ContainerResourceDetector.ParseMode.V1, }, - new TestCase() + new TestCase { Name = "cgroupv1 with prefix and suffix", Line = "13:name=systemd:/podruntime/docker/kubepods/crio-dc679f8a8319c8cf7d38e1adf263bc08d23.stuff", ExpectedContainerId = "dc679f8a8319c8cf7d38e1adf263bc08d23", - CgroupVersion = DockerResourceDetector.ParseMode.V1, + CgroupVersion = ContainerResourceDetector.ParseMode.V1, }, - new TestCase() + new TestCase { Name = "cgroupv1 with container Id", Line = "13:name=systemd:/pod/d86d75589bf6cc254f3e2cc29debdf85dde404998aa128997a819ff991827356", ExpectedContainerId = "d86d75589bf6cc254f3e2cc29debdf85dde404998aa128997a819ff991827356", - CgroupVersion = DockerResourceDetector.ParseMode.V1, + CgroupVersion = ContainerResourceDetector.ParseMode.V1, }, }; private readonly List testValidCasesV2 = new() { - new TestCase() + new TestCase { Name = "cgroupv2 with container Id", Line = "13:name=systemd:/pod/d86d75589bf6cc254f3e2cc29debdf85dde404998aa128997a819ff991827356/hostname", ExpectedContainerId = "d86d75589bf6cc254f3e2cc29debdf85dde404998aa128997a819ff991827356", - CgroupVersion = DockerResourceDetector.ParseMode.V2, + CgroupVersion = ContainerResourceDetector.ParseMode.V2, }, - new TestCase() + new TestCase { Name = "cgroupv2 with full line", Line = "473 456 254:1 /docker/containers/dc64b5743252dbaef6e30521c34d6bbd1620c8ce65bdb7bf9e7143b61bb5b183/hostname /etc/hostname rw,relatime - ext4 /dev/vda1 rw", ExpectedContainerId = "dc64b5743252dbaef6e30521c34d6bbd1620c8ce65bdb7bf9e7143b61bb5b183", - CgroupVersion = DockerResourceDetector.ParseMode.V2, + CgroupVersion = ContainerResourceDetector.ParseMode.V2, }, - new TestCase() + new TestCase { Name = "cgroupv2 with minikube containerd mountinfo", Line = "1537 1517 8:1 /var/lib/containerd/io.containerd.grpc.v1.cri/sandboxes/fb5916a02feca96bdeecd8e062df9e5e51d6617c8214b5e1f3ff9320f4402ae6/hostname /etc/hostname rw,relatime - ext4 /dev/sda1 rw", ExpectedContainerId = "fb5916a02feca96bdeecd8e062df9e5e51d6617c8214b5e1f3ff9320f4402ae6", - CgroupVersion = DockerResourceDetector.ParseMode.V2, + CgroupVersion = ContainerResourceDetector.ParseMode.V2, }, - new TestCase() + new TestCase { Name = "cgroupv2 with minikube docker mountinfo", Line = "2327 2307 8:1 /var/lib/docker/containers/a1551a1d7e1881d6c18d2c9ec462cab6ad3666825f0adb2098e9d5b198fd7e19/hostname /etc/hostname rw,relatime - ext4 /dev/sda1 rw", ExpectedContainerId = "a1551a1d7e1881d6c18d2c9ec462cab6ad3666825f0adb2098e9d5b198fd7e19", - CgroupVersion = DockerResourceDetector.ParseMode.V2, + CgroupVersion = ContainerResourceDetector.ParseMode.V2, }, - new TestCase() + new TestCase { Name = "cgroupv2 with minikube docker mountinfo2", Line = "929 920 254:1 /docker/volumes/minikube/_data/lib/docker/containers/0eaa6718003210b6520f7e82d14b4c8d4743057a958a503626240f8d1900bc33/hostname /etc/hostname rw,relatime - ext4 /dev/vda1 rw", ExpectedContainerId = "0eaa6718003210b6520f7e82d14b4c8d4743057a958a503626240f8d1900bc33", - CgroupVersion = DockerResourceDetector.ParseMode.V2, + CgroupVersion = ContainerResourceDetector.ParseMode.V2, }, - new TestCase() + new TestCase { Name = "cgroupv2 with podman mountinfo", Line = "1096 1088 0:104 /containers/overlay-containers/1a2de27e7157106568f7e081e42a8c14858c02bd9df30d6e352b298178b46809/userdata/hostname /etc/hostname rw,nosuid,nodev,relatime - tmpfs tmpfs rw,size=813800k,nr_inodes=203450,mode=700,uid=1000,gid=1000", ExpectedContainerId = "1a2de27e7157106568f7e081e42a8c14858c02bd9df30d6e352b298178b46809", - CgroupVersion = DockerResourceDetector.ParseMode.V2, + CgroupVersion = ContainerResourceDetector.ParseMode.V2, }, }; private readonly List testInvalidCases = new() { - new TestCase() + new TestCase { Name = "Invalid cgroupv1 line", Line = "13:name=systemd:/podruntime/docker/kubepods/ac679f8a8319c8cf7d38e1adf263bc08d23zzzz", - CgroupVersion = DockerResourceDetector.ParseMode.V1, + CgroupVersion = ContainerResourceDetector.ParseMode.V1, }, - new TestCase() + new TestCase { Name = "Invalid hex cgroupv2 line (contains a z)", Line = "13:name=systemd:/var/lib/containerd/io.containerd.grpc.v1.cri/sandboxes/fb5916a02feca96bdeecd8e062df9e5e51d6617c8214b5e1f3fz9320f4402ae6/hostname", - CgroupVersion = DockerResourceDetector.ParseMode.V2, + CgroupVersion = ContainerResourceDetector.ParseMode.V2, }, }; [Fact] public void TestValidContainer() { - var dockerResourceDetector = new DockerResourceDetector(); + var containerResourceDetector = new ContainerResourceDetector(); var allValidTestCases = this.testValidCasesV1.Concat(this.testValidCasesV2); foreach (var testCase in allValidTestCases) { - using TempFile tempFile = new TempFile(); + using var tempFile = new TempFile(); tempFile.Write(testCase.Line); Assert.Equal( testCase.ExpectedContainerId, - GetContainerId(dockerResourceDetector.BuildResource(tempFile.FilePath, testCase.CgroupVersion))); + GetContainerId(containerResourceDetector.BuildResource(tempFile.FilePath, testCase.CgroupVersion))); } } [Fact] public void TestInvalidContainer() { - var dockerResourceDetector = new DockerResourceDetector(); + var containerResourceDetector = new ContainerResourceDetector(); // Valid in cgroupv1 is not valid in cgroupv2 foreach (var testCase in this.testValidCasesV1) { - using TempFile tempFile = new TempFile(); + using var tempFile = new TempFile(); tempFile.Write(testCase.Line); Assert.Equal( - dockerResourceDetector.BuildResource(tempFile.FilePath, DockerResourceDetector.ParseMode.V2), + containerResourceDetector.BuildResource(tempFile.FilePath, ContainerResourceDetector.ParseMode.V2), Resource.Empty); } // Valid in cgroupv1 is not valid in cgroupv1 foreach (var testCase in this.testValidCasesV2) { - using TempFile tempFile = new TempFile(); + using var tempFile = new TempFile(); tempFile.Write(testCase.Line); Assert.Equal( - dockerResourceDetector.BuildResource(tempFile.FilePath, DockerResourceDetector.ParseMode.V1), + containerResourceDetector.BuildResource(tempFile.FilePath, ContainerResourceDetector.ParseMode.V1), Resource.Empty); } // test invalid cases foreach (var testCase in this.testInvalidCases) { - using TempFile tempFile = new TempFile(); + using var tempFile = new TempFile(); tempFile.Write(testCase.Line); - Assert.Equal(dockerResourceDetector.BuildResource(tempFile.FilePath, testCase.CgroupVersion), Resource.Empty); + Assert.Equal(containerResourceDetector.BuildResource(tempFile.FilePath, testCase.CgroupVersion), Resource.Empty); } // test invalid file - Assert.Equal(dockerResourceDetector.BuildResource(Path.GetTempPath(), DockerResourceDetector.ParseMode.V1), Resource.Empty); - Assert.Equal(dockerResourceDetector.BuildResource(Path.GetTempPath(), DockerResourceDetector.ParseMode.V2), Resource.Empty); + Assert.Equal(containerResourceDetector.BuildResource(Path.GetTempPath(), ContainerResourceDetector.ParseMode.V1), Resource.Empty); + Assert.Equal(containerResourceDetector.BuildResource(Path.GetTempPath(), ContainerResourceDetector.ParseMode.V2), Resource.Empty); } private static string GetContainerId(Resource resource) { var resourceAttributes = resource.Attributes.ToDictionary(x => x.Key, x => x.Value); - return resourceAttributes[DockerSemanticConventions.AttributeContainerID]?.ToString(); + return resourceAttributes[ContainerSemanticConventions.AttributeContainerId]?.ToString(); } private sealed class TestCase @@ -187,6 +186,6 @@ private sealed class TestCase public string ExpectedContainerId { get; set; } - public DockerResourceDetector.ParseMode CgroupVersion { get; set; } + public ContainerResourceDetector.ParseMode CgroupVersion { get; set; } } } diff --git a/test/OpenTelemetry.Extensions.Docker.Tests/OpenTelemetry.Extensions.Docker.Tests.csproj b/test/OpenTelemetry.ResourceDetectors.Container.Tests/OpenTelemetry.ResourceDetectors.Container.Tests.csproj similarity index 76% rename from test/OpenTelemetry.Extensions.Docker.Tests/OpenTelemetry.Extensions.Docker.Tests.csproj rename to test/OpenTelemetry.ResourceDetectors.Container.Tests/OpenTelemetry.ResourceDetectors.Container.Tests.csproj index 8457c84d05..6c4811cb1f 100644 --- a/test/OpenTelemetry.Extensions.Docker.Tests/OpenTelemetry.Extensions.Docker.Tests.csproj +++ b/test/OpenTelemetry.ResourceDetectors.Container.Tests/OpenTelemetry.ResourceDetectors.Container.Tests.csproj @@ -1,7 +1,7 @@ - Unit test project for Docker Detector for OpenTelemetry + Unit test project for Container Detector for OpenTelemetry net7.0;net6.0 $(TargetFrameworks);net462 @@ -19,7 +19,11 @@ - + + + + + diff --git a/test/OpenTelemetry.Extensions.Docker.Tests/Resources/TempFile.cs b/test/OpenTelemetry.ResourceDetectors.Container.Tests/TempFile.cs similarity index 71% rename from test/OpenTelemetry.Extensions.Docker.Tests/Resources/TempFile.cs rename to test/OpenTelemetry.ResourceDetectors.Container.Tests/TempFile.cs index 61bb38d80f..64c66fe657 100644 --- a/test/OpenTelemetry.Extensions.Docker.Tests/Resources/TempFile.cs +++ b/test/OpenTelemetry.ResourceDetectors.Container.Tests/TempFile.cs @@ -18,28 +18,22 @@ using System.IO; using System.Threading; -namespace OpenTelemetry.Extensions.Docker.Tests; +namespace OpenTelemetry.ResourceDetectors.Container.Tests; internal class TempFile : IDisposable { - private string filePath; - public TempFile() { - this.filePath = Path.GetTempFileName(); + this.FilePath = Path.GetTempFileName(); } - public string FilePath - { - get { return this.filePath; } - set { this.filePath = value; } - } + public string FilePath { get; set; } public void Write(string data) { - using (FileStream stream = new FileStream(this.filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete)) + using (var stream = new FileStream(this.FilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete)) { - using (StreamWriter sw = new StreamWriter(stream)) + using (var sw = new StreamWriter(stream)) { sw.Write(data); } @@ -48,11 +42,11 @@ public void Write(string data) public void Dispose() { - for (int tries = 0; ; tries++) + for (var tries = 0; ; tries++) { try { - File.Delete(this.filePath); + File.Delete(this.FilePath); return; } catch (IOException) when (tries < 3) From 11c69f199e97be065a7bd119f2f9d87bca3738b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Sat, 1 Apr 2023 02:32:24 +0200 Subject: [PATCH 06/16] [Instrumentation.AWS] drop default parameter from registration method (#1117) --- .../.publicApi/net462/PublicAPI.Unshipped.txt | 4 +++- .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 4 +++- .../CHANGELOG.md | 2 ++ .../TracerProviderBuilderExtensions.cs | 10 +++++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Contrib.Instrumentation.AWS/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Contrib.Instrumentation.AWS/.publicApi/net462/PublicAPI.Unshipped.txt index 7dc5c58110..fb419c1de8 100644 --- a/src/OpenTelemetry.Contrib.Instrumentation.AWS/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Contrib.Instrumentation.AWS/.publicApi/net462/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ -#nullable enable +*REMOVED*static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action? configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder! +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder! +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action? configure) -> OpenTelemetry.Trace.TracerProviderBuilder! diff --git a/src/OpenTelemetry.Contrib.Instrumentation.AWS/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Contrib.Instrumentation.AWS/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 7dc5c58110..fb419c1de8 100644 --- a/src/OpenTelemetry.Contrib.Instrumentation.AWS/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Contrib.Instrumentation.AWS/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ -#nullable enable +*REMOVED*static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action? configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder! +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder! +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action? configure) -> OpenTelemetry.Trace.TracerProviderBuilder! diff --git a/src/OpenTelemetry.Contrib.Instrumentation.AWS/CHANGELOG.md b/src/OpenTelemetry.Contrib.Instrumentation.AWS/CHANGELOG.md index 28303b32a3..ae9dc28eab 100644 --- a/src/OpenTelemetry.Contrib.Instrumentation.AWS/CHANGELOG.md +++ b/src/OpenTelemetry.Contrib.Instrumentation.AWS/CHANGELOG.md @@ -4,6 +4,8 @@ * Raised the minimum .NET version to `net462` ([#1095](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1095)) +* Removes `AddAWSInstrumentation` method with default configure default parameter. + ([#1117](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1117)) ## 1.0.2 diff --git a/src/OpenTelemetry.Contrib.Instrumentation.AWS/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Contrib.Instrumentation.AWS/TracerProviderBuilderExtensions.cs index 47063958d0..32bcbfe2ba 100644 --- a/src/OpenTelemetry.Contrib.Instrumentation.AWS/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Contrib.Instrumentation.AWS/TracerProviderBuilderExtensions.cs @@ -26,6 +26,14 @@ namespace OpenTelemetry.Trace; /// public static class TracerProviderBuilderExtensions { + /// + /// Enables AWS Instrumentation. + /// + /// being configured. + /// The instance of to chain the calls. + public static TracerProviderBuilder AddAWSInstrumentation( + this TracerProviderBuilder builder) => AddAWSInstrumentation(builder, configure: null); + /// /// Enables AWS Instrumentation. /// @@ -34,7 +42,7 @@ public static class TracerProviderBuilderExtensions /// The instance of to chain the calls. public static TracerProviderBuilder AddAWSInstrumentation( this TracerProviderBuilder builder, - Action? configure = null) + Action? configure) { Guard.ThrowIfNull(builder); From af46ef24f0377f246463a38b91f2e7a50e664ece Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Mon, 3 Apr 2023 11:05:07 -0700 Subject: [PATCH 07/16] [OneCollectorExporter] eventId support (#1127) --- .../CHANGELOG.md | 4 ++++ .../LogRecordCommonSchemaJsonSerializer.cs | 6 ++---- .../LogRecordCommonSchemaJsonSerializerTests.cs | 13 +++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md b/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md index b17bc47694..4de8d3d852 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md @@ -14,6 +14,10 @@ exception is present on `LogRecord`s. ([#1082](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1082)) +* Added support for sending common schema `eventId` field when `EventId.Id` is + non-zero on `LogRecord`s. + ([#1127](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1127)) + ## 0.1.0-alpha.2 Released 2023-Mar-6 diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs index b2d2f7f957..9af77e3f22 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs @@ -23,6 +23,7 @@ namespace OpenTelemetry.Exporter.OneCollector; internal sealed class LogRecordCommonSchemaJsonSerializer : CommonSchemaJsonSerializer { + private static readonly JsonEncodedText EventIdProperty = JsonEncodedText.Encode("eventId"); private static readonly JsonEncodedText SeverityTextProperty = JsonEncodedText.Encode("severityText"); private static readonly JsonEncodedText SeverityNumberProperty = JsonEncodedText.Encode("severityNumber"); private static readonly JsonEncodedText BodyProperty = JsonEncodedText.Encode("body"); @@ -120,13 +121,10 @@ protected override void SerializeItemToJson(Resource resource, LogRecord item, C writer.WriteStartObject(CommonSchemaJsonSerializationHelper.DataProperty); - /* TODO: There doesn't seem to be a spot in common schema defined for - event.id so we will drop for now. - if (item.EventId.Id != 0) { writer.WriteNumber(EventIdProperty, item.EventId.Id); - }*/ + } var logLevel = (int)item.LogLevel; writer.WriteString(SeverityTextProperty, LogLevelToSeverityTextMappings[logLevel]); diff --git a/test/OpenTelemetry.Exporter.OneCollector.Tests/LogRecordCommonSchemaJsonSerializerTests.cs b/test/OpenTelemetry.Exporter.OneCollector.Tests/LogRecordCommonSchemaJsonSerializerTests.cs index 5c1b506325..a42e14d2db 100644 --- a/test/OpenTelemetry.Exporter.OneCollector.Tests/LogRecordCommonSchemaJsonSerializerTests.cs +++ b/test/OpenTelemetry.Exporter.OneCollector.Tests/LogRecordCommonSchemaJsonSerializerTests.cs @@ -83,6 +83,19 @@ public void LogRecordCategoryNameAndEventNameJsonTest(string categoryName, strin json); } + [Fact] + public void LogRecordEventIdJsonTest() + { + string json = GetLogRecordJson(1, (index, logRecord) => + { + logRecord.EventId = new(18); + }); + + Assert.Equal( + "{\"ver\":\"4.0\",\"name\":\"Namespace.Name\",\"time\":\"2032-01-18T10:11:12Z\",\"iKey\":\"o:tenant-token\",\"data\":{\"eventId\":18,\"severityText\":\"Trace\",\"severityNumber\":1}}\n", + json); + } + [Fact] public void LogRecordTimestampJsonTest() { From a1acd45cb962088aac83e8745b74ce8f3696b18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Tue, 4 Apr 2023 06:31:47 +0200 Subject: [PATCH 08/16] Unify Exception ToInvariantString method (#1126) --- build/Common.props | 5 +- .../AWSXRayEventSource.cs | 26 ++------- ...elemetry.Contrib.Extensions.AWSXRay.csproj | 1 + .../Api/ExceptionExtensions.cs | 12 ++--- .../Internal/ExporterEventSource.cs | 30 ++--------- .../MsgPackExporter/MsgPackLogExporter.cs | 18 +------ .../OpenTelemetry.Exporter.Geneva.csproj | 1 + .../TLDExporter/TldLogExporter.cs | 18 +------ .../InstanaExporterEventSource.cs | 24 +-------- .../OpenTelemetry.Exporter.Instana.csproj | 1 + .../OneCollectorExporterEventSource.cs | 23 ++------ .../LogRecordCommonSchemaJsonSerializer.cs | 3 +- ...OpenTelemetry.Exporter.OneCollector.csproj | 1 + .../ExporterStackdriverEventSource.cs | 54 +------------------ .../OpenTelemetry.Exporter.Stackdriver.csproj | 3 +- .../OpenTelemetry.Extensions.csproj | 2 +- ...entation.AspNet.TelemetryHttpModule.csproj | 2 +- ...penTelemetry.Instrumentation.AspNet.csproj | 2 +- ...Instrumentation.ElasticsearchClient.csproj | 3 +- ...tityFrameworkInstrumentationEventSource.cs | 23 +------- ...Instrumentation.EntityFrameworkCore.csproj | 3 +- .../OwinInstrumentationEventSource.cs | 26 ++------- .../OpenTelemetry.Instrumentation.Owin.csproj | 2 +- ...penTelemetry.Instrumentation.Quartz.csproj | 3 +- ....Instrumentation.StackExchangeRedis.csproj | 1 + .../WcfInstrumentationEventSource.cs | 26 ++------- .../OpenTelemetry.Instrumentation.Wcf.csproj | 1 + ...etry.PersistentStorage.Abstractions.csproj | 1 + ...ersistentStorageAbstractionsEventSource.cs | 24 +-------- ...emetry.PersistentStorage.FileSystem.csproj | 1 + .../PersistentStorageEventSource.cs | 40 ++++---------- .../ContainerExtensionsEventSource.cs | 24 +-------- ...lemetry.ResourceDetectors.Container.csproj | 1 + .../AWSSamplerEventSource.cs | 22 -------- ...try.Instrumentation.AWSLambda.Tests.csproj | 1 + 35 files changed, 73 insertions(+), 355 deletions(-) diff --git a/build/Common.props b/build/Common.props index fd517f699f..5e644908d3 100644 --- a/build/Common.props +++ b/build/Common.props @@ -54,6 +54,10 @@ + + + + @@ -62,7 +66,6 @@ - diff --git a/src/OpenTelemetry.Contrib.Extensions.AWSXRay/AWSXRayEventSource.cs b/src/OpenTelemetry.Contrib.Extensions.AWSXRay/AWSXRayEventSource.cs index c42b4eac89..4e0ba6c9d9 100644 --- a/src/OpenTelemetry.Contrib.Extensions.AWSXRay/AWSXRayEventSource.cs +++ b/src/OpenTelemetry.Contrib.Extensions.AWSXRay/AWSXRayEventSource.cs @@ -16,8 +16,7 @@ using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; +using OpenTelemetry.Internal; namespace OpenTelemetry.Contrib.Extensions.AWSXRay; @@ -31,7 +30,7 @@ public void ActivityContextExtractException(string format, Exception ex) { if (this.IsEnabled(EventLevel.Warning, (EventKeywords)(-1))) { - this.FailedToExtractActivityContext(format, ToInvariantString(ex)); + this.FailedToExtractActivityContext(format, ex.ToInvariantString()); } } @@ -40,7 +39,7 @@ public void ResourceAttributesExtractException(string format, Exception ex) { if (this.IsEnabled(EventLevel.Warning, (EventKeywords)(-1))) { - this.FailedToExtractResourceAttributes(format, ToInvariantString(ex)); + this.FailedToExtractResourceAttributes(format, ex.ToInvariantString()); } } @@ -67,23 +66,4 @@ public void FailedToValidateCertificate(string format, string error) { this.WriteEvent(4, format, error); } - - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } } diff --git a/src/OpenTelemetry.Contrib.Extensions.AWSXRay/OpenTelemetry.Contrib.Extensions.AWSXRay.csproj b/src/OpenTelemetry.Contrib.Extensions.AWSXRay/OpenTelemetry.Contrib.Extensions.AWSXRay.csproj index d804733696..d06b9eb9ca 100644 --- a/src/OpenTelemetry.Contrib.Extensions.AWSXRay/OpenTelemetry.Contrib.Extensions.AWSXRay.csproj +++ b/src/OpenTelemetry.Contrib.Extensions.AWSXRay/OpenTelemetry.Contrib.Extensions.AWSXRay.csproj @@ -5,6 +5,7 @@ OpenTelemetry extensions for AWS X-Ray. Extensions.AWSXRay- enable + true diff --git a/src/OpenTelemetry.Contrib.Shared/Api/ExceptionExtensions.cs b/src/OpenTelemetry.Contrib.Shared/Api/ExceptionExtensions.cs index 9fc3296917..dea6a61c66 100644 --- a/src/OpenTelemetry.Contrib.Shared/Api/ExceptionExtensions.cs +++ b/src/OpenTelemetry.Contrib.Shared/Api/ExceptionExtensions.cs @@ -14,9 +14,9 @@ // limitations under the License. // -using System; +#nullable enable + using System.Globalization; -using System.Threading; namespace OpenTelemetry.Internal; @@ -28,18 +28,18 @@ internal static class ExceptionExtensions /// /// Exception to convert to string. /// Exception as string with no culture. - public static string ToInvariantString(this Exception exception) + public static string ToInvariantString(this System.Exception exception) { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; + var originalUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture; try { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; + System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; return exception.ToString(); } finally { - Thread.CurrentThread.CurrentUICulture = originalUICulture; + System.Threading.Thread.CurrentThread.CurrentUICulture = originalUICulture; } } } diff --git a/src/OpenTelemetry.Exporter.Geneva/Internal/ExporterEventSource.cs b/src/OpenTelemetry.Exporter.Geneva/Internal/ExporterEventSource.cs index 65f43be9af..91cf275805 100644 --- a/src/OpenTelemetry.Exporter.Geneva/Internal/ExporterEventSource.cs +++ b/src/OpenTelemetry.Exporter.Geneva/Internal/ExporterEventSource.cs @@ -16,8 +16,7 @@ using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; +using OpenTelemetry.Internal; namespace OpenTelemetry.Exporter.Geneva; @@ -43,7 +42,7 @@ public void FailedToSendTraceData(Exception ex) // descrs[0].Size = ((arg1.Length + 1) * 2); // I'm assuming it calculates the size of string, then it should be: // (count of chars) * sizeof(char) + sizeof(Length:int) = (str.Length * 2 + 4). - this.FailedToSendTraceData(ToInvariantString(ex)); + this.FailedToSendTraceData(ex.ToInvariantString()); } } @@ -53,7 +52,7 @@ public void FailedToSendLogData(Exception ex) if (this.IsEnabled(EventLevel.Error, EventKeywords.All)) { // TODO: Do not hit ETW size limit even for external library exception stack. - this.FailedToSendLogData(ToInvariantString(ex)); + this.FailedToSendLogData(ex.ToInvariantString()); } } @@ -63,7 +62,7 @@ public void FailedToSendMetricData(string monitoringAccount, string metricNamesp if (this.IsEnabled(EventLevel.Error, EventKeywords.All)) { // TODO: Do not hit ETW size limit even for external library exception stack. - this.FailedToSendMetricData(monitoringAccount, metricNamespace, metricName, ToInvariantString(ex)); + this.FailedToSendMetricData(monitoringAccount, metricNamespace, metricName, ex.ToInvariantString()); } } @@ -73,7 +72,7 @@ public void ExporterException(string message, Exception ex) if (Log.IsEnabled(EventLevel.Error, EventKeywords.All)) { // TODO: Do not hit ETW size limit even for external library exception stack. - this.ExporterException(message, ToInvariantString(ex)); + this.ExporterException(message, ex.ToInvariantString()); } } @@ -100,23 +99,4 @@ public void ExporterException(string message, string error) { this.WriteEvent(EVENT_ID_ERROR, message, error); } - - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } } diff --git a/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MsgPackLogExporter.cs b/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MsgPackLogExporter.cs index f02febac53..b8c9534796 100644 --- a/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MsgPackLogExporter.cs +++ b/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MsgPackLogExporter.cs @@ -21,6 +21,7 @@ using System.Runtime.InteropServices; using System.Threading; using Microsoft.Extensions.Logging; +using OpenTelemetry.Internal; using OpenTelemetry.Logs; namespace OpenTelemetry.Exporter.Geneva; @@ -370,7 +371,7 @@ internal int SerializeLogRecord(LogRecord logRecord) // before running out of limit instead of STRING_SIZE_LIMIT_CHAR_COUNT. // 2. Trim smarter, by trimming the middle of stack, an // keep top and bottom. - var exceptionStack = ToInvariantString(logRecord.Exception); + var exceptionStack = logRecord.Exception.ToInvariantString(); cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, "env_ex_stack"); cursor = MessagePackSerializer.SerializeUnicodeString(buffer, cursor, exceptionStack); cntFields += 1; @@ -413,21 +414,6 @@ private static byte GetSeverityNumber(LogLevel logLevel) } } - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } - public void Dispose() { if (this.isDisposed) diff --git a/src/OpenTelemetry.Exporter.Geneva/OpenTelemetry.Exporter.Geneva.csproj b/src/OpenTelemetry.Exporter.Geneva/OpenTelemetry.Exporter.Geneva.csproj index 41c3ddcc7b..4478d94496 100644 --- a/src/OpenTelemetry.Exporter.Geneva/OpenTelemetry.Exporter.Geneva.csproj +++ b/src/OpenTelemetry.Exporter.Geneva/OpenTelemetry.Exporter.Geneva.csproj @@ -10,6 +10,7 @@ $(TargetFrameworks);net462 Exporter.Geneva- true + true diff --git a/src/OpenTelemetry.Exporter.Geneva/TLDExporter/TldLogExporter.cs b/src/OpenTelemetry.Exporter.Geneva/TLDExporter/TldLogExporter.cs index d056ef9a54..415891a9c2 100644 --- a/src/OpenTelemetry.Exporter.Geneva/TLDExporter/TldLogExporter.cs +++ b/src/OpenTelemetry.Exporter.Geneva/TLDExporter/TldLogExporter.cs @@ -278,7 +278,7 @@ internal void SerializeLogRecord(LogRecord logRecord) // before running out of limit instead of STRING_SIZE_LIMIT_CHAR_COUNT. // 2. Trim smarter, by trimming the middle of stack, an // keep top and bottom. - var exceptionStack = ToInvariantString(logRecord.Exception); + var exceptionStack = logRecord.Exception.ToInvariantString(); eb.AddCountedAnsiString("ext_ex_stack", exceptionStack, Encoding.UTF8, 0, Math.Min(exceptionStack.Length, StringLengthLimit)); partAFieldsCount++; } @@ -484,22 +484,6 @@ private static string GetSanitizedCategoryName(string categoryName) return result.Slice(0, validNameLength).ToString(); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } - private static readonly Action ProcessScopeForIndividualColumns = (scope, state) => { var stateData = state.serializationData.Value; diff --git a/src/OpenTelemetry.Exporter.Instana/Implementation/InstanaExporterEventSource.cs b/src/OpenTelemetry.Exporter.Instana/Implementation/InstanaExporterEventSource.cs index 8a5ede78f0..1d797a2bda 100644 --- a/src/OpenTelemetry.Exporter.Instana/Implementation/InstanaExporterEventSource.cs +++ b/src/OpenTelemetry.Exporter.Instana/Implementation/InstanaExporterEventSource.cs @@ -16,8 +16,7 @@ using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; +using OpenTelemetry.Internal; namespace OpenTelemetry.Exporter.Instana.Implementation; @@ -35,7 +34,7 @@ public void FailedExport(Exception ex) { if (this.IsEnabled(EventLevel.Error, EventKeywords.All)) { - this.FailedExport(ToInvariantString(ex)); + this.FailedExport(ex.ToInvariantString()); } } @@ -44,23 +43,4 @@ public void FailedExport(string exception) { this.WriteEvent(1, exception); } - - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } } diff --git a/src/OpenTelemetry.Exporter.Instana/OpenTelemetry.Exporter.Instana.csproj b/src/OpenTelemetry.Exporter.Instana/OpenTelemetry.Exporter.Instana.csproj index 8977649b0f..6afb43a629 100644 --- a/src/OpenTelemetry.Exporter.Instana/OpenTelemetry.Exporter.Instana.csproj +++ b/src/OpenTelemetry.Exporter.Instana/OpenTelemetry.Exporter.Instana.csproj @@ -6,6 +6,7 @@ Instana Tracing APM Instana .NET Exporter for OpenTelemetry Exporter.Instana- + true diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/OneCollectorExporterEventSource.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/OneCollectorExporterEventSource.cs index bb73a80a13..8cfefcbe63 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/OneCollectorExporterEventSource.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/OneCollectorExporterEventSource.cs @@ -15,8 +15,8 @@ // using System.Diagnostics.Tracing; -using System.Globalization; using System.Runtime.CompilerServices; +using OpenTelemetry.Internal; namespace OpenTelemetry.Exporter.OneCollector; @@ -33,7 +33,7 @@ public void WriteExportExceptionThrownEventIfEnabled(string itemType, Exception { if (this.IsEnabled(EventLevel.Error, EventKeywords.All)) { - this.ExportExceptionThrown(itemType, ExceptionToInvariantString(exception)); + this.ExportExceptionThrown(itemType, exception.ToInvariantString()); } } @@ -60,7 +60,7 @@ public void WriteTransportExceptionThrownEventIfEnabled(string transportType, Ex { if (this.IsEnabled(EventLevel.Error, EventKeywords.All)) { - this.TransportExceptionThrown(transportType, ExceptionToInvariantString(exception)); + this.TransportExceptionThrown(transportType, exception.ToInvariantString()); } } @@ -78,7 +78,7 @@ public void WriteExceptionThrownFromUserCodeEventIfEnabled(string userCodeType, { if (this.IsEnabled(EventLevel.Error, EventKeywords.All)) { - this.ExceptionThrownFromUserCode(userCodeType, ExceptionToInvariantString(exception)); + this.ExceptionThrownFromUserCode(userCodeType, exception.ToInvariantString()); } } @@ -147,19 +147,4 @@ public void AttributeDropped(string itemType, string name, string reason) { this.WriteEvent(11, itemType, name, reason); } - - internal static string ExceptionToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } } diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs index 9af77e3f22..2d202236b7 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs @@ -16,6 +16,7 @@ using System.Diagnostics; using System.Text.Json; +using OpenTelemetry.Internal; using OpenTelemetry.Logs; using OpenTelemetry.Resources; @@ -208,7 +209,7 @@ private void SerializeExtensionPropertiesToJson(LogRecord item, Utf8JsonWriter w if (this.exceptionStackTraceHandling == OneCollectorExporterSerializationExceptionStackTraceHandlingType.IncludeAsString) { - writer.WriteString(ExceptionExtensionStackTraceProperty, OneCollectorExporterEventSource.ExceptionToInvariantString(item.Exception)); + writer.WriteString(ExceptionExtensionStackTraceProperty, item.Exception.ToInvariantString()); } writer.WriteEndObject(); diff --git a/src/OpenTelemetry.Exporter.OneCollector/OpenTelemetry.Exporter.OneCollector.csproj b/src/OpenTelemetry.Exporter.OneCollector/OpenTelemetry.Exporter.OneCollector.csproj index bb4ac8d267..cd6db1ff7d 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/OpenTelemetry.Exporter.OneCollector.csproj +++ b/src/OpenTelemetry.Exporter.OneCollector/OpenTelemetry.Exporter.OneCollector.csproj @@ -10,6 +10,7 @@ enable true true + true diff --git a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ExporterStackdriverEventSource.cs b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ExporterStackdriverEventSource.cs index c6c55009ec..118f88aac5 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ExporterStackdriverEventSource.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ExporterStackdriverEventSource.cs @@ -16,8 +16,7 @@ using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; +using OpenTelemetry.Internal; namespace OpenTelemetry.Exporter.Stackdriver.Implementation; @@ -26,42 +25,12 @@ internal class ExporterStackdriverEventSource : EventSource { public static readonly ExporterStackdriverEventSource Log = new ExporterStackdriverEventSource(); - [NonEvent] - public void UnknownProblemInWorkerThreadError(Exception ex) - { - if (Log.IsEnabled(EventLevel.Error, EventKeywords.All)) - { - this.UnknownProblemInWorkerThreadError(ToInvariantString(ex)); - } - } - - [Event(1, Message = "Stackdriver exporter encountered an unknown error and will shut down. Exception: {0}", Level = EventLevel.Error)] - public void UnknownProblemInWorkerThreadError(string ex) - { - this.WriteEvent(1, ex); - } - - [NonEvent] - public void UnknownProblemWhileCreatingStackdriverTimeSeriesError(Exception ex) - { - if (Log.IsEnabled(EventLevel.Error, EventKeywords.All)) - { - this.UnknownProblemWhileCreatingStackdriverTimeSeriesError(ToInvariantString(ex)); - } - } - - [Event(2, Message = "Stackdriver exporter failed to create time series. Time series will be lost. Exception: {0}", Level = EventLevel.Error)] - public void UnknownProblemWhileCreatingStackdriverTimeSeriesError(string ex) - { - this.WriteEvent(2, ex); - } - [NonEvent] public void ExportMethodException(Exception ex) { if (Log.IsEnabled(EventLevel.Error, EventKeywords.All)) { - this.ExportMethodException(ToInvariantString(ex)); + this.ExportMethodException(ex.ToInvariantString()); } } @@ -70,23 +39,4 @@ public void ExportMethodException(string ex) { this.WriteEvent(1, ex); } - - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } } diff --git a/src/OpenTelemetry.Exporter.Stackdriver/OpenTelemetry.Exporter.Stackdriver.csproj b/src/OpenTelemetry.Exporter.Stackdriver/OpenTelemetry.Exporter.Stackdriver.csproj index f8fbd7ea5a..34f46926f4 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/OpenTelemetry.Exporter.Stackdriver.csproj +++ b/src/OpenTelemetry.Exporter.Stackdriver/OpenTelemetry.Exporter.Stackdriver.csproj @@ -1,10 +1,11 @@ - + netstandard2.0;net462 Stackdriver .NET Exporter for OpenTelemetry. $(PackageTags);Stackdriver;Google;GCP;distributed-tracing Exporter.Stackdriver- + true diff --git a/src/OpenTelemetry.Extensions/OpenTelemetry.Extensions.csproj b/src/OpenTelemetry.Extensions/OpenTelemetry.Extensions.csproj index 8462a7674f..6518979045 100644 --- a/src/OpenTelemetry.Extensions/OpenTelemetry.Extensions.csproj +++ b/src/OpenTelemetry.Extensions/OpenTelemetry.Extensions.csproj @@ -4,6 +4,7 @@ netstandard2.0;net462; net6.0;$(TargetFrameworks) + true OpenTelemetry .NET SDK preview features and extensions Extensions- enable @@ -11,7 +12,6 @@ - diff --git a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj index e84816eca4..a084f11f68 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj +++ b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj @@ -2,13 +2,13 @@ $(NetFrameworkMinimumSupportedVersion) + true A module that instruments incoming request with System.Diagnostics.Activity and notifies listeners with DiagnosticsSource. $(PackageTags);distributed-tracing;AspNet;MVC;WebAPI Instrumentation.AspNet.TelemetryHttpModule- - diff --git a/src/OpenTelemetry.Instrumentation.AspNet/OpenTelemetry.Instrumentation.AspNet.csproj b/src/OpenTelemetry.Instrumentation.AspNet/OpenTelemetry.Instrumentation.AspNet.csproj index 6cac679253..f0eec1af27 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/OpenTelemetry.Instrumentation.AspNet.csproj +++ b/src/OpenTelemetry.Instrumentation.AspNet/OpenTelemetry.Instrumentation.AspNet.csproj @@ -2,6 +2,7 @@ $(NetFrameworkMinimumSupportedVersion) + true ASP.NET instrumentation for OpenTelemetry .NET $(PackageTags);distributed-tracing;AspNet;MVC;WebAPI true @@ -14,7 +15,6 @@ - diff --git a/src/OpenTelemetry.Instrumentation.ElasticsearchClient/OpenTelemetry.Instrumentation.ElasticsearchClient.csproj b/src/OpenTelemetry.Instrumentation.ElasticsearchClient/OpenTelemetry.Instrumentation.ElasticsearchClient.csproj index b0323bbc18..e8560eac26 100644 --- a/src/OpenTelemetry.Instrumentation.ElasticsearchClient/OpenTelemetry.Instrumentation.ElasticsearchClient.csproj +++ b/src/OpenTelemetry.Instrumentation.ElasticsearchClient/OpenTelemetry.Instrumentation.ElasticsearchClient.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;net462 @@ -6,6 +6,7 @@ $(PackageTags);distributed-tracing Instrumentation.ElasticsearchClient- true + true diff --git a/src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkInstrumentationEventSource.cs b/src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkInstrumentationEventSource.cs index 1b6e8a2e70..520c3063a3 100644 --- a/src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkInstrumentationEventSource.cs +++ b/src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkInstrumentationEventSource.cs @@ -16,8 +16,6 @@ using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; using OpenTelemetry.Internal; namespace OpenTelemetry.Instrumentation.EntityFrameworkCore.Implementation; @@ -32,7 +30,7 @@ public void UnknownErrorProcessingEvent(string handlerName, string eventName, Ex { if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1))) { - this.UnknownErrorProcessingEvent(handlerName, eventName, ToInvariantString(ex)); + this.UnknownErrorProcessingEvent(handlerName, eventName, ex.ToInvariantString()); } } @@ -77,23 +75,4 @@ public void EnrichmentException(string eventName, string exception) this.WriteEvent(5, eventName, exception); } } - - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } } diff --git a/src/OpenTelemetry.Instrumentation.EntityFrameworkCore/OpenTelemetry.Instrumentation.EntityFrameworkCore.csproj b/src/OpenTelemetry.Instrumentation.EntityFrameworkCore/OpenTelemetry.Instrumentation.EntityFrameworkCore.csproj index 7cb47060c4..f4d574d930 100644 --- a/src/OpenTelemetry.Instrumentation.EntityFrameworkCore/OpenTelemetry.Instrumentation.EntityFrameworkCore.csproj +++ b/src/OpenTelemetry.Instrumentation.EntityFrameworkCore/OpenTelemetry.Instrumentation.EntityFrameworkCore.csproj @@ -1,10 +1,11 @@ - + netstandard2.0 Microsoft.EntityFrameworkCore instrumentation for OpenTelemetry .NET $(PackageTags);distributed-tracing Instrumentation.EntityFrameworkCore- true + true diff --git a/src/OpenTelemetry.Instrumentation.Owin/Implementation/OwinInstrumentationEventSource.cs b/src/OpenTelemetry.Instrumentation.Owin/Implementation/OwinInstrumentationEventSource.cs index ddcd595f10..be5229504e 100644 --- a/src/OpenTelemetry.Instrumentation.Owin/Implementation/OwinInstrumentationEventSource.cs +++ b/src/OpenTelemetry.Instrumentation.Owin/Implementation/OwinInstrumentationEventSource.cs @@ -16,8 +16,7 @@ using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; +using OpenTelemetry.Internal; namespace OpenTelemetry.Instrumentation.Owin; @@ -34,7 +33,7 @@ public void RequestFilterException(Exception ex) { if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1))) { - this.RequestFilterException(ToInvariantString(ex)); + this.RequestFilterException(ex.ToInvariantString()); } } @@ -55,7 +54,7 @@ public void EnrichmentException(Exception exception) { if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1))) { - this.EnrichmentException(ToInvariantString(exception)); + this.EnrichmentException(exception.ToInvariantString()); } } @@ -65,25 +64,6 @@ public void EnrichmentException(string exception) this.WriteEvent(EventIds.EnrichmentException, exception); } - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } - private class EventIds { public const int RequestIsFilteredOut = 1; diff --git a/src/OpenTelemetry.Instrumentation.Owin/OpenTelemetry.Instrumentation.Owin.csproj b/src/OpenTelemetry.Instrumentation.Owin/OpenTelemetry.Instrumentation.Owin.csproj index 65ebc2363d..de6e33c97f 100644 --- a/src/OpenTelemetry.Instrumentation.Owin/OpenTelemetry.Instrumentation.Owin.csproj +++ b/src/OpenTelemetry.Instrumentation.Owin/OpenTelemetry.Instrumentation.Owin.csproj @@ -1,6 +1,7 @@  $(NetFrameworkMinimumSupportedVersion) + true OpenTelemetry instrumentation for OWIN $(PackageTags);distributed-tracing;OWIN Instrumentation.Owin- @@ -8,7 +9,6 @@ - diff --git a/src/OpenTelemetry.Instrumentation.Quartz/OpenTelemetry.Instrumentation.Quartz.csproj b/src/OpenTelemetry.Instrumentation.Quartz/OpenTelemetry.Instrumentation.Quartz.csproj index 97e19a1f72..0b271ac9da 100644 --- a/src/OpenTelemetry.Instrumentation.Quartz/OpenTelemetry.Instrumentation.Quartz.csproj +++ b/src/OpenTelemetry.Instrumentation.Quartz/OpenTelemetry.Instrumentation.Quartz.csproj @@ -5,8 +5,7 @@ Instrumentation.Quartz- true netstandard2.0 - OpenTelemetry.Instrumentation.Quartz - OpenTelemetry.Instrumentation.Quartz + true diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/OpenTelemetry.Instrumentation.StackExchangeRedis.csproj b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/OpenTelemetry.Instrumentation.StackExchangeRedis.csproj index c12e750ae0..29b7e82417 100644 --- a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/OpenTelemetry.Instrumentation.StackExchangeRedis.csproj +++ b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/OpenTelemetry.Instrumentation.StackExchangeRedis.csproj @@ -5,6 +5,7 @@ StackExchange.Redis instrumentation for OpenTelemetry .NET $(PackageTags);distributed-tracing;Redis;StackExchange.Redis true + true Instrumentation.StackExchangeRedis- diff --git a/src/OpenTelemetry.Instrumentation.Wcf/Implementation/WcfInstrumentationEventSource.cs b/src/OpenTelemetry.Instrumentation.Wcf/Implementation/WcfInstrumentationEventSource.cs index fa73b497c1..bd23a2e9c6 100644 --- a/src/OpenTelemetry.Instrumentation.Wcf/Implementation/WcfInstrumentationEventSource.cs +++ b/src/OpenTelemetry.Instrumentation.Wcf/Implementation/WcfInstrumentationEventSource.cs @@ -16,8 +16,7 @@ using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; +using OpenTelemetry.Internal; namespace OpenTelemetry.Instrumentation.Wcf.Implementation; @@ -31,7 +30,7 @@ public void RequestFilterException(Exception ex) { if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1))) { - this.RequestFilterException(ToInvariantString(ex)); + this.RequestFilterException(ex.ToInvariantString()); } } @@ -52,7 +51,7 @@ public void EnrichmentException(Exception exception) { if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1))) { - this.EnrichmentException(ToInvariantString(exception)); + this.EnrichmentException(exception.ToInvariantString()); } } @@ -62,25 +61,6 @@ public void EnrichmentException(string exception) this.WriteEvent(EventIds.EnrichmentException, exception); } - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } - private class EventIds { public const int RequestIsFilteredOut = 1; diff --git a/src/OpenTelemetry.Instrumentation.Wcf/OpenTelemetry.Instrumentation.Wcf.csproj b/src/OpenTelemetry.Instrumentation.Wcf/OpenTelemetry.Instrumentation.Wcf.csproj index 922b8fd1a9..cc6da9eac8 100644 --- a/src/OpenTelemetry.Instrumentation.Wcf/OpenTelemetry.Instrumentation.Wcf.csproj +++ b/src/OpenTelemetry.Instrumentation.Wcf/OpenTelemetry.Instrumentation.Wcf.csproj @@ -3,6 +3,7 @@ netstandard2.0;net462 + true OpenTelemetry instrumentation for WCF $(PackageTags);distributed-tracing;WCF Instrumentation.Wcf- diff --git a/src/OpenTelemetry.PersistentStorage.Abstractions/OpenTelemetry.PersistentStorage.Abstractions.csproj b/src/OpenTelemetry.PersistentStorage.Abstractions/OpenTelemetry.PersistentStorage.Abstractions.csproj index 3c2fc65c5c..f23566e9bf 100644 --- a/src/OpenTelemetry.PersistentStorage.Abstractions/OpenTelemetry.PersistentStorage.Abstractions.csproj +++ b/src/OpenTelemetry.PersistentStorage.Abstractions/OpenTelemetry.PersistentStorage.Abstractions.csproj @@ -5,6 +5,7 @@ netstandard2.0 $(TargetFrameworks);net462 net6.0;$(TargetFrameworks) + true OpenTelemetry Persistent Storage Abstractions Extensions.PersistentStorage.Abstractions- $(NoWarn),1591 diff --git a/src/OpenTelemetry.PersistentStorage.Abstractions/PersistentStorageAbstractionsEventSource.cs b/src/OpenTelemetry.PersistentStorage.Abstractions/PersistentStorageAbstractionsEventSource.cs index 4c122d7217..7c0d1d2861 100644 --- a/src/OpenTelemetry.PersistentStorage.Abstractions/PersistentStorageAbstractionsEventSource.cs +++ b/src/OpenTelemetry.PersistentStorage.Abstractions/PersistentStorageAbstractionsEventSource.cs @@ -16,8 +16,7 @@ using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; +using OpenTelemetry.Internal; namespace OpenTelemetry.PersistentStorage.Abstractions; @@ -32,7 +31,7 @@ public void PersistentStorageAbstractionsException(string className, string mess { if (this.IsEnabled(EventLevel.Error, EventKeywords.All)) { - this.PersistentStorageAbstractionsException(className, message, ToInvariantString(ex)); + this.PersistentStorageAbstractionsException(className, message, ex.ToInvariantString()); } } @@ -41,23 +40,4 @@ public void PersistentStorageAbstractionsException(string className, string mess { this.WriteEvent(1, className, message, ex); } - - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } } diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/OpenTelemetry.PersistentStorage.FileSystem.csproj b/src/OpenTelemetry.PersistentStorage.FileSystem/OpenTelemetry.PersistentStorage.FileSystem.csproj index 9deb66221d..c3c1452e07 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/OpenTelemetry.PersistentStorage.FileSystem.csproj +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/OpenTelemetry.PersistentStorage.FileSystem.csproj @@ -5,6 +5,7 @@ netstandard2.0 $(TargetFrameworks);net462 net6.0;$(TargetFrameworks) + true OpenTelemetry Persistent Storage Extensions.PersistentStorage- diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageEventSource.cs b/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageEventSource.cs index 3192c453fa..8ba898fae6 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageEventSource.cs +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageEventSource.cs @@ -16,8 +16,7 @@ using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; +using OpenTelemetry.Internal; namespace OpenTelemetry.PersistentStorage.FileSystem; @@ -32,7 +31,7 @@ public void CouldNotReadFileBlob(string filePath, Exception ex) { if (this.IsEnabled(EventLevel.Informational, EventKeywords.All)) { - this.CouldNotReadFileBlob(filePath, ToInvariantString(ex)); + this.CouldNotReadFileBlob(filePath, ex.ToInvariantString()); } } @@ -41,7 +40,7 @@ public void CouldNotWriteFileBlob(string filePath, Exception ex) { if (this.IsEnabled(EventLevel.Informational, EventKeywords.All)) { - this.CouldNotWriteFileBlob(filePath, ToInvariantString(ex)); + this.CouldNotWriteFileBlob(filePath, ex.ToInvariantString()); } } @@ -50,7 +49,7 @@ public void CouldNotLeaseFileBlob(string filePath, Exception ex) { if (this.IsEnabled(EventLevel.Informational, EventKeywords.All)) { - this.CouldNotLeaseFileBlob(filePath, ToInvariantString(ex)); + this.CouldNotLeaseFileBlob(filePath, ex.ToInvariantString()); } } @@ -59,7 +58,7 @@ public void CouldNotDeleteFileBlob(string filePath, Exception ex) { if (this.IsEnabled(EventLevel.Informational, EventKeywords.All)) { - this.CouldNotDeleteFileBlob(filePath, ToInvariantString(ex)); + this.CouldNotDeleteFileBlob(filePath, ex.ToInvariantString()); } } @@ -68,7 +67,7 @@ public void CouldNotCreateFileBlob(Exception ex) { if (this.IsEnabled(EventLevel.Informational, EventKeywords.All)) { - this.CouldNotCreateFileBlob(ToInvariantString(ex)); + this.CouldNotCreateFileBlob(ex.ToInvariantString()); } } @@ -77,7 +76,7 @@ public void CouldNotRemoveExpiredBlob(string filePath, Exception ex) { if (this.IsEnabled(EventLevel.Warning, EventKeywords.All)) { - this.CouldNotRemoveExpiredBlob(filePath, ToInvariantString(ex)); + this.CouldNotRemoveExpiredBlob(filePath, ex.ToInvariantString()); } } @@ -86,7 +85,7 @@ public void CouldNotRemoveTimedOutTmpFile(string filePath, Exception ex) { if (this.IsEnabled(EventLevel.Warning, EventKeywords.All)) { - this.CouldNotRemoveTimedOutTmpFile(filePath, ToInvariantString(ex)); + this.CouldNotRemoveTimedOutTmpFile(filePath, ex.ToInvariantString()); } } @@ -95,7 +94,7 @@ public void CouldNotRemoveExpiredLease(string srcFilePath, string destFilePath, { if (this.IsEnabled(EventLevel.Warning, EventKeywords.All)) { - this.CouldNotRemoveExpiredLease(srcFilePath, destFilePath, ToInvariantString(ex)); + this.CouldNotRemoveExpiredLease(srcFilePath, destFilePath, ex.ToInvariantString()); } } @@ -104,7 +103,7 @@ public void PersistentStorageException(string className, string message, Excepti { if (this.IsEnabled(EventLevel.Error, EventKeywords.All)) { - this.PersistentStorageException(className, message, ToInvariantString(ex)); + this.PersistentStorageException(className, message, ex.ToInvariantString()); } } @@ -173,23 +172,4 @@ public void PersistentStorageInformation(string className, string message) { this.WriteEvent(11, className, message); } - - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } } diff --git a/src/OpenTelemetry.ResourceDetectors.Container/ContainerExtensionsEventSource.cs b/src/OpenTelemetry.ResourceDetectors.Container/ContainerExtensionsEventSource.cs index 6e2eda010b..7525df7c27 100644 --- a/src/OpenTelemetry.ResourceDetectors.Container/ContainerExtensionsEventSource.cs +++ b/src/OpenTelemetry.ResourceDetectors.Container/ContainerExtensionsEventSource.cs @@ -16,8 +16,7 @@ using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; +using OpenTelemetry.Internal; namespace OpenTelemetry.ResourceDetectors.Container; @@ -31,7 +30,7 @@ public void ExtractResourceAttributesException(string format, Exception ex) { if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1))) { - this.FailedToExtractResourceAttributes(format, ToInvariantString(ex)); + this.FailedToExtractResourceAttributes(format, ex.ToInvariantString()); } } @@ -40,23 +39,4 @@ public void FailedToExtractResourceAttributes(string format, string exception) { this.WriteEvent(1, format, exception); } - - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } } diff --git a/src/OpenTelemetry.ResourceDetectors.Container/OpenTelemetry.ResourceDetectors.Container.csproj b/src/OpenTelemetry.ResourceDetectors.Container/OpenTelemetry.ResourceDetectors.Container.csproj index da126da3d5..ff5eb95467 100644 --- a/src/OpenTelemetry.ResourceDetectors.Container/OpenTelemetry.ResourceDetectors.Container.csproj +++ b/src/OpenTelemetry.ResourceDetectors.Container/OpenTelemetry.ResourceDetectors.Container.csproj @@ -5,6 +5,7 @@ OpenTelemetry Extensions - Container Resource Detector from Container environment. ResourceDetectors.Container- enable + true diff --git a/src/OpenTelemetry.Sampler.AWS/AWSSamplerEventSource.cs b/src/OpenTelemetry.Sampler.AWS/AWSSamplerEventSource.cs index 702fe6886f..6e5e58143d 100644 --- a/src/OpenTelemetry.Sampler.AWS/AWSSamplerEventSource.cs +++ b/src/OpenTelemetry.Sampler.AWS/AWSSamplerEventSource.cs @@ -14,10 +14,7 @@ // limitations under the License. // -using System; using System.Diagnostics.Tracing; -using System.Globalization; -using System.Threading; namespace OpenTelemetry.Sampler.AWS; @@ -43,23 +40,4 @@ public void FailedToDeserializeResponse(string format, string error) { this.WriteEvent(3, format, error); } - - /// - /// Returns a culture-independent string representation of the given object, - /// appropriate for diagnostics tracing. - /// - private static string ToInvariantString(Exception exception) - { - var originalUICulture = Thread.CurrentThread.CurrentUICulture; - - try - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; - return exception.ToString(); - } - finally - { - Thread.CurrentThread.CurrentUICulture = originalUICulture; - } - } } diff --git a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/OpenTelemetry.Instrumentation.AWSLambda.Tests.csproj b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/OpenTelemetry.Instrumentation.AWSLambda.Tests.csproj index ecc88c9a31..681bd2ba2f 100644 --- a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/OpenTelemetry.Instrumentation.AWSLambda.Tests.csproj +++ b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/OpenTelemetry.Instrumentation.AWSLambda.Tests.csproj @@ -4,6 +4,7 @@ Unit test project of OpenTelemetry instrumentation for AWS Lambda netcoreapp3.1 true + true From bb8f923a4e934dd440fa70dfb21588b31cdd750f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 5 Apr 2023 22:21:06 +0200 Subject: [PATCH 09/16] Remove unused StatusHelper (#1128) --- build/Common.props | 1 - .../Api/StatusHelper.cs | 64 ------------------- ...Telemetry.Instrumentation.MySqlData.csproj | 1 - ...emetry.Instrumentation.AspNet.Tests.csproj | 1 - 4 files changed, 67 deletions(-) delete mode 100644 src/OpenTelemetry.Contrib.Shared/Api/StatusHelper.cs diff --git a/build/Common.props b/build/Common.props index 5e644908d3..78f7845324 100644 --- a/build/Common.props +++ b/build/Common.props @@ -69,7 +69,6 @@ - diff --git a/src/OpenTelemetry.Contrib.Shared/Api/StatusHelper.cs b/src/OpenTelemetry.Contrib.Shared/Api/StatusHelper.cs deleted file mode 100644 index 51f4b69163..0000000000 --- a/src/OpenTelemetry.Contrib.Shared/Api/StatusHelper.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#nullable enable - -using System; -using System.Runtime.CompilerServices; -using OpenTelemetry.Trace; - -namespace OpenTelemetry.Internal; - -internal static class StatusHelper -{ - public const string UnsetStatusCodeTagValue = "UNSET"; - public const string OkStatusCodeTagValue = "OK"; - public const string ErrorStatusCodeTagValue = "ERROR"; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static string? GetTagValueForStatusCode(StatusCode statusCode) - { - return statusCode switch - { - /* - * Note: Order here does matter for perf. Unset is - * first because assumption is most spans will be - * Unset, then Error. Ok is not set by the SDK. - */ - StatusCode.Unset => UnsetStatusCodeTagValue, - StatusCode.Error => ErrorStatusCodeTagValue, - StatusCode.Ok => OkStatusCodeTagValue, - _ => null, - }; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static StatusCode? GetStatusCodeForTagValue(string statusCodeTagValue) - { - return statusCodeTagValue switch - { - /* - * Note: Order here does matter for perf. Unset is - * first because assumption is most spans will be - * Unset, then Error. Ok is not set by the SDK. - */ - not null when UnsetStatusCodeTagValue.Equals(statusCodeTagValue, StringComparison.OrdinalIgnoreCase) => StatusCode.Unset, - not null when ErrorStatusCodeTagValue.Equals(statusCodeTagValue, StringComparison.OrdinalIgnoreCase) => StatusCode.Error, - not null when OkStatusCodeTagValue.Equals(statusCodeTagValue, StringComparison.OrdinalIgnoreCase) => StatusCode.Ok, - _ => (StatusCode?)null, - }; - } -} diff --git a/src/OpenTelemetry.Instrumentation.MySqlData/OpenTelemetry.Instrumentation.MySqlData.csproj b/src/OpenTelemetry.Instrumentation.MySqlData/OpenTelemetry.Instrumentation.MySqlData.csproj index f11c391fd3..5397712c47 100644 --- a/src/OpenTelemetry.Instrumentation.MySqlData/OpenTelemetry.Instrumentation.MySqlData.csproj +++ b/src/OpenTelemetry.Instrumentation.MySqlData/OpenTelemetry.Instrumentation.MySqlData.csproj @@ -16,7 +16,6 @@ - diff --git a/test/OpenTelemetry.Instrumentation.AspNet.Tests/OpenTelemetry.Instrumentation.AspNet.Tests.csproj b/test/OpenTelemetry.Instrumentation.AspNet.Tests/OpenTelemetry.Instrumentation.AspNet.Tests.csproj index 92750cb40e..5a1b585cda 100644 --- a/test/OpenTelemetry.Instrumentation.AspNet.Tests/OpenTelemetry.Instrumentation.AspNet.Tests.csproj +++ b/test/OpenTelemetry.Instrumentation.AspNet.Tests/OpenTelemetry.Instrumentation.AspNet.Tests.csproj @@ -26,7 +26,6 @@ - From 59640b6d555954bd2257be4982c93885ee2802cf Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 5 Apr 2023 13:55:59 -0700 Subject: [PATCH 10/16] Remove unused code (#1131) Co-authored-by: Utkarsh Umesan Pillai --- .../PersistentStorageHelper.cs | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageHelper.cs b/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageHelper.cs index 71584b491c..3ce0a062fa 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageHelper.cs +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageHelper.cs @@ -19,8 +19,6 @@ using System.IO; using System.Linq; using System.Runtime.CompilerServices; -using System.Security.Cryptography; -using System.Text; using System.Threading; namespace OpenTelemetry.PersistentStorage.FileSystem; @@ -190,29 +188,6 @@ internal static DateTime GetDateTimeFromLeaseName(string filePath) return dateTime.ToUniversalTime(); } - internal static string GetSHA256Hash(string input) - { - byte[] inputBits = Encoding.Unicode.GetBytes(input); - -#if NET6_0_OR_GREATER -#pragma warning disable CA1308 // Normalize strings to uppercase - return Convert.ToHexString(SHA256.HashData(inputBits)).ToLowerInvariant(); -#pragma warning restore CA1308 // Normalize strings to uppercase -#else - var hashString = new StringBuilder(); - using (var sha256 = SHA256.Create()) - { - byte[] hashBits = sha256.ComputeHash(inputBits); - foreach (byte b in hashBits) - { - hashString.Append(b.ToString("x2", CultureInfo.InvariantCulture)); - } - } - - return hashString.ToString(); -#endif - } - private static long CalculateFolderSize(string path) { if (!Directory.Exists(path)) From a50e1cdbbe869ab2204d100610067e9325a338b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 6 Apr 2023 06:22:35 +0200 Subject: [PATCH 11/16] [Instrumentation.Hangfire] drop default parameter from registration method (#1129) --- .../netstandard2.0/PublicAPI.Unshipped.txt | 3 ++- .../CHANGELOG.md | 2 ++ .../TracerProviderBuilderExtensions.cs | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Hangfire/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.Hangfire/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index f5f2649209..61a9676a20 100644 --- a/src/OpenTelemetry.Instrumentation.Hangfire/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.Hangfire/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -5,4 +5,5 @@ OpenTelemetry.Trace.HangfireInstrumentationOptions.HangfireInstrumentationOption OpenTelemetry.Trace.HangfireInstrumentationOptions.RecordException.get -> bool OpenTelemetry.Trace.HangfireInstrumentationOptions.RecordException.set -> void OpenTelemetry.Trace.TracerProviderBuilderExtensions -static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHangfireInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configureHangfireInstrumentationOptions = null) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHangfireInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder +static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddHangfireInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configure) -> OpenTelemetry.Trace.TracerProviderBuilder diff --git a/src/OpenTelemetry.Instrumentation.Hangfire/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Hangfire/CHANGELOG.md index e8caed7660..989674df6b 100644 --- a/src/OpenTelemetry.Instrumentation.Hangfire/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Hangfire/CHANGELOG.md @@ -4,6 +4,8 @@ * Update OTel API version to `1.4.0`. ([#1038](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1038)) +* Removes `AddHangfireInstrumentation` method with default configure default parameter. + ([#1129](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1129)) ## 1.0.0-beta.4 diff --git a/src/OpenTelemetry.Instrumentation.Hangfire/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Instrumentation.Hangfire/TracerProviderBuilderExtensions.cs index e1d3a9d2e7..551edf445a 100644 --- a/src/OpenTelemetry.Instrumentation.Hangfire/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Instrumentation.Hangfire/TracerProviderBuilderExtensions.cs @@ -29,16 +29,25 @@ public static class TracerProviderBuilderExtensions /// Adds Hangfire instrumentation to the tracer provider. /// /// being configured. - /// Callback action for configuring . + /// The instance of to chain the calls. + public static TracerProviderBuilder AddHangfireInstrumentation( + this TracerProviderBuilder builder) => + AddHangfireInstrumentation(builder, configure: null); + + /// + /// Adds Hangfire instrumentation to the tracer provider. + /// + /// being configured. + /// Callback action for configuring . /// The instance of to chain the calls. public static TracerProviderBuilder AddHangfireInstrumentation( this TracerProviderBuilder builder, - Action configureHangfireInstrumentationOptions = null) + Action configure) { Guard.ThrowIfNull(builder); var options = new HangfireInstrumentationOptions(); - configureHangfireInstrumentationOptions?.Invoke(options); + configure?.Invoke(options); Hangfire.GlobalJobFilters.Filters.Add(new HangfireInstrumentationJobFilterAttribute(options)); From c5b2adefa5f06d1908c23069b9f7dc3a4db0b2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 7 Apr 2023 06:56:38 +0200 Subject: [PATCH 12/16] [ResourceDetectors.Container] Release 1.0.0-beta.3 (#1132) --- src/OpenTelemetry.ResourceDetectors.Container/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OpenTelemetry.ResourceDetectors.Container/CHANGELOG.md b/src/OpenTelemetry.ResourceDetectors.Container/CHANGELOG.md index f3e5bf6ec8..09cff2b9b3 100644 --- a/src/OpenTelemetry.ResourceDetectors.Container/CHANGELOG.md +++ b/src/OpenTelemetry.ResourceDetectors.Container/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +## 1.0.0-beta.3 + +Released 2023-Apr-7 + * Going forward the NuGet package will be [`OpenTelemetry.ResourceDetectors.Container`](https://www.nuget.org/packages/OpenTelemetry.ResourceDetectors.Container). Older versions will remain at From 8d8be7004234e30d7dc07050bec94a64e24bbfd0 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai Date: Fri, 7 Apr 2023 01:14:06 -0700 Subject: [PATCH 13/16] [Exporter.Geneva][TldLogExporter] Update TldLogExporter to log eventId.Id as a PartB field (#1134) --- src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md | 4 ++++ .../TLDExporter/TldLogExporter.cs | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md index e66996a40a..47a2080158 100644 --- a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* TldLogExporter to export `eventId.Id` as a Part B field instead of Part C + field. + ([#1134](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1134)) + ## 1.5.0-alpha.2 Released 2023-Mar-29 diff --git a/src/OpenTelemetry.Exporter.Geneva/TLDExporter/TldLogExporter.cs b/src/OpenTelemetry.Exporter.Geneva/TLDExporter/TldLogExporter.cs index 415891a9c2..d4238b86f7 100644 --- a/src/OpenTelemetry.Exporter.Geneva/TLDExporter/TldLogExporter.cs +++ b/src/OpenTelemetry.Exporter.Geneva/TLDExporter/TldLogExporter.cs @@ -296,6 +296,13 @@ internal void SerializeLogRecord(LogRecord logRecord) eb.AddUInt8("severityNumber", GetSeverityNumber(logLevel)); eb.AddCountedAnsiString("name", categoryName, Encoding.UTF8); + var eventId = logRecord.EventId; + if (eventId != default) + { + eb.AddInt32("eventId", eventId.Id); + partBFieldsCount++; + } + byte hasEnvProperties = 0; bool bodyPopulated = false; @@ -395,13 +402,6 @@ internal void SerializeLogRecord(LogRecord logRecord) eb.AddCountedAnsiString("env_properties", serializedEnvPropertiesStringAsBytes, 0, count); } - var eventId = logRecord.EventId; - if (eventId != default) - { - eb.AddInt32("eventId", eventId.Id); - partCFieldsCount++; - } - eb.SetStructFieldCount(partCFieldsCountPatch, (byte)partCFieldsCount); } From 18ba3ba4985e3058cefd5a22e46295d901fa204a Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Fri, 7 Apr 2023 10:22:49 -0700 Subject: [PATCH 14/16] [Exporter.Geneva] Fix changelog (#1136) --- src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md index 47a2080158..3592898456 100644 --- a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md @@ -6,6 +6,14 @@ field. ([#1134](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1134)) +## 1.4.1 + +Released 2023-Mar-29 + +* Relaxed table name mapping validation rules to restore the previous behavior + from version 1.3.0. + ([#1120](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1120)) + ## 1.5.0-alpha.2 Released 2023-Mar-29 @@ -14,8 +22,8 @@ Released 2023-Mar-29 ([#1099](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1099)) * Relaxed table name mapping validation rules to restore the previous behavior - from version 1.3.0. ([Issue - #1105](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/1105)) + from version 1.3.0. + ([#1109](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1109)) * Add support for exporting metrics to more than a single account/namespace combination using a single GenevaMetricExporter instance. Users can now export From be07337e16cc34e18ad731d2782f8d6e735f6732 Mon Sep 17 00:00:00 2001 From: Timothy Mothra Date: Mon, 10 Apr 2023 23:01:29 -0700 Subject: [PATCH 15/16] [PersistentStorage.FileSystem] fix directory size bug (#1133) --- .../CHANGELOG.md | 5 +- .../DirectorySizeTracker.cs | 86 +++++++++++++++++++ .../FileBlob.cs | 12 ++- .../FileBlobProvider.cs | 14 +-- .../PersistentStorageHelper.cs | 59 +------------ .../DirectorySizeTrackerTests.cs | 60 +++++++++++++ .../FileBlobProviderTests.cs | 9 +- 7 files changed, 176 insertions(+), 69 deletions(-) create mode 100644 src/OpenTelemetry.PersistentStorage.FileSystem/DirectorySizeTracker.cs create mode 100644 test/OpenTelemetry.PersistentStorage.FileSystem.Tests/DirectorySizeTrackerTests.cs diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/CHANGELOG.md b/src/OpenTelemetry.PersistentStorage.FileSystem/CHANGELOG.md index 380611ae50..ec38a42e07 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/CHANGELOG.md +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/CHANGELOG.md @@ -2,8 +2,11 @@ ## 1.0.0-beta.2 (Unreleased) +* Fix a bug affecting the directory size when multiple `FileBlobProvider`s + were in a single process. [(#1133)](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1133) + * `FileBlobProvider` will now use the path provided during initialization as is -* for storing blobs, without adding additional hash of current user and process. + for storing blobs, without adding additional hash of current user and process. ([#1110](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1110)) * Going forward the NuGet package will be diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/DirectorySizeTracker.cs b/src/OpenTelemetry.PersistentStorage.FileSystem/DirectorySizeTracker.cs new file mode 100644 index 0000000000..7d942ec7e9 --- /dev/null +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/DirectorySizeTracker.cs @@ -0,0 +1,86 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.IO; +using System.Threading; + +namespace OpenTelemetry.PersistentStorage.FileSystem; + +/// +/// Tracks the available storage in a specified directory. +/// +internal class DirectorySizeTracker +{ + private readonly long maxSizeInBytes; + private readonly string path; + private long directoryCurrentSizeInBytes; + + public DirectorySizeTracker(long maxSizeInBytes, string path) + { + this.maxSizeInBytes = maxSizeInBytes; + this.path = path; + this.directoryCurrentSizeInBytes = CalculateFolderSize(path); + } + + public void FileAdded(long fileSizeInBytes) => Interlocked.Add(ref this.directoryCurrentSizeInBytes, fileSizeInBytes); + + public void FileRemoved(long fileSizeInBytes) => Interlocked.Add(ref this.directoryCurrentSizeInBytes, fileSizeInBytes * -1); + + public bool IsSpaceAvailable(out long currentSizeInBytes) + { + currentSizeInBytes = Interlocked.Read(ref this.directoryCurrentSizeInBytes); + return currentSizeInBytes < this.maxSizeInBytes; + } + + public void RecountCurrentSize() + { + var size = CalculateFolderSize(this.path); + Interlocked.Exchange(ref this.directoryCurrentSizeInBytes, size); + } + + internal static long CalculateFolderSize(string path) + { + if (!Directory.Exists(path)) + { + return 0; + } + + long directorySize = 0; + try + { + foreach (string file in Directory.EnumerateFiles(path)) + { + if (File.Exists(file)) + { + FileInfo fileInfo = new FileInfo(file); + directorySize += fileInfo.Length; + } + } + + foreach (string dir in Directory.GetDirectories(path)) + { + directorySize += CalculateFolderSize(dir); + } + } + catch (Exception ex) + { + PersistentStorageEventSource.Log.PersistentStorageException(nameof(PersistentStorageHelper), "Error calculating folder size", ex); + } + + return directorySize; + } +} diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlob.cs b/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlob.cs index 2b18bb87a4..b3e2258afc 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlob.cs +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlob.cs @@ -28,14 +28,22 @@ namespace OpenTelemetry.PersistentStorage.FileSystem; /// public class FileBlob : PersistentBlob { + private readonly DirectorySizeTracker? directorySizeTracker; + /// /// Initializes a new instance of the /// class. /// /// Absolute file path of the blob. public FileBlob(string fullPath) + : this(fullPath, null) + { + } + + internal FileBlob(string fullPath, DirectorySizeTracker? directorySizeTracker) { this.FullPath = fullPath; + this.directorySizeTracker = directorySizeTracker; } public string FullPath { get; private set; } @@ -80,6 +88,7 @@ protected override bool OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = return false; } + this.directorySizeTracker?.FileAdded(buffer.LongLength); return true; } @@ -113,7 +122,8 @@ protected override bool OnTryDelete() { try { - PersistentStorageHelper.RemoveFile(this.FullPath); + PersistentStorageHelper.RemoveFile(this.FullPath, out var fileSize); + this.directorySizeTracker?.FileRemoved(fileSize); } catch (Exception ex) { diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlobProvider.cs b/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlobProvider.cs index 188defef62..2b6d053aad 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlobProvider.cs +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlobProvider.cs @@ -32,7 +32,7 @@ namespace OpenTelemetry.PersistentStorage.FileSystem; public class FileBlobProvider : PersistentBlobProvider, IDisposable { internal readonly string DirectoryPath; - private readonly long maxSizeInBytes; + private readonly DirectorySizeTracker directorySizeTracker; private readonly long retentionPeriodInMilliseconds; private readonly int writeTimeoutInMilliseconds; private readonly Timer maintenanceTimer; @@ -94,7 +94,7 @@ public FileBlobProvider( // TODO: Validate time period values this.DirectoryPath = PersistentStorageHelper.CreateSubdirectory(path); - this.maxSizeInBytes = maxSizeInBytes; + this.directorySizeTracker = new DirectorySizeTracker(maxSizeInBytes, path); this.retentionPeriodInMilliseconds = retentionPeriodInMilliseconds; this.writeTimeoutInMilliseconds = writeTimeoutInMilliseconds; @@ -132,7 +132,7 @@ protected override IEnumerable OnGetBlobs() DateTime fileDateTime = PersistentStorageHelper.GetDateTimeFromBlobName(file); if (fileDateTime > retentionDeadline) { - yield return new FileBlob(file); + yield return new FileBlob(file, this.directorySizeTracker); } } } @@ -174,12 +174,14 @@ private void OnMaintenanceEvent(object? source, ElapsedEventArgs e) } PersistentStorageHelper.RemoveExpiredBlobs(this.DirectoryPath, this.retentionPeriodInMilliseconds, this.writeTimeoutInMilliseconds); + + // It is faster to calculate the directory size, instead of removing length of expired files. + this.directorySizeTracker.RecountCurrentSize(); } private bool CheckStorageSize() { - var size = PersistentStorageHelper.GetDirectorySize(); - if (size >= this.maxSizeInBytes) + if (!this.directorySizeTracker.IsSpaceAvailable(out long size)) { // TODO: check accuracy of size reporting. PersistentStorageEventSource.Log.PersistentStorageWarning( @@ -201,7 +203,7 @@ private bool CheckStorageSize() try { var blobFilePath = Path.Combine(this.DirectoryPath, PersistentStorageHelper.GetUniqueFileName(".blob")); - var blob = new FileBlob(blobFilePath); + var blob = new FileBlob(blobFilePath, this.directorySizeTracker); if (blob.TryWrite(buffer, leasePeriodMilliseconds)) { diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageHelper.cs b/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageHelper.cs index 3ce0a062fa..60d31fd4e7 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageHelper.cs +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/PersistentStorageHelper.cs @@ -19,14 +19,11 @@ using System.IO; using System.Linq; using System.Runtime.CompilerServices; -using System.Threading; namespace OpenTelemetry.PersistentStorage.FileSystem; internal static class PersistentStorageHelper { - private static long directorySize; - internal static void RemoveExpiredBlob(DateTime retentionDeadline, string filePath) { if (filePath.EndsWith(".blob", StringComparison.OrdinalIgnoreCase)) @@ -121,32 +118,20 @@ internal static void RemoveExpiredBlobs(string directoryPath, long retentionPeri RemoveExpiredBlob(retentionDeadline, file); } } - - // It is faster to calculate the directory size, instead of removing length of expired files. - var size = CalculateFolderSize(directoryPath); - Interlocked.Exchange(ref directorySize, size); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static long GetDirectorySize() - { - return Interlocked.Read(ref directorySize); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void WriteAllBytes(string path, byte[] buffer) { File.WriteAllBytes(path, buffer); - UpdateDirectorySize(buffer.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static void RemoveFile(string fileName) + internal static void RemoveFile(string fileName, out long fileSize) { var fileInfo = new FileInfo(fileName); - var fileSize = fileInfo.Length; + fileSize = fileInfo.Length; fileInfo.Delete(); - UpdateDirectorySize(fileSize * -1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -158,17 +143,9 @@ internal static string GetUniqueFileName(string extension) internal static string CreateSubdirectory(string path) { Directory.CreateDirectory(path); - - directorySize = CalculateFolderSize(path); return path; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static long UpdateDirectorySize(long fileContentLength) - { - return Interlocked.Add(ref directorySize, fileContentLength); - } - internal static DateTime GetDateTimeFromBlobName(string filePath) { var fileName = Path.GetFileNameWithoutExtension(filePath); @@ -187,36 +164,4 @@ internal static DateTime GetDateTimeFromLeaseName(string filePath) DateTime.TryParseExact(time, "yyyy-MM-ddTHHmmss.fffffffZ", CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateTime); return dateTime.ToUniversalTime(); } - - private static long CalculateFolderSize(string path) - { - if (!Directory.Exists(path)) - { - return 0; - } - - long directorySize = 0; - try - { - foreach (string file in Directory.EnumerateFiles(path)) - { - if (File.Exists(file)) - { - FileInfo fileInfo = new FileInfo(file); - directorySize += fileInfo.Length; - } - } - - foreach (string dir in Directory.GetDirectories(path)) - { - directorySize += CalculateFolderSize(dir); - } - } - catch (Exception ex) - { - PersistentStorageEventSource.Log.PersistentStorageException(nameof(PersistentStorageHelper), "Error calculating folder size", ex); - } - - return directorySize; - } } diff --git a/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/DirectorySizeTrackerTests.cs b/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/DirectorySizeTrackerTests.cs new file mode 100644 index 0000000000..d349e4107a --- /dev/null +++ b/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/DirectorySizeTrackerTests.cs @@ -0,0 +1,60 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System.IO; +using Xunit; + +namespace OpenTelemetry.PersistentStorage.FileSystem.Tests; + +public class DirectorySizeTrackerTests +{ + [Fact] + public void VerifyDirectorySizeTracker() + { + var testDirectory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); + testDirectory.Create(); + + var directorySizeTracker = new DirectorySizeTracker(maxSizeInBytes: 100, path: testDirectory.FullName); + + // new directory, expected to have space + Assert.True(directorySizeTracker.IsSpaceAvailable(out long currentSize1)); + Assert.Equal(0, currentSize1); + + // add a file and check current space. + directorySizeTracker.FileAdded(30); + Assert.True(directorySizeTracker.IsSpaceAvailable(out long currentSize2)); + Assert.Equal(30, currentSize2); + + // add a file and check current space. Here we've exceeded the configured max size + directorySizeTracker.FileAdded(100); + Assert.False(directorySizeTracker.IsSpaceAvailable(out long currentSize3)); + Assert.Equal(130, currentSize3); + + // remove a file and check current space. + directorySizeTracker.FileRemoved(50); + Assert.True(directorySizeTracker.IsSpaceAvailable(out long currentSize4)); + Assert.Equal(80, currentSize4); + + // since we haven't actually written any files to disk, + // Recount will reset to zero. + directorySizeTracker.RecountCurrentSize(); + Assert.True(directorySizeTracker.IsSpaceAvailable(out long currentSize5)); + Assert.Equal(0, currentSize5); + + // cleanup + testDirectory.Delete(); + } +} diff --git a/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobProviderTests.cs b/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobProviderTests.cs index f9aebd1dc4..036b321aa4 100644 --- a/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobProviderTests.cs +++ b/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobProviderTests.cs @@ -64,13 +64,14 @@ public void FileBlobProvider_E2E_Test() testDirectory.Delete(true); } - [Fact(Skip = "Unstable")] - public void FileBlobProvider_CreateBlobReturnsNullIfblobProviderIsFull() + [Fact] + public void FileBlobProvider_CreateBlobReturnsNullIfBlobProviderIsFull() { var testDirectory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); - using var blobProvider = new FileBlobProvider(testDirectory.FullName, 10000); + using var blobProvider = new FileBlobProvider(testDirectory.FullName, 100); - PersistentStorageHelper.UpdateDirectorySize(10000); + // write a file to fill up the configured max space. + Assert.True(blobProvider.TryCreateBlob(new byte[100], out _)); var data = Encoding.UTF8.GetBytes("Hello, World!"); From 59075730c47e12d2bee1a372a31a50e62f22b677 Mon Sep 17 00:00:00 2001 From: yan xu <58940428+xyq175com@users.noreply.github.com> Date: Tue, 11 Apr 2023 14:19:50 +0800 Subject: [PATCH 16/16] [Examples.AspNet] Update Prometheus exporter (#1107) Signed-off-by: Xu, Yan --- examples/AspNet/Examples.AspNet.csproj | 2 +- examples/AspNet/Global.asax.cs | 2 +- examples/AspNet/Views/Web.config | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/AspNet/Examples.AspNet.csproj b/examples/AspNet/Examples.AspNet.csproj index 0d181ef44c..d7d8ac9dc1 100644 --- a/examples/AspNet/Examples.AspNet.csproj +++ b/examples/AspNet/Examples.AspNet.csproj @@ -84,7 +84,7 @@ - + diff --git a/examples/AspNet/Global.asax.cs b/examples/AspNet/Global.asax.cs index db50f5bd43..8250029c0d 100644 --- a/examples/AspNet/Global.asax.cs +++ b/examples/AspNet/Global.asax.cs @@ -77,7 +77,7 @@ protected void Application_Start() }); break; case "prometheus": - meterBuilder.AddPrometheusExporter(); + meterBuilder.AddPrometheusHttpListener(); break; default: meterBuilder.AddConsoleExporter((exporterOptions, metricReaderOptions) => diff --git a/examples/AspNet/Views/Web.config b/examples/AspNet/Views/Web.config index 6e67a6c67f..b9508f1106 100644 --- a/examples/AspNet/Views/Web.config +++ b/examples/AspNet/Views/Web.config @@ -1,4 +1,4 @@ - + @@ -9,7 +9,7 @@ - + @@ -34,7 +34,7 @@ - +