diff --git a/.gitignore b/.gitignore index e7f0d44149b..439e441439e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,8 @@ *.user *.userosscache *.sln.docstates -.vscode/solution-explorer +.vscode/ +.devcontainer/ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/OpenTelemetry.sln b/OpenTelemetry.sln index ab19ea9e3e1..af0d31785ba 100644 --- a/OpenTelemetry.sln +++ b/OpenTelemetry.sln @@ -43,8 +43,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Zipk EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Api", "src\OpenTelemetry.Api\OpenTelemetry.Api.csproj", "{99F8A331-05E9-45A5-89BA-4C54E825E5B2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prometheus", "src\OpenTelemetry.Exporter.Prometheus\OpenTelemetry.Exporter.Prometheus.csproj", "{AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.AspNetCore", "src\OpenTelemetry.Instrumentation.AspNetCore\OpenTelemetry.Instrumentation.AspNetCore.csproj", "{752D2182-A351-41D8-99EE-DD363D7D5B43}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Instrumentation.AspNetCore.Tests", "test\OpenTelemetry.Instrumentation.AspNetCore.Tests\OpenTelemetry.Instrumentation.AspNetCore.Tests.csproj", "{2A47F6A8-63E5-4237-8046-94CAF321E797}" @@ -75,8 +73,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Ho EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.OpenTelemetryProtocol", "src\OpenTelemetry.Exporter.OpenTelemetryProtocol\OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj", "{A38AC295-2745-4B85-8B6B-DCA864CEDD5B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Prometheus.Tests", "test\OpenTelemetry.Exporter.Prometheus.Tests\OpenTelemetry.Exporter.Prometheus.Tests.csproj", "{393128EC-454D-45E8-A204-EC54904E5B3F}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.ZPages", "src\OpenTelemetry.Exporter.ZPages\OpenTelemetry.Exporter.ZPages.csproj", "{56A34828-621A-478B-A0B8-C065FE938383}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Console", "src\OpenTelemetry.Exporter.Console\OpenTelemetry.Exporter.Console.csproj", "{1AFFF251-3B0C-47CA-BE94-937083732C0A}" @@ -207,7 +203,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Shared", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp.AspNetCore.5.0", "test\TestApp.AspNetCore.5.0\TestApp.AspNetCore.5.0.csproj", "{972396A8-E35B-499C-9BA1-765E9B8822E1}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "exception-handling", "docs\trace\exception-handling\exception-handling.csproj", "{08D29501-F0A3-468F-B18D-BD1821A72383}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "exception-reporting", "docs\trace\exception-reporting\exception-reporting.csproj", "{08D29501-F0A3-468F-B18D-BD1821A72383}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "customizing-the-sdk", "docs\trace\customizing-the-sdk\customizing-the-sdk.csproj", "{64E3D8BB-93AB-4571-93F7-ED8D64DFFD06}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -231,10 +229,6 @@ Global {99F8A331-05E9-45A5-89BA-4C54E825E5B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {99F8A331-05E9-45A5-89BA-4C54E825E5B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {99F8A331-05E9-45A5-89BA-4C54E825E5B2}.Release|Any CPU.Build.0 = Release|Any CPU - {AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AD9B2B54-EC9C-448E-BD3C-EDCC3F7AD022}.Release|Any CPU.Build.0 = Release|Any CPU {752D2182-A351-41D8-99EE-DD363D7D5B43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {752D2182-A351-41D8-99EE-DD363D7D5B43}.Debug|Any CPU.Build.0 = Debug|Any CPU {752D2182-A351-41D8-99EE-DD363D7D5B43}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -283,10 +277,6 @@ Global {A38AC295-2745-4B85-8B6B-DCA864CEDD5B}.Debug|Any CPU.Build.0 = Debug|Any CPU {A38AC295-2745-4B85-8B6B-DCA864CEDD5B}.Release|Any CPU.ActiveCfg = Release|Any CPU {A38AC295-2745-4B85-8B6B-DCA864CEDD5B}.Release|Any CPU.Build.0 = Release|Any CPU - {393128EC-454D-45E8-A204-EC54904E5B3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {393128EC-454D-45E8-A204-EC54904E5B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {393128EC-454D-45E8-A204-EC54904E5B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {393128EC-454D-45E8-A204-EC54904E5B3F}.Release|Any CPU.Build.0 = Release|Any CPU {56A34828-621A-478B-A0B8-C065FE938383}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {56A34828-621A-478B-A0B8-C065FE938383}.Debug|Any CPU.Build.0 = Debug|Any CPU {56A34828-621A-478B-A0B8-C065FE938383}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -411,6 +401,10 @@ Global {08D29501-F0A3-468F-B18D-BD1821A72383}.Debug|Any CPU.Build.0 = Debug|Any CPU {08D29501-F0A3-468F-B18D-BD1821A72383}.Release|Any CPU.ActiveCfg = Release|Any CPU {08D29501-F0A3-468F-B18D-BD1821A72383}.Release|Any CPU.Build.0 = Release|Any CPU + {64E3D8BB-93AB-4571-93F7-ED8D64DFFD06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64E3D8BB-93AB-4571-93F7-ED8D64DFFD06}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64E3D8BB-93AB-4571-93F7-ED8D64DFFD06}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64E3D8BB-93AB-4571-93F7-ED8D64DFFD06}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -442,6 +436,7 @@ Global {13C10C9A-07E8-43EB-91F5-C2B116FBE0FC} = {3862190B-E2C5-418E-AFDC-DB281FB5C705} {972396A8-E35B-499C-9BA1-765E9B8822E1} = {77C7929A-2EED-4AA6-8705-B5C443C8AA0F} {08D29501-F0A3-468F-B18D-BD1821A72383} = {5B7FB835-3FFF-4BC2-99C5-A5B5FAE3C818} + {64E3D8BB-93AB-4571-93F7-ED8D64DFFD06} = {5B7FB835-3FFF-4BC2-99C5-A5B5FAE3C818} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {55639B5C-0770-4A22-AB56-859604650521} diff --git a/README.md b/README.md index 29378e69d52..cad33dac0d7 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,6 @@ libraries](https://github.com/open-telemetry/opentelemetry-specification/blob/ma * [Jaeger](./src/OpenTelemetry.Exporter.Jaeger/README.md) * [OTLP](./src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md) (OpenTelemetry Protocol) -* [Prometheus](./src/OpenTelemetry.Exporter.Prometheus/README.md) * [Zipkin](./src/OpenTelemetry.Exporter.Zipkin/README.md) See the [OpenTelemetry registry](https://opentelemetry.io/registry/?s=net) for @@ -114,6 +113,14 @@ Maintainers *Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer).* +Triager +([@open-telemetry/dotnet-triagers](https://github.com/orgs/open-telemetry/teams/dotnet-triagers)): + +* [Victor Lu](https://github.com/victlu), Microsoft + +*Find more about the triager role in [community +repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#triager).* + ### Thanks to all the people who have contributed [![contributors](https://contributors-img.web.app/image?repo=open-telemetry/opentelemetry-dotnet)](https://github.com/open-telemetry/opentelemetry-dotnet/graphs/contributors) diff --git a/build/Common.nonprod.props b/build/Common.nonprod.props index 58ff63eb96d..57593f6ca76 100644 --- a/build/Common.nonprod.props +++ b/build/Common.nonprod.props @@ -25,7 +25,7 @@ [0.12.1,0.13) [2.3.0,3.0) [2.3.1,3.0) - [3.13.0,4.0) + [3.15.5,4.0) [2.27.0,3.0) [2.30.0, 3.0) [2.25.0,3.0) diff --git a/build/Common.props b/build/Common.props index 2bc3c531f61..5c9505ed4e0 100644 --- a/build/Common.props +++ b/build/Common.props @@ -22,7 +22,7 @@ Refer to https://docs.microsoft.com/en-us/nuget/concepts/package-versioning for semver syntax. --> [2.3.0,3.0) - [3.6.1,4.0) + [3.15.5,4.0) [2.23.0,3.0) [2.32.0,3.0) [2.25.0,3.0) diff --git a/build/RELEASING.md b/build/RELEASING.md index 21884be37f3..2bb6eaa035a 100644 --- a/build/RELEASING.md +++ b/build/RELEASING.md @@ -18,7 +18,7 @@ Only for Maintainers. $ended = $false foreach ($line in $lines) { - if($line -like "## *" -and $started -ne $true) + if($line -like "## Unreleased" -and $started -ne $true) { $started = $true } @@ -121,3 +121,7 @@ and contents of combinedchangelog from Step2. TODO: Add tagging for Metrics release. TODO: Separate version for instrumention/hosting/OTshim package. + +16.Update the OpenTelemetry.io document +[here](https://github.com/open-telemetry/opentelemetry.io/tree/main/content/en/docs/net) +by sending a Pull Request. diff --git a/docs/Directory.Build.props b/docs/Directory.Build.props index 230f010de60..95ae4329f8e 100644 --- a/docs/Directory.Build.props +++ b/docs/Directory.Build.props @@ -4,7 +4,7 @@ Exe - netcoreapp2.1;netcoreapp3.1;net5.0 + netcoreapp3.1;net5.0 $(TargetFrameworks);net461;net462;net47;net471;net472;net48 diff --git a/docs/logs/extending-the-sdk/Program.cs b/docs/logs/extending-the-sdk/Program.cs index e47cb304ac2..4da7a2a87bb 100644 --- a/docs/logs/extending-the-sdk/Program.cs +++ b/docs/logs/extending-the-sdk/Program.cs @@ -15,9 +15,6 @@ // using System.Collections.Generic; -#if NETCOREAPP2_1 -using Microsoft.Extensions.DependencyInjection; -#endif using Microsoft.Extensions.Logging; using OpenTelemetry; using OpenTelemetry.Logs; @@ -26,11 +23,7 @@ public class Program { public static void Main() { -#if NETCOREAPP2_1 - var serviceCollection = new ServiceCollection().AddLogging(builder => -#else using var loggerFactory = LoggerFactory.Create(builder => -#endif builder.AddOpenTelemetry(options => { options.IncludeScopes = true; @@ -40,12 +33,7 @@ public static void Main() .AddMyExporter(); })); -#if NETCOREAPP2_1 - using var serviceProvider = serviceCollection.BuildServiceProvider(); - var logger = serviceProvider.GetRequiredService>(); -#else var logger = loggerFactory.CreateLogger(); -#endif // unstructured log logger.LogInformation("Hello, World!"); diff --git a/docs/logs/extending-the-sdk/extending-the-sdk.csproj b/docs/logs/extending-the-sdk/extending-the-sdk.csproj index aed90386e92..a5ae2beeec6 100644 --- a/docs/logs/extending-the-sdk/extending-the-sdk.csproj +++ b/docs/logs/extending-the-sdk/extending-the-sdk.csproj @@ -3,12 +3,7 @@ - - - - - - + diff --git a/docs/logs/getting-started/Program.cs b/docs/logs/getting-started/Program.cs index 57fc6616e27..e0eb8d41781 100644 --- a/docs/logs/getting-started/Program.cs +++ b/docs/logs/getting-started/Program.cs @@ -14,9 +14,6 @@ // limitations under the License. // -#if NETCOREAPP2_1 -using Microsoft.Extensions.DependencyInjection; -#endif using Microsoft.Extensions.Logging; using OpenTelemetry.Logs; @@ -24,23 +21,13 @@ public class Program { public static void Main() { -#if NETCOREAPP2_1 - var serviceCollection = new ServiceCollection().AddLogging(builder => -#else using var loggerFactory = LoggerFactory.Create(builder => -#endif { builder.AddOpenTelemetry(options => options .AddConsoleExporter()); }); -#if NETCOREAPP2_1 - using var serviceProvider = serviceCollection.BuildServiceProvider(); - var logger = serviceProvider.GetRequiredService>(); -#else var logger = loggerFactory.CreateLogger(); -#endif - logger.LogInformation("Hello from {name} {price}.", "tomato", 2.99); } } diff --git a/docs/logs/getting-started/README.md b/docs/logs/getting-started/README.md index 0b24a2b44a7..0f4f38f8250 100644 --- a/docs/logs/getting-started/README.md +++ b/docs/logs/getting-started/README.md @@ -17,21 +17,7 @@ You should see the following output: Hello World! ``` -Let's install the packages to get started with logging. If your ConsoleApp -targets `netcoreapp2.1` install the version `2.1.1` of -`Microsoft.Extensions.Logging` and `Microsoft.Extensions.DependencyInjection` -packages: - - ```sh - dotnet add package Microsoft.Extensions.Logging -v 2.1.1 - ``` - - ```sh - dotnet add package Microsoft.Extensions.DependencyInjection -v 2.1.1 - ``` - -If your ConsoleApp targets a framework other than `netcoreapp2.1`, install the -latest Microsoft.Extensions.Logging package: +Install the latest `Microsoft.Extensions.Logging` package: ```sh dotnet add package Microsoft.Extensions.Logging @@ -39,7 +25,7 @@ latest Microsoft.Extensions.Logging package: Install the [OpenTelemetry.Exporter.Console](../../../src/OpenTelemetry.Exporter.Console/README.md) -package (Use the latest version): +package: ```sh dotnet add package OpenTelemetry.Exporter.Console @@ -72,3 +58,8 @@ API to log a formatted string with a severity level of Information. Click for more information on the different logs levels. Opentelemetry captures this and sends it to `ConsoleExporter`. `ConsoleExporter` simply displays it on the console. + +## Learn more + +* If you want to build a custom exporter/processor/sampler, refer to [extending + the SDK](../extending-the-sdk/README.md). diff --git a/docs/logs/getting-started/getting-started.csproj b/docs/logs/getting-started/getting-started.csproj index 4db489c913b..93374308e63 100644 --- a/docs/logs/getting-started/getting-started.csproj +++ b/docs/logs/getting-started/getting-started.csproj @@ -3,12 +3,7 @@ - - - - - - + diff --git a/docs/metrics/getting-started.md b/docs/metrics/getting-started.md index 2b75972449b..bbe39c679b4 100644 --- a/docs/metrics/getting-started.md +++ b/docs/metrics/getting-started.md @@ -10,8 +10,3 @@ Please check the [Metric support plan](https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501). ## Sample usage - -Check -[TestPrometheusExporter.cs](../../examples/Console/TestPrometheusExporter.cs) -for an example usage of currently implemented Metrics API/SDK along with -Prometheus exporter. diff --git a/docs/trace/customizing-the-sdk/Program.cs b/docs/trace/customizing-the-sdk/Program.cs new file mode 100644 index 00000000000..de95d4088dc --- /dev/null +++ b/docs/trace/customizing-the-sdk/Program.cs @@ -0,0 +1,78 @@ +// +// 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.Diagnostics; +using OpenTelemetry; +using OpenTelemetry.Trace; + +public class Program +{ + private static readonly ActivitySource MyLibraryActivitySource = new ActivitySource( + "MyCompany.MyProduct.MyLibrary"); + + private static readonly ActivitySource ComponentAActivitySource = new ActivitySource( + "AbcCompany.XyzProduct.ComponentA"); + + private static readonly ActivitySource ComponentBActivitySource = new ActivitySource( + "AbcCompany.XyzProduct.ComponentB"); + + private static readonly ActivitySource SomeOtherActivitySource = new ActivitySource( + "SomeCompany.SomeProduct.SomeComponent"); + + public static void Main() + { + using var tracerProvider = Sdk.CreateTracerProviderBuilder() + + // The following adds subscription to activities from Activity Source + // named "MyCompany.MyProduct.MyLibrary" only. + .AddSource("MyCompany.MyProduct.MyLibrary") + + // The following adds subscription to activities from all Activity Sources + // whose name starts with "AbcCompany.XyzProduct.". + .AddSource("AbcCompany.XyzProduct.*") + .AddConsoleExporter() + .Build(); + + // This activity source is enabled. + using (var activity = MyLibraryActivitySource.StartActivity("SayHello")) + { + activity?.SetTag("foo", 1); + activity?.SetTag("bar", "Hello, World!"); + } + + // This activity source is enabled through wild card "AbcCompany.XyzProduct.*" + using (var activity = ComponentAActivitySource.StartActivity("SayHello")) + { + activity?.SetTag("foo", 1); + activity?.SetTag("bar", "Hello, World!"); + } + + // This activity source is enabled through wild card "AbcCompany.XyzProduct.*" + using (var activity = ComponentBActivitySource.StartActivity("SayHello")) + { + activity?.SetTag("foo", 1); + activity?.SetTag("bar", "Hello, World!"); + } + + // This activity source is not enabled, so activity will + // be null here. + using (var activity = SomeOtherActivitySource.StartActivity("SayHello")) + { + activity?.SetTag("foo", 1); + activity?.SetTag("bar", "Hello, World!"); + } + } +} diff --git a/docs/trace/customizing-the-sdk/README.md b/docs/trace/customizing-the-sdk/README.md new file mode 100644 index 00000000000..75807f8b421 --- /dev/null +++ b/docs/trace/customizing-the-sdk/README.md @@ -0,0 +1,118 @@ +# Customizing OpenTelemetry .NET SDK + +**This doc is work-in-progress.** + +## TracerProvider + +As shown in the [getting-started](../getting-started/README.md) doc, a valid +[`TracerProvider`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#tracer-provider) +must be configured and built to collect traces with OpenTelemetry .NET Sdk. +`TracerProvider` holds all the configuration for tracing like samplers, +processors, etc. Naturally, almost all the customizations must be done on the +`TracerProvider`. + +## Building a TracerProvider + +Building a `TracerProvider` is done using `TracerProviderBuilder` which must be +obtained by calling `Sdk.CreateTracerProviderBuilder()`. `TracerProviderBuilder` +exposes various methods which configures the provider it is going to build. These +includes methods like `SetSampler`, `AddProcessor` etc, and are explained in +subsequent sections of this document. Once configuration is done, calling +`Build()` on the `TracerProviderBuilder` builds the `TracerProvider` instance. +Once built, changes to its configuration is not allowed, with the exception of +adding more processors. In most cases, a single `TracerProvider` is created at +the application startup, and is disposed when application shuts down. + +The snippet below shows how to build a basic `TracerProvider`. This will create +a provider with default configuration, and is not particularly useful. The +subsequent sections shows how to build a more useful provider. + +```csharp +using OpenTelemetry; +using OpenTelemetry.Trace; + +using var tracerProvider = Sdk.CreateTracerProviderBuilder().Build(); +``` + +## TracerProvider configuration + +`TracerProvider` holds the tracing configuration, which includes the following: + +1. The list of `ActivitySource`s (aka Tracers) from which traces are collected. +2. The list of instrumentations enabled via + [InstrumentationLibrary](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#instrumentation-library). +3. The list of + [Processors](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#span-processor), + including exporting processors which exports traces to + [Exporters](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#span-exporter) +4. The + [Resource](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md) + associated with the traces. +5. The + [Sampler](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#sampler) + to be used. + +### Activity Source + +`ActivitySource` denotes a +[`Tracer`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#tracer), +which is used to start activities. The SDK follows an explicit opt-in model for +listening to activity sources. i.e, by default, it listens to no sources. Every +activity source which produce telemetry must be explicitly added to the tracer +provider to start collecting traces from them. + +`AddSource` method on `TracerProviderBuilder` can be used to add a +`ActivitySource` to the provider. The name of the `ActivitySource` +(case-insensitive) must be the argument to this method. Multiple `AddSource` can +be called to add more than one source. It also supports wild-card subscription +model as well. + +It is not possible to add sources *after* the provider is built, by calling the +`Build()` method on the `TracerProviderBuilder`. + +The snippet below shows how to add activity sources to the provider. + +```csharp +using OpenTelemetry; +using OpenTelemetry.Trace; + +using var tracerProvider = Sdk.CreateTracerProviderBuilder() + // The following subscribes to activities from Activity Source + // named "MyCompany.MyProduct.MyLibrary" only. + .AddSource("MyCompany.MyProduct.MyLibrary") + // The following subscribes to activities from all Activity Sources + // whose name starts with "AbcCompany.XyzProduct.". + .AddSource("AbcCompany.XyzProduct.*") + .Build(); +``` + +See [Program.cs](./Program.cs) for complete example. + +**Note** +A common mistake while configuring `TracerProvider` is forgetting to add +all `ActivitySources` to the provider. It is recommended to leverage the +wild card subscription model where it makes sense. For example, if your +application is expecting to enable tracing from a number of libraries +from a company "Abc", the you can use `AddSource("Abc.*")` to enable +all sources whose name starts with "Abc.". + +### Instrumentation + +// TODO + +### Processor + +// TODO + +### Resource + +// TODO + +### Sampler + +// TODO + +## Context Propagation + +// TODO: OpenTelemetry Sdk contents about Context. +// TODO: Links to built-in instrumentations doing Propagation. diff --git a/docs/trace/customizing-the-sdk/customizing-the-sdk.csproj b/docs/trace/customizing-the-sdk/customizing-the-sdk.csproj new file mode 100644 index 00000000000..2e58890af03 --- /dev/null +++ b/docs/trace/customizing-the-sdk/customizing-the-sdk.csproj @@ -0,0 +1,8 @@ + + + + + + diff --git a/docs/trace/exception-handling/Program.cs b/docs/trace/exception-reporting/Program.cs similarity index 100% rename from docs/trace/exception-handling/Program.cs rename to docs/trace/exception-reporting/Program.cs diff --git a/docs/trace/exception-handling/README.md b/docs/trace/exception-reporting/README.md similarity index 55% rename from docs/trace/exception-handling/README.md rename to docs/trace/exception-reporting/README.md index e4ea4ec844f..5e397910ed6 100644 --- a/docs/trace/exception-handling/README.md +++ b/docs/trace/exception-reporting/README.md @@ -1,9 +1,41 @@ -# Exception Handling +# Exception Reporting + +The following doc describes how to report Exceptions to OpenTelemetry tracing +when user is manually creating Activities. If the user is using one of the +[instrumentation +libraries](../extending-the-sdk/README.md#instrumentation-library), it may +provide these functionalities automatically. Please refer to the respective +documentation for guidance. ## User-handled Exception The term `User-handled Exception` is used to describe exceptions that are -handled by the application. +handled by the application, as shown in the below sample code. + +```csharp +try +{ + Func(); +} +catch (SomeException ex) +{ + DoSomething(); +} +catch (Exception ex) +{ + DoSomethingElse(); + throw; +} +``` + +OpenTelemetry .NET provides several options to report Exceptions in `Activity`. +It varies from the most basic option of setting `Status`, to fully recording the +`Exception` itself to activity. + +### Option 1 - Set Activity Status manually + +The most basic option is to set Activity status to Error to indicate that an +Exception has occurred. While using `Activity` API, the common pattern would be: @@ -19,7 +51,7 @@ using (var activity = MyActivitySource.StartActivity("Foo")) activity?.SetStatus(Status.Error); DoSomething(); } - catch (Exception) + catch (Exception ex) { activity?.SetStatus(Status.Error); throw; @@ -27,8 +59,11 @@ using (var activity = MyActivitySource.StartActivity("Foo")) } ``` -The above approach could become hard to manage if there are deeply nested -`Activity` objects, or there are activities created in a 3rd party library. +### Option 2 - Set Activity Status using SetErrorStatusOnException feature + +The approach described in Option 1 could become hard to manage if there are +deeply nested `Activity` objects, or there are activities created in a 3rd party +library. The following configuration will automatically detect exception and set the activity status to `Error`: @@ -44,6 +79,52 @@ A complete example can be found [here](./Program.cs). Note: this feature is platform dependent as it relies on [System.Runtime.InteropServices.Marshal.GetExceptionPointers](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshal.getexceptionpointers). +### Option 3 - Set Activity Status with Error description + +While convenient, the `SetErrorStatusOnException` feature only sets the activity +status to Error and nothing more. It is sometimes desirable to store the +exception message as the Status description. The following code shows how to do +that: + +```csharp +using (var activity = MyActivitySource.StartActivity("Foo")) +{ + try + { + Func(); + } + catch (SomeException ex) + { + activity?.SetStatus(Status.Error.WithDescription(ex.message)); + } +} +``` + +### Option 4 - Use Activity.RecordException + +Both options 1 and 2 above showed the most basic reporting of Exception, by +leveraging Activity status. Neither of the approach actually records the +Exception itself to do more richer debugging. `Activity.RecordException()` +allows the exception to be stored in the Activity as ActivityEvent as per +[OpenTelemetry +convention](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md), +as shown below: + +```csharp +using (var activity = MyActivitySource.StartActivity("Foo")) +{ + try + { + Func(); + } + catch (SomeException ex) + { + activity?.SetStatus(Status.Error.WithDescription(ex.message)); + activity?.RecordException(ex); + } +} +``` + ## Unhandled Exception The term `Unhandled Exception` is used to describe exceptions that are not diff --git a/docs/trace/exception-handling/exception-handling.csproj b/docs/trace/exception-reporting/exception-reporting.csproj similarity index 100% rename from docs/trace/exception-handling/exception-handling.csproj rename to docs/trace/exception-reporting/exception-reporting.csproj diff --git a/docs/trace/getting-started/README.md b/docs/trace/getting-started/README.md index 2374cb8dbbd..76db16f0a12 100644 --- a/docs/trace/getting-started/README.md +++ b/docs/trace/getting-started/README.md @@ -74,3 +74,10 @@ and respectively. Read [this](../../../src/OpenTelemetry.Api/README.md#introduction-to-opentelemetry-net-tracing-api) to learn more. + +## Learn more + +* If you want to customize the Sdk, refer to [customizing + the SDK](../customizing-the-sdk/README.md). +* If you want to build a custom exporter/processor/sampler, refer to [extending + the SDK](../extending-the-sdk/README.md). diff --git a/examples/AspNetCore/Startup.cs b/examples/AspNetCore/Startup.cs index 7a0e7876643..625c7c16615 100644 --- a/examples/AspNetCore/Startup.cs +++ b/examples/AspNetCore/Startup.cs @@ -23,7 +23,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; -using OpenTelemetry; +using OpenTelemetry.Exporter; +using OpenTelemetry.Instrumentation.AspNetCore; using OpenTelemetry.Resources; using OpenTelemetry.Trace; @@ -63,20 +64,17 @@ public void ConfigureServices(IServiceCollection services) .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(this.Configuration.GetValue("Jaeger:ServiceName"))) .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() - .AddJaegerExporter(jaegerOptions => - { - jaegerOptions.AgentHost = this.Configuration.GetValue("Jaeger:Host"); - jaegerOptions.AgentPort = this.Configuration.GetValue("Jaeger:Port"); - })); + .AddJaegerExporter()); + + services.Configure(this.Configuration.GetSection("Jaeger")); break; case "zipkin": services.AddOpenTelemetryTracing((builder) => builder .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() - .AddZipkinExporter(zipkinOptions => - { - zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue("Zipkin:Endpoint")); - })); + .AddZipkinExporter()); + + services.Configure(this.Configuration.GetSection("Zipkin")); break; case "otlp": // Adding the OtlpExporter creates a GrpcChannel. @@ -98,6 +96,19 @@ public void ConfigureServices(IServiceCollection services) .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddConsoleExporter()); + + // For options which can be bound from IConfiguration. + services.Configure(this.Configuration.GetSection("AspNetCoreInstrumentation")); + + // For options which can be configured from code only. + services.Configure(options => + { + options.Filter = (req) => + { + return req.Request.Host != null; + }; + }); + break; } } diff --git a/examples/AspNetCore/appsettings.json b/examples/AspNetCore/appsettings.json index fad736148cb..d9e5cf957cc 100644 --- a/examples/AspNetCore/appsettings.json +++ b/examples/AspNetCore/appsettings.json @@ -10,8 +10,8 @@ "UseExporter": "console", "Jaeger": { "ServiceName": "jaeger-test", - "Host": "localhost", - "Port": 6831 + "AgentHost": "localhost", + "AgentPort": 6831 }, "Zipkin": { "ServiceName": "zipkin-test", @@ -20,5 +20,8 @@ "Otlp": { "ServiceName": "otlp-test", "Endpoint": "http://localhost:4317" + }, + "AspNetCoreInstrumentation": { + "RecordException": "true" } } diff --git a/examples/Console/Examples.Console.csproj b/examples/Console/Examples.Console.csproj index a60c5e7dbef..33a1f6a4191 100644 --- a/examples/Console/Examples.Console.csproj +++ b/examples/Console/Examples.Console.csproj @@ -30,7 +30,6 @@ - diff --git a/examples/Console/Program.cs b/examples/Console/Program.cs index afea8ffcb16..342a8520761 100644 --- a/examples/Console/Program.cs +++ b/examples/Console/Program.cs @@ -45,7 +45,7 @@ public static void Main(string[] args) .MapResult( (JaegerOptions options) => TestJaegerExporter.Run(options.Host, options.Port), (ZipkinOptions options) => TestZipkinExporter.Run(options.Uri), - (PrometheusOptions options) => TestPrometheusExporter.RunAsync(options.Port, options.PushIntervalInSecs, options.DurationInMins), + (PrometheusOptions options) => TestPrometheusExporter.Run(options.Port, options.PushIntervalInSecs, options.DurationInMins), (GrpcNetClientOptions options) => TestGrpcNetClient.Run(), (HttpClientOptions options) => TestHttpClient.Run(), (RedisOptions options) => TestRedis.Run(options.Uri), diff --git a/examples/Console/TestPrometheusExporter.cs b/examples/Console/TestPrometheusExporter.cs index 51ddfee9a73..3b78c169098 100644 --- a/examples/Console/TestPrometheusExporter.cs +++ b/examples/Console/TestPrometheusExporter.cs @@ -19,16 +19,13 @@ using System.Diagnostics; using System.Threading.Tasks; using OpenTelemetry; -using OpenTelemetry.Exporter.Prometheus; -using OpenTelemetry.Metrics; -using OpenTelemetry.Metrics.Export; using OpenTelemetry.Trace; namespace Examples.Console { internal class TestPrometheusExporter { - internal static async Task RunAsync(int port, int pushIntervalInSecs, int totalDurationInMins) + internal static object Run(int port, int pushIntervalInSecs, int totalDurationInMins) { System.Console.WriteLine($"OpenTelemetry Prometheus Exporter is making metrics available at http://localhost:{port}/metrics/"); @@ -45,74 +42,8 @@ internal static async Task RunAsync(int port, int pushIntervalInSecs, in static_configs: - targets: ['localhost:9184'] */ - - // Create and Setup Prometheus Exporter - var promOptions = new PrometheusExporterOptions() { Url = $"http://localhost:{port}/metrics/" }; - var promExporter = new PrometheusExporter(promOptions); - var metricsHttpServer = new PrometheusExporterMetricsHttpServer(promExporter); - metricsHttpServer.Start(); - - // Create Processor (called Batcher in Metric spec, this is still not decided) - var processor = new UngroupedBatcher(); - - // Application which decides to enable OpenTelemetry metrics - // would setup a MeterProvider and make it default. - // All meters from this factory will be configured with the common processing pipeline. - MeterProvider.SetDefault(Sdk.CreateMeterProviderBuilder() - .SetProcessor(processor) - .SetExporter(promExporter) - .SetPushInterval(TimeSpan.FromSeconds(pushIntervalInSecs)) - .Build()); - - // The following shows how libraries would obtain a MeterProvider. - // MeterProvider is the entry point, which provides Meter. - // If user did not set the Default MeterProvider (shown in earlier lines), - // all metric operations become no-ops. - var meterProvider = MeterProvider.Default; - var meter = meterProvider.GetMeter("MyMeter"); - - // the rest is purely from Metrics API. - var testCounter = meter.CreateInt64Counter("MyCounter"); - var testMeasure = meter.CreateInt64Measure("MyMeasure"); - var testObserver = meter.CreateInt64Observer("MyObservation", CallBackForMyObservation); - var labels1 = new List>(); - labels1.Add(new KeyValuePair("dim1", "value1")); - - var labels2 = new List>(); - labels2.Add(new KeyValuePair("dim1", "value2")); - var defaultContext = default(SpanContext); - - Stopwatch sw = Stopwatch.StartNew(); - while (sw.Elapsed.TotalMinutes < totalDurationInMins) - { - testCounter.Add(defaultContext, 100, meter.GetLabelSet(labels1)); - - testMeasure.Record(defaultContext, 100, meter.GetLabelSet(labels1)); - testMeasure.Record(defaultContext, 500, meter.GetLabelSet(labels1)); - testMeasure.Record(defaultContext, 5, meter.GetLabelSet(labels1)); - testMeasure.Record(defaultContext, 750, meter.GetLabelSet(labels1)); - - // Obviously there is no testObserver.Oberve() here, as Observer instruments - // have callbacks that are called by the Meter automatically at each collection interval. - - await Task.Delay(1000); - var remaining = (totalDurationInMins * 60) - sw.Elapsed.TotalSeconds; - System.Console.WriteLine("Running and emitting metrics. Remaining time:" + (int)remaining + " seconds"); - } - - // Stopping - metricsHttpServer.Stop(); - System.Console.WriteLine("Metrics server shutdown."); System.Console.WriteLine("Press Enter key to exit."); return null; } - - internal static void CallBackForMyObservation(Int64ObserverMetric observerMetric) - { - var labels1 = new List>(); - labels1.Add(new KeyValuePair("dim1", "value1")); - - observerMetric.Observe(Process.GetCurrentProcess().WorkingSet64, labels1); - } } } diff --git a/src/OpenTelemetry.Api/.publicApi/net452/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Api/.publicApi/net452/PublicAPI.Unshipped.txt index e69de29bb2d..877fcaee8d0 100644 --- a/src/OpenTelemetry.Api/.publicApi/net452/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Api/.publicApi/net452/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +OpenTelemetry.Trace.TracerProviderBuilder.TracerProviderBuilder() -> void \ No newline at end of file diff --git a/src/OpenTelemetry.Api/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Api/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index e69de29bb2d..877fcaee8d0 100644 --- a/src/OpenTelemetry.Api/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Api/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +OpenTelemetry.Trace.TracerProviderBuilder.TracerProviderBuilder() -> void \ No newline at end of file diff --git a/src/OpenTelemetry.Api/CHANGELOG.md b/src/OpenTelemetry.Api/CHANGELOG.md index d1e1ac43b47..aff68e8de4f 100644 --- a/src/OpenTelemetry.Api/CHANGELOG.md +++ b/src/OpenTelemetry.Api/CHANGELOG.md @@ -7,8 +7,19 @@ branch](https://github.com/open-telemetry/opentelemetry-dotnet/tree/metrics), please check the latest changes [here](https://github.com/open-telemetry/opentelemetry-dotnet/blob/metrics/src/OpenTelemetry.Api/CHANGELOG.md#experimental---metrics). +* Removed existing Metrics code as the spec is completely being re-written. + ([#2030](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2030)) + ## Unreleased +## 1.1.0-beta2 + +Released 2021-Apr-23 + +* `BaggagePropagator` now uses `baggage` as the header name instead of `Baggage` + to `Extract` from and `Inject` to `carrier` + ([#2003](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2003)) + ## 1.1.0-beta1 Released 2021-Mar-19 diff --git a/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs b/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs index 30808f642d5..cfeb5387c93 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs @@ -28,7 +28,7 @@ namespace OpenTelemetry.Context.Propagation /// public class BaggagePropagator : TextMapPropagator { - internal const string BaggageHeaderName = "Baggage"; + internal const string BaggageHeaderName = "baggage"; private const int MaxBaggageLength = 8192; private const int MaxBaggageItems = 180; diff --git a/src/OpenTelemetry.Api/Metrics/BlankLabelSet.cs b/src/OpenTelemetry.Api/Metrics/BlankLabelSet.cs deleted file mode 100644 index 13a18031b15..00000000000 --- a/src/OpenTelemetry.Api/Metrics/BlankLabelSet.cs +++ /dev/null @@ -1,27 +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. -// - -using System; - -namespace OpenTelemetry.Metrics -{ - /// - /// Blank or No-op LabelSet. - /// - public sealed class BlankLabelSet : LabelSet - { - } -} diff --git a/src/OpenTelemetry.Api/Metrics/BoundCounterMetric.cs b/src/OpenTelemetry.Api/Metrics/BoundCounterMetric.cs deleted file mode 100644 index 5c62de07e91..00000000000 --- a/src/OpenTelemetry.Api/Metrics/BoundCounterMetric.cs +++ /dev/null @@ -1,44 +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. -// - -using System; -using OpenTelemetry.Trace; - -namespace OpenTelemetry.Metrics -{ - /// - /// Bound counter metric with the defined . - /// - /// The type of counter. Only long and double are supported now. - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public abstract class BoundCounterMetric - where T : struct - { - /// - /// Adds the given value to the bound counter metric. - /// - /// the associated . - /// value by which the bound counter metric should be added. - public abstract void Add(in SpanContext context, T value); - - /// - /// Adds the given value to the bound counter metric. - /// - /// the associated . - /// value by which the bound counter metric should be added. - public abstract void Add(in Baggage context, T value); - } -} diff --git a/src/OpenTelemetry.Api/Metrics/BoundMeasureMetric.cs b/src/OpenTelemetry.Api/Metrics/BoundMeasureMetric.cs deleted file mode 100644 index 69163a56267..00000000000 --- a/src/OpenTelemetry.Api/Metrics/BoundMeasureMetric.cs +++ /dev/null @@ -1,44 +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. -// - -using System; -using OpenTelemetry.Trace; - -namespace OpenTelemetry.Metrics -{ - /// - /// Bound measure metric with the defined . - /// - /// The type of Measure. Only long and double are supported now. - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public abstract class BoundMeasureMetric - where T : struct - { - /// - /// Record the given value to the bound measure metric. - /// - /// the associated . - /// the measurement to be recorded. - public abstract void Record(in SpanContext context, T value); - - /// - /// Record the given value to the bound measure metric. - /// - /// the associated . - /// the measurement to be recorded. - public abstract void Record(in Baggage context, T value); - } -} diff --git a/src/OpenTelemetry.Api/Metrics/CounterMetric.cs b/src/OpenTelemetry.Api/Metrics/CounterMetric.cs deleted file mode 100644 index 46ce9a703c3..00000000000 --- a/src/OpenTelemetry.Api/Metrics/CounterMetric.cs +++ /dev/null @@ -1,77 +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. -// - -using System; -using System.Collections.Generic; -using OpenTelemetry.Trace; - -namespace OpenTelemetry.Metrics -{ - /// - /// Counter instrument. - /// - /// The type of counter. Only long and double are supported now. - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public abstract class CounterMetric - where T : struct - { - /// - /// Adds or Increments the counter. - /// - /// the associated . - /// value by which the counter should be incremented. - /// The labelset associated with this value. - public abstract void Add(in SpanContext context, T value, LabelSet labelset); - - /// - /// Adds or Increments the counter. - /// - /// the associated . - /// value by which the counter should be incremented. - /// The labels or dimensions associated with this value. - public abstract void Add(in SpanContext context, T value, IEnumerable> labels); - - /// - /// Adds or Increments the counter. - /// - /// the associated . - /// value by which the counter should be incremented. - /// The labelset associated with this value. - public abstract void Add(in Baggage context, T value, LabelSet labelset); - - /// - /// Adds or Increments the counter. - /// - /// the associated . - /// value by which the counter should be incremented. - /// The labels or dimensions associated with this value. - public abstract void Add(in Baggage context, T value, IEnumerable> labels); - - /// - /// Gets the bound counter metric with given labelset. - /// - /// The labelset from which bound instrument should be constructed. - /// The bound counter metric. - public abstract BoundCounterMetric Bind(LabelSet labelset); - - /// - /// Gets the bound counter metric with given labels. - /// - /// The labels or dimensions associated with this value. - /// The bound counter metric. - public abstract BoundCounterMetric Bind(IEnumerable> labels); - } -} diff --git a/src/OpenTelemetry.Api/Metrics/DoubleObserverMetric.cs b/src/OpenTelemetry.Api/Metrics/DoubleObserverMetric.cs deleted file mode 100644 index bb75b9eeded..00000000000 --- a/src/OpenTelemetry.Api/Metrics/DoubleObserverMetric.cs +++ /dev/null @@ -1,42 +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. -// - -using System; -using System.Collections.Generic; - -namespace OpenTelemetry.Metrics -{ - /// - /// Observer instrument for Double values. - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public abstract class DoubleObserverMetric - { - /// - /// Observes a value. - /// - /// value to observe. - /// The labelset associated with this value. - public abstract void Observe(double value, LabelSet labelset); - - /// - /// Observes a value. - /// - /// value to observe. - /// The labels or dimensions associated with this value. - public abstract void Observe(double value, IEnumerable> labels); - } -} diff --git a/src/OpenTelemetry.Api/Metrics/DoubleObserverMetricHandle.cs b/src/OpenTelemetry.Api/Metrics/DoubleObserverMetricHandle.cs deleted file mode 100644 index ec214d4d646..00000000000 --- a/src/OpenTelemetry.Api/Metrics/DoubleObserverMetricHandle.cs +++ /dev/null @@ -1,33 +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. -// - -using System; - -namespace OpenTelemetry.Metrics -{ - /// - /// Handle to the metrics observer with the defined . - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public abstract class DoubleObserverMetricHandle - { - /// - /// Observes the given value. - /// - /// value by which the observer handle should be Recorded. - public abstract void Observe(double value); - } -} diff --git a/src/OpenTelemetry.Api/Metrics/Int64ObserverMetric.cs b/src/OpenTelemetry.Api/Metrics/Int64ObserverMetric.cs deleted file mode 100644 index 6f6c00f5d74..00000000000 --- a/src/OpenTelemetry.Api/Metrics/Int64ObserverMetric.cs +++ /dev/null @@ -1,42 +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. -// - -using System; -using System.Collections.Generic; - -namespace OpenTelemetry.Metrics -{ - /// - /// Observer instrument for Int64 values. - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public abstract class Int64ObserverMetric - { - /// - /// Observes a value. - /// - /// value to observe. - /// The labelset associated with this value. - public abstract void Observe(long value, LabelSet labelset); - - /// - /// Observes a value. - /// - /// value to observe. - /// The labels or dimensions associated with this value. - public abstract void Observe(long value, IEnumerable> labels); - } -} diff --git a/src/OpenTelemetry.Api/Metrics/Int64ObserverMetricHandle.cs b/src/OpenTelemetry.Api/Metrics/Int64ObserverMetricHandle.cs deleted file mode 100644 index 40e6ccb60b1..00000000000 --- a/src/OpenTelemetry.Api/Metrics/Int64ObserverMetricHandle.cs +++ /dev/null @@ -1,33 +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. -// - -using System; - -namespace OpenTelemetry.Metrics -{ - /// - /// Handle to the metrics observer with the defined . - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public abstract class Int64ObserverMetricHandle - { - /// - /// Observes the given value. - /// - /// value by which the observer handle should be Recorded. - public abstract void Observe(long value); - } -} diff --git a/src/OpenTelemetry.Api/Metrics/LabelSet.cs b/src/OpenTelemetry.Api/Metrics/LabelSet.cs deleted file mode 100644 index ea785a905f8..00000000000 --- a/src/OpenTelemetry.Api/Metrics/LabelSet.cs +++ /dev/null @@ -1,39 +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. -// - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenTelemetry.Metrics -{ - /// - /// Normalized name value pairs of metric labels. - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public abstract class LabelSet - { - /// - /// Empty LabelSet. - /// - public static readonly LabelSet BlankLabelSet = new BlankLabelSet(); - - /// - /// Gets or sets the labels after sorting and removing duplicates. - /// - public virtual IEnumerable> Labels { get; set; } = Enumerable.Empty>(); - } -} diff --git a/src/OpenTelemetry.Api/Metrics/MeasureMetric.cs b/src/OpenTelemetry.Api/Metrics/MeasureMetric.cs deleted file mode 100644 index a00245ac90f..00000000000 --- a/src/OpenTelemetry.Api/Metrics/MeasureMetric.cs +++ /dev/null @@ -1,77 +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. -// - -using System; -using System.Collections.Generic; -using OpenTelemetry.Trace; - -namespace OpenTelemetry.Metrics -{ - /// - /// Measure instrument. - /// - /// The type of measure. Only long and double are supported now. - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public abstract class MeasureMetric - where T : struct - { - /// - /// Records a measure. - /// - /// the associated . - /// value to record. - /// The labelset associated with this value. - public void Record(in SpanContext context, T value, LabelSet labelset) => this.Bind(labelset).Record(context, value); - - /// - /// Records a measure. - /// - /// the associated . - /// value to record. - /// The labels or dimensions associated with this value. - public void Record(in SpanContext context, T value, IEnumerable> labels) => this.Bind(labels).Record(context, value); - - /// - /// Records a measure. - /// - /// the associated . - /// value to record. - /// The labelset associated with this value. - public void Record(in Baggage context, T value, LabelSet labelset) => this.Bind(labelset).Record(context, value); - - /// - /// Records a measure. - /// - /// the associated . - /// value to record. - /// The labels or dimensions associated with this value. - public void Record(in Baggage context, T value, IEnumerable> labels) => this.Bind(labels).Record(context, value); - - /// - /// Gets the bound measure metric with given labelset. - /// - /// The labelset from which bound instrument should be constructed. - /// The bound measure metric. - public abstract BoundMeasureMetric Bind(LabelSet labelset); - - /// - /// Gets the bound measure metric with given labelset. - /// - /// The labels or dimensions associated with this value. - /// The bound measure metric. - public abstract BoundMeasureMetric Bind(IEnumerable> labels); - } -} diff --git a/src/OpenTelemetry.Api/Metrics/Meter.cs b/src/OpenTelemetry.Api/Metrics/Meter.cs deleted file mode 100644 index 9bac322408a..00000000000 --- a/src/OpenTelemetry.Api/Metrics/Meter.cs +++ /dev/null @@ -1,85 +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. -// - -using System; -using System.Collections.Generic; - -namespace OpenTelemetry.Metrics -{ - /// - /// Main interface to obtain metric instruments. - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public abstract class Meter - { - /// - /// Creates Int64 counter with given name. - /// - /// The name of the counter. - /// indicates if only positive values are expected. - /// The counter instance. - public abstract CounterMetric CreateInt64Counter(string name, bool monotonic = true); - - /// - /// Creates double counter with given name. - /// - /// The name of the counter. - /// indicates if only positive values are expected. - /// The counter instance. - public abstract CounterMetric CreateDoubleCounter(string name, bool monotonic = true); - - /// - /// Creates Int64 Measure with given name. - /// - /// The name of the measure. - /// indicates if only positive values are expected. - /// The measure instance. - public abstract MeasureMetric CreateInt64Measure(string name, bool absolute = true); - - /// - /// Creates double Measure with given name. - /// - /// The name of the measure. - /// indicates if only positive values are expected. - /// The measure instance. - public abstract MeasureMetric CreateDoubleMeasure(string name, bool absolute = true); - - /// - /// Creates Int64 Observer with given name. - /// - /// The name of the observer. - /// The callback to be called to observe metric value. - /// indicates if only positive values are expected. - /// The observer instance. - public abstract Int64ObserverMetric CreateInt64Observer(string name, Action callback, bool absolute = true); - - /// - /// Creates Double Observer with given name. - /// - /// The name of the observer. - /// The callback to be called to observe metric value. - /// indicates if only positive values are expected. - /// The observer instance. - public abstract DoubleObserverMetric CreateDoubleObserver(string name, Action callback, bool absolute = true); - - /// - /// Constructs or retrieves the from the given label key-value pairs. - /// - /// Label key-value pairs. - /// The with given label key value pairs. - public abstract LabelSet GetLabelSet(IEnumerable> labels); - } -} diff --git a/src/OpenTelemetry.Api/Metrics/MeterFactoryBase.cs b/src/OpenTelemetry.Api/Metrics/MeterFactoryBase.cs deleted file mode 100644 index 2967b747c90..00000000000 --- a/src/OpenTelemetry.Api/Metrics/MeterFactoryBase.cs +++ /dev/null @@ -1,87 +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. -// -using System; - -namespace OpenTelemetry.Metrics -{ - /// - /// Creates Meters for an instrumentation library. - /// Libraries should use this class as follows to obtain Meter instance. - /// MeterFactoryBase.Default.GetMeter("libraryname", "version"). - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public class MeterFactoryBase - { - private static ProxyMeter proxyMeter = new ProxyMeter(); - private static bool isInitialized; - private static MeterFactoryBase defaultFactory = new MeterFactoryBase(); - - /// - /// Gets the dafult instance of a . - /// - public static MeterFactoryBase Default - { - get => defaultFactory; - } - - /// - /// Sets the default instance of . - /// - /// Instance of . - /// - /// This method can only be called once. Calling it multiple times will throw an . - /// - /// Thrown when called multiple times. - public static void SetDefault(MeterFactoryBase meterFactory) - { - if (isInitialized) - { - throw new InvalidOperationException("Default factory is already set"); - } - - defaultFactory = meterFactory ?? throw new ArgumentNullException(nameof(meterFactory)); - - // some libraries might have already used and cached ProxyMeter. - // let's update it to real one and forward all calls. - - // resource assignment is not possible for libraries that cache tracer before SDK is initialized. - // SDK (Tracer) must be at least partially initialized before any collection starts to capture resources. - // we might be able to work this around with events. - proxyMeter.UpdateMeter(defaultFactory.GetMeter(null)); - - isInitialized = true; - } - - /// - /// Returns a Meter for a given name and version. - /// - /// Name of the instrumentation library. - /// Version of the instrumentation library (optional). - /// Meter for the given name and version information. - public virtual Meter GetMeter(string name, string version = null) - { - return isInitialized ? defaultFactory.GetMeter(name, version) : proxyMeter; - } - - // for tests - internal static void Reset() - { - proxyMeter = new ProxyMeter(); - isInitialized = false; - defaultFactory = new MeterFactoryBase(); - } - } -} diff --git a/src/OpenTelemetry.Api/Metrics/MeterProvider.cs b/src/OpenTelemetry.Api/Metrics/MeterProvider.cs deleted file mode 100644 index 402f35572b2..00000000000 --- a/src/OpenTelemetry.Api/Metrics/MeterProvider.cs +++ /dev/null @@ -1,94 +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. -// - -using System; - -namespace OpenTelemetry.Metrics -{ - /// - /// MeterProvider is the entry point of the OpenTelemetry Metrics API. It provides access to Meters. - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public class MeterProvider : BaseProvider - { - private static ProxyMeter proxyMeter = new ProxyMeter(); - private static bool isInitialized; - private static MeterProvider defaultProvider = new MeterProvider(); - - /// - /// Initializes a new instance of the class. - /// - protected MeterProvider() - { - } - - /// - /// Gets the dafult instance of a . - /// - public static MeterProvider Default - { - get => defaultProvider; - } - - /// - /// Sets the default instance of . - /// - /// Instance of . - /// - /// This method can only be called once. Calling it multiple times will throw an . - /// - /// Thrown when called multiple times. - public static void SetDefault(MeterProvider meterProvider) - { - if (isInitialized) - { - throw new InvalidOperationException("Default factory is already set"); - } - - defaultProvider = meterProvider ?? throw new ArgumentNullException(nameof(meterProvider)); - - // some libraries might have already used and cached ProxyMeter. - // let's update it to real one and forward all calls. - - // TODO: - // resource assignment is not possible for libraries that cache meter before SDK is initialized. - // SDK (Meter) must be at least partially initialized before any collection starts to capture resources. - // we might be able to work this around in future. - proxyMeter.UpdateMeter(defaultProvider.GetMeter(null)); - - isInitialized = true; - } - - /// - /// Returns a Meter for a given name and version. - /// - /// Name of the instrumentation library. - /// Version of the instrumentation library (optional). - /// Meter for the given name and version information. - public virtual Meter GetMeter(string name, string version = null) - { - return isInitialized ? defaultProvider.GetMeter(name, version) : proxyMeter; - } - - // for tests - internal static void Reset() - { - proxyMeter = new ProxyMeter(); - isInitialized = false; - defaultProvider = new MeterProvider(); - } - } -} diff --git a/src/OpenTelemetry.Api/Metrics/NoopBoundCounterMetric.cs b/src/OpenTelemetry.Api/Metrics/NoopBoundCounterMetric.cs deleted file mode 100644 index fb93e223d57..00000000000 --- a/src/OpenTelemetry.Api/Metrics/NoopBoundCounterMetric.cs +++ /dev/null @@ -1,45 +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. -// - -using System; -using OpenTelemetry.Trace; - -namespace OpenTelemetry.Metrics -{ - /// - /// No-Op bound counter metric. - /// - /// The type of counter. Only long and double are supported now. - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public sealed class NoopBoundCounterMetric : BoundCounterMetric - where T : struct - { - /// - /// No op counter bound instrument instance. - /// - public static readonly NoopBoundCounterMetric Instance = new NoopBoundCounterMetric(); - - /// - public override void Add(in SpanContext context, T value) - { - } - - /// - public override void Add(in Baggage context, T value) - { - } - } -} diff --git a/src/OpenTelemetry.Api/Metrics/NoopBoundMeasureMetric.cs b/src/OpenTelemetry.Api/Metrics/NoopBoundMeasureMetric.cs deleted file mode 100644 index ef73f02ec84..00000000000 --- a/src/OpenTelemetry.Api/Metrics/NoopBoundMeasureMetric.cs +++ /dev/null @@ -1,45 +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. -// - -using System; -using OpenTelemetry.Trace; - -namespace OpenTelemetry.Metrics -{ - /// - /// No op measure handle. - /// - /// The type of Measure. Only long and double are supported now. - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public sealed class NoopBoundMeasureMetric : BoundMeasureMetric - where T : struct - { - /// - /// No op measure bound instrument instance. - /// - public static readonly NoopBoundMeasureMetric Instance = new NoopBoundMeasureMetric(); - - /// - public override void Record(in SpanContext context, T value) - { - } - - /// - public override void Record(in Baggage context, T value) - { - } - } -} diff --git a/src/OpenTelemetry.Api/Metrics/NoopCounterMetric.cs b/src/OpenTelemetry.Api/Metrics/NoopCounterMetric.cs deleted file mode 100644 index b1c028d9f78..00000000000 --- a/src/OpenTelemetry.Api/Metrics/NoopCounterMetric.cs +++ /dev/null @@ -1,68 +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. -// - -using System; -using System.Collections.Generic; -using OpenTelemetry.Trace; - -namespace OpenTelemetry.Metrics -{ - /// - /// A no-op counter instrument. - /// - /// The type of counter. Only long and double are supported now. - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public sealed class NoopCounterMetric : CounterMetric - where T : struct - { - /// - /// No op counter instance. - /// - public static readonly NoopCounterMetric Instance = new NoopCounterMetric(); - - /// - public override void Add(in SpanContext context, T value, LabelSet labelset) - { - } - - /// - public override void Add(in SpanContext context, T value, IEnumerable> labels) - { - } - - /// - public override void Add(in Baggage context, T value, LabelSet labelset) - { - } - - /// - public override void Add(in Baggage context, T value, IEnumerable> labels) - { - } - - /// - public override BoundCounterMetric Bind(LabelSet labelset) - { - return NoopBoundCounterMetric.Instance; - } - - /// - public override BoundCounterMetric Bind(IEnumerable> labels) - { - return NoopBoundCounterMetric.Instance; - } - } -} diff --git a/src/OpenTelemetry.Api/Metrics/NoopDoubleObserverMetric.cs b/src/OpenTelemetry.Api/Metrics/NoopDoubleObserverMetric.cs deleted file mode 100644 index c77b89b1443..00000000000 --- a/src/OpenTelemetry.Api/Metrics/NoopDoubleObserverMetric.cs +++ /dev/null @@ -1,43 +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. -// - -using System; -using System.Collections.Generic; - -namespace OpenTelemetry.Metrics -{ - /// - /// A no-op observer instrument. - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public sealed class NoopDoubleObserverMetric : DoubleObserverMetric - { - /// - /// No op observer instance. - /// - public static readonly NoopDoubleObserverMetric Instance = new NoopDoubleObserverMetric(); - - /// - public override void Observe(double value, LabelSet labelset) - { - } - - /// - public override void Observe(double value, IEnumerable> labels) - { - } - } -} diff --git a/src/OpenTelemetry.Api/Metrics/NoopDoubleObserverMetricHandle.cs b/src/OpenTelemetry.Api/Metrics/NoopDoubleObserverMetricHandle.cs deleted file mode 100644 index e049d5e87f6..00000000000 --- a/src/OpenTelemetry.Api/Metrics/NoopDoubleObserverMetricHandle.cs +++ /dev/null @@ -1,37 +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. -// - -using System; - -namespace OpenTelemetry.Metrics -{ - /// - /// No-Op observer handle. - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public sealed class NoopDoubleObserverMetricHandle : DoubleObserverMetricHandle - { - /// - /// No op observer handle instance. - /// - public static readonly NoopDoubleObserverMetricHandle Instance = new NoopDoubleObserverMetricHandle(); - - /// - public override void Observe(double value) - { - } - } -} diff --git a/src/OpenTelemetry.Api/Metrics/NoopInt64ObserverMetric.cs b/src/OpenTelemetry.Api/Metrics/NoopInt64ObserverMetric.cs deleted file mode 100644 index 771ce2c36c3..00000000000 --- a/src/OpenTelemetry.Api/Metrics/NoopInt64ObserverMetric.cs +++ /dev/null @@ -1,43 +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. -// - -using System; -using System.Collections.Generic; - -namespace OpenTelemetry.Metrics -{ - /// - /// A no-op observer instrument. - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public sealed class NoopInt64ObserverMetric : Int64ObserverMetric - { - /// - /// No op observer instance. - /// - public static readonly Int64ObserverMetric Instance = new NoopInt64ObserverMetric(); - - /// - public override void Observe(long value, LabelSet labelset) - { - } - - /// - public override void Observe(long value, IEnumerable> labels) - { - } - } -} diff --git a/src/OpenTelemetry.Api/Metrics/NoopInt64ObserverMetricHandle.cs b/src/OpenTelemetry.Api/Metrics/NoopInt64ObserverMetricHandle.cs deleted file mode 100644 index db779d45262..00000000000 --- a/src/OpenTelemetry.Api/Metrics/NoopInt64ObserverMetricHandle.cs +++ /dev/null @@ -1,37 +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. -// - -using System; - -namespace OpenTelemetry.Metrics -{ - /// - /// No-Op observer handle. - /// - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public sealed class NoopInt64ObserverMetricHandle : Int64ObserverMetricHandle - { - /// - /// No op observer handle instance. - /// - public static readonly NoopInt64ObserverMetricHandle Instance = new NoopInt64ObserverMetricHandle(); - - /// - public override void Observe(long value) - { - } - } -} diff --git a/src/OpenTelemetry.Api/Metrics/NoopMeasureMetric.cs b/src/OpenTelemetry.Api/Metrics/NoopMeasureMetric.cs deleted file mode 100644 index 9cd6f2deb6d..00000000000 --- a/src/OpenTelemetry.Api/Metrics/NoopMeasureMetric.cs +++ /dev/null @@ -1,47 +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. -// - -using System; -using System.Collections.Generic; - -namespace OpenTelemetry.Metrics -{ - /// - /// No op measure instrument. - /// - /// The type of counter. Only long and double are supported now. - [Obsolete("Metrics API/SDK is not recommended for production. See https://github.com/open-telemetry/opentelemetry-dotnet/issues/1501 for more information on metrics support.")] - public sealed class NoopMeasureMetric : MeasureMetric - where T : struct - { - /// - /// No op measure instance. - /// - public static readonly NoopMeasureMetric Instance = new NoopMeasureMetric(); - - /// - public override BoundMeasureMetric Bind(LabelSet labelset) - { - return NoopBoundMeasureMetric.Instance; - } - - /// - public override BoundMeasureMetric Bind(IEnumerable> labels) - { - return NoopBoundMeasureMetric.Instance; - } - } -} diff --git a/src/OpenTelemetry.Api/Metrics/ProxyMeter.cs b/src/OpenTelemetry.Api/Metrics/ProxyMeter.cs deleted file mode 100644 index a21a98efcb3..00000000000 --- a/src/OpenTelemetry.Api/Metrics/ProxyMeter.cs +++ /dev/null @@ -1,80 +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. -// -using System; -using System.Collections.Generic; -using System.Threading; - -namespace OpenTelemetry.Metrics -{ - /// - /// Proxy Meter which act as a No-Op Meter, until real meter is provided. - /// - internal sealed class ProxyMeter : Meter - { - private Meter realMeter; - - public ProxyMeter() - { - } - - public override CounterMetric CreateDoubleCounter(string name, bool monotonic = true) - { - return this.realMeter != null ? this.realMeter.CreateDoubleCounter(name, monotonic) : NoopCounterMetric.Instance; - } - - public override MeasureMetric CreateDoubleMeasure(string name, bool absolute = true) - { - return this.realMeter != null ? this.realMeter.CreateDoubleMeasure(name, absolute) : NoopMeasureMetric.Instance; - } - - public override DoubleObserverMetric CreateDoubleObserver(string name, Action callback, bool absolute = true) - { - return this.realMeter != null ? this.realMeter.CreateDoubleObserver(name, callback, absolute) : NoopDoubleObserverMetric.Instance; - } - - public override CounterMetric CreateInt64Counter(string name, bool monotonic = true) - { - return this.realMeter != null ? this.realMeter.CreateInt64Counter(name, monotonic) : NoopCounterMetric.Instance; - } - - public override MeasureMetric CreateInt64Measure(string name, bool absolute = true) - { - return this.realMeter != null ? this.realMeter.CreateInt64Measure(name, absolute) : NoopMeasureMetric.Instance; - } - - public override Int64ObserverMetric CreateInt64Observer(string name, Action callback, bool absolute = true) - { - return this.realMeter != null ? this.realMeter.CreateInt64Observer(name, callback, absolute) : NoopInt64ObserverMetric.Instance; - } - - public override LabelSet GetLabelSet(IEnumerable> labels) - { - // return no op - return this.realMeter != null ? this.realMeter.GetLabelSet(labels) : LabelSet.BlankLabelSet; - } - - public void UpdateMeter(Meter realMeter) - { - if (this.realMeter != null) - { - return; - } - - // just in case user calls init concurrently - Interlocked.CompareExchange(ref this.realMeter, realMeter, null); - } - } -} diff --git a/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj b/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj index 861c6490d93..1df6ca2d4cf 100644 --- a/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj +++ b/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj @@ -1,6 +1,6 @@  - net452;netstandard2.0 + netstandard2.0;net452 OpenTelemetry .NET API OpenTelemetry @@ -13,4 +13,8 @@ + + + + diff --git a/src/OpenTelemetry.Api/README.md b/src/OpenTelemetry.Api/README.md index c960945539c..5d53ae4cb46 100644 --- a/src/OpenTelemetry.Api/README.md +++ b/src/OpenTelemetry.Api/README.md @@ -419,7 +419,7 @@ As mentioned in the introduction section, using OpenTelemetry.API Shim is only recommended if you want to use OpenTelemetry terminology like Tracer, Span instead of ActivitySource, Activity. -Follow [this](../../examples/console/TestOTelShimWithConsoleExporter.cs) code +Follow [this](../../examples/Console/TestOTelShimWithConsoleExporter.cs) code for example usage of this shim. ## Context propagation diff --git a/src/OpenTelemetry.Api/Trace/TracerProviderBuilder.cs b/src/OpenTelemetry.Api/Trace/TracerProviderBuilder.cs index 5dfcaa7ca39..dc8e0d57efb 100644 --- a/src/OpenTelemetry.Api/Trace/TracerProviderBuilder.cs +++ b/src/OpenTelemetry.Api/Trace/TracerProviderBuilder.cs @@ -22,12 +22,15 @@ namespace OpenTelemetry.Trace /// public abstract class TracerProviderBuilder { - internal TracerProviderBuilder() + /// + /// Initializes a new instance of the class. + /// + protected TracerProviderBuilder() { } /// - /// Adds an instrumentation to the provider. + /// Adds instrumentation to the provider. /// /// Type of instrumentation class. /// Function that builds instrumentation. diff --git a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md index adc7fd9c748..dd41d1dfce7 100644 --- a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md @@ -9,6 +9,10 @@ please check the latest changes ## Unreleased +## 1.1.0-beta2 + +Released 2021-Apr-23 + ## 1.1.0-beta1 Released 2021-Mar-19 diff --git a/src/OpenTelemetry.Exporter.Console/OpenTelemetry.Exporter.Console.csproj b/src/OpenTelemetry.Exporter.Console/OpenTelemetry.Exporter.Console.csproj index ae2f851a449..3ae301c8d73 100644 --- a/src/OpenTelemetry.Exporter.Console/OpenTelemetry.Exporter.Console.csproj +++ b/src/OpenTelemetry.Exporter.Console/OpenTelemetry.Exporter.Console.csproj @@ -1,7 +1,7 @@  - net452;net461;netstandard2.0 + netstandard2.0;net452;net461 Console exporter for OpenTelemetry .NET $(PackageTags);Console;distributed-tracing core- diff --git a/src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md b/src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md index c239bde5fe6..7e691e878a2 100644 --- a/src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md @@ -9,6 +9,10 @@ please check the latest changes ## Unreleased +## 1.1.0-beta2 + +Released 2021-Apr-23 + ## 1.1.0-beta1 Released 2021-Mar-19 diff --git a/src/OpenTelemetry.Exporter.InMemory/OpenTelemetry.Exporter.InMemory.csproj b/src/OpenTelemetry.Exporter.InMemory/OpenTelemetry.Exporter.InMemory.csproj index 9958b6530c3..896a0108ed8 100644 --- a/src/OpenTelemetry.Exporter.InMemory/OpenTelemetry.Exporter.InMemory.csproj +++ b/src/OpenTelemetry.Exporter.InMemory/OpenTelemetry.Exporter.InMemory.csproj @@ -1,7 +1,7 @@ - net452;net46;net461;netstandard2.0 + netstandard2.0;net452;net46;net461 In-memory exporter for OpenTelemetry .NET $(PackageTags) core- diff --git a/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md b/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md index 57062584dd3..9732234ee14 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md @@ -2,6 +2,18 @@ ## Unreleased +## 1.1.0-beta2 + +Released 2021-Apr-23 + +* When using OpenTelemetry.Extensions.Hosting you can now bind + `JaegerExporterOptions` to `IConfiguration` using the `Configure` extension + (ex: + `services.Configure(this.Configuration.GetSection("Jaeger"));`). + ([#1889](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1889)) +* Fixed data corruption when creating Jaeger Batch messages + ([#1372](https://github.com/open-telemetry/opentelemetry-dotnet/issues/1372)) + ## 1.1.0-beta1 Released 2021-Mar-19 diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index c30d9276824..5d2a888c8ac 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -158,6 +158,13 @@ internal void AppendSpan(JaegerSpan jaegerSpan) if (this.batchByteSize + spanTotalBytesNeeded >= this.maxPayloadSizeInBytes) { this.SendCurrentBatch(); + + // SendCurrentBatch clears/invalidates the BufferWriter in InMemoryTransport. + // The new spanMessage is still located in it, though. It might get overwritten later + // when spans are written in the buffer for the next batch. + // Move spanMessage to the beginning of the BufferWriter to avoid data corruption. + this.memoryTransport.Write(spanMessage.BufferWriter.Buffer, spanMessage.Offset, spanMessage.Count); + spanMessage = this.memoryTransport.ToBuffer(); } this.Batch.Add(spanMessage); diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs index bcea406491d..827b35047b7 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterHelperExtensions.cs @@ -38,11 +38,24 @@ public static TracerProviderBuilder AddJaegerExporter(this TracerProviderBuilder throw new ArgumentNullException(nameof(builder)); } - var exporterOptions = new JaegerExporterOptions(); - configure?.Invoke(exporterOptions); - var jaegerExporter = new JaegerExporter(exporterOptions); + if (builder is IDeferredTracerProviderBuilder deferredTracerProviderBuilder) + { + return deferredTracerProviderBuilder.Configure((sp, builder) => + { + AddJaegerExporter(builder, sp.GetOptions(), configure); + }); + } + + return AddJaegerExporter(builder, new JaegerExporterOptions(), configure); + } + + private static TracerProviderBuilder AddJaegerExporter(TracerProviderBuilder builder, JaegerExporterOptions options, Action configure = null) + { + configure?.Invoke(options); + + var jaegerExporter = new JaegerExporter(options); - if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple) + if (options.ExportProcessorType == ExportProcessorType.Simple) { return builder.AddProcessor(new SimpleActivityExportProcessor(jaegerExporter)); } @@ -50,10 +63,10 @@ public static TracerProviderBuilder AddJaegerExporter(this TracerProviderBuilder { return builder.AddProcessor(new BatchActivityExportProcessor( jaegerExporter, - exporterOptions.BatchExportProcessorOptions.MaxQueueSize, - exporterOptions.BatchExportProcessorOptions.ScheduledDelayMilliseconds, - exporterOptions.BatchExportProcessorOptions.ExporterTimeoutMilliseconds, - exporterOptions.BatchExportProcessorOptions.MaxExportBatchSize)); + options.BatchExportProcessorOptions.MaxQueueSize, + options.BatchExportProcessorOptions.ScheduledDelayMilliseconds, + options.BatchExportProcessorOptions.ExporterTimeoutMilliseconds, + options.BatchExportProcessorOptions.MaxExportBatchSize)); } } } diff --git a/src/OpenTelemetry.Exporter.Jaeger/OpenTelemetry.Exporter.Jaeger.csproj b/src/OpenTelemetry.Exporter.Jaeger/OpenTelemetry.Exporter.Jaeger.csproj index 2227d11ce22..b065a2d502e 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/OpenTelemetry.Exporter.Jaeger.csproj +++ b/src/OpenTelemetry.Exporter.Jaeger/OpenTelemetry.Exporter.Jaeger.csproj @@ -1,7 +1,7 @@  - net46;netstandard2.0;netstandard2.1 + netstandard2.0;netstandard2.1;net46 Jaeger exporter for OpenTelemetry .NET $(PackageTags);Jaeger;distributed-tracing core- @@ -22,6 +22,7 @@ + diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index 39489207617..8f0a45ae550 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -9,6 +9,26 @@ please check the latest changes ## Unreleased +## 1.1.0-beta2 + +Released 2021-Apr-23 + +* Resolves `System.TypeInitializationException` exception when using the + exporter with an application that references Google.Protobuf 3.15. The OTLP + exporter now depends on Google.Protobuf 3.15.5 enabling the use of the new + `UnsafeByteOperations.UnsafeWrap` to avoid unnecessary allocations. + ([#1873](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1873)) + +* Null values in string arrays are preserved according to + [spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/common.md). + ([#1919](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1919)) and + ([#1945](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1945)). + +* When using OpenTelemetry.Extensions.Hosting you can now bind + `OtlpExporterOptions` to `IConfiguration` using the `Configure` extension (ex: + `services.Configure(this.Configuration.GetSection("Otlp"));`). + ([#1942](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1942)) + ## 1.1.0-beta1 Released 2021-Mar-19 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs index 9814b17055e..135a83d91ba 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs @@ -37,7 +37,6 @@ internal static class ActivityExtensions { private static readonly ConcurrentBag SpanListPool = new ConcurrentBag(); private static readonly Action, int> RepeatedFieldOfSpanSetCountAction = CreateRepeatedFieldOfSpanSetCountAction(); - private static readonly Func ByteStringCtorFunc = CreateByteStringCtorFunc(); internal static void AddBatch( this OtlpCollector.ExportTraceServiceRequest request, @@ -135,7 +134,7 @@ internal static OtlpTrace.Span ToOtlpSpan(this Activity activity) { byte[] parentSpanIdBytes = new byte[8]; activity.ParentSpanId.CopyTo(parentSpanIdBytes); - parentSpanIdString = ByteStringCtorFunc(parentSpanIdBytes); + parentSpanIdString = UnsafeByteOperations.UnsafeWrap(parentSpanIdBytes); } var startTimeUnixNano = activity.StartTimeUtc.ToUnixTimeNanoseconds(); @@ -146,8 +145,8 @@ internal static OtlpTrace.Span ToOtlpSpan(this Activity activity) // There is an offset of 1 on the OTLP enum. Kind = (OtlpTrace.Span.Types.SpanKind)(activity.Kind + 1), - TraceId = ByteStringCtorFunc(traceIdBytes), - SpanId = ByteStringCtorFunc(spanIdBytes), + TraceId = UnsafeByteOperations.UnsafeWrap(traceIdBytes), + SpanId = UnsafeByteOperations.UnsafeWrap(spanIdBytes), ParentSpanId = parentSpanIdString, StartTimeUnixNano = (ulong)startTimeUnixNano, @@ -285,8 +284,8 @@ private static OtlpTrace.Span.Types.Link ToOtlpLink(ActivityLink activityLink) var otlpLink = new OtlpTrace.Span.Types.Link { - TraceId = ByteStringCtorFunc(traceIdBytes), - SpanId = ByteStringCtorFunc(spanIdBytes), + TraceId = UnsafeByteOperations.UnsafeWrap(traceIdBytes), + SpanId = UnsafeByteOperations.UnsafeWrap(spanIdBytes), }; TagEnumerationState otlpTags = default; @@ -341,26 +340,6 @@ private static OtlpTrace.Span.Types.Event ToOtlpEvent(ActivityEvent activityEven return (Action, int>)dynamicMethod.CreateDelegate(typeof(Action, int>)); } - private static Func CreateByteStringCtorFunc() - { - ConstructorInfo byteStringCtor = typeof(ByteString).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(byte[]) }, null); - - DynamicMethod dynamicMethod = new DynamicMethod( - "ByteStringCtor", - typeof(ByteString), - new[] { typeof(byte[]) }, - typeof(ActivityExtensions).Module, - skipVisibility: true); - - var generator = dynamicMethod.GetILGenerator(); - - generator.Emit(OpCodes.Ldarg_0); - generator.Emit(OpCodes.Newobj, byteStringCtor); - generator.Emit(OpCodes.Ret); - - return (Func)dynamicMethod.CreateDelegate(typeof(Func)); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] private static OtlpCommon.KeyValue CreateOtlpKeyValue(string key, OtlpCommon.AnyValue value) { @@ -455,7 +434,14 @@ public bool ForEach(KeyValuePair activityTag) case string[] stringArray: foreach (var item in stringArray) { - PooledList.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { StringValue = item })); + PooledList.Add(ref this.Tags, CreateOtlpKeyValue(key, item == null ? null : new OtlpCommon.AnyValue { StringValue = item })); + } + + break; + case long[] longArray: + foreach (var item in longArray) + { + PooledList.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { IntValue = item })); } break; diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj index fe31c2db339..1db5c1f1036 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj @@ -1,6 +1,6 @@  - net452;net46;netstandard2.0 + netstandard2.0;net452;net46