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
+
+
+
+
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;net461Console exporter for OpenTelemetry .NET$(PackageTags);Console;distributed-tracingcore-
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;net461In-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;net46Jaeger exporter for OpenTelemetry .NET$(PackageTags);Jaeger;distributed-tracingcore-
@@ -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