Skip to content

Commit e1cefe8

Browse files
author
Jann Roder
authored
Merge branch 'main' into sql_settings_unconditional
2 parents 0d81214 + 9805587 commit e1cefe8

51 files changed

Lines changed: 530 additions & 127 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
*.user
99
*.userosscache
1010
*.sln.docstates
11-
.vscode/solution-explorer
11+
.vscode/
12+
.devcontainer/
1213

1314
# User-specific files (MonoDevelop/Xamarin Studio)
1415
*.userprefs

OpenTelemetry.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp.AspNetCore.5.0", "t
199199
EndProject
200200
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "exception-reporting", "docs\trace\exception-reporting\exception-reporting.csproj", "{08D29501-F0A3-468F-B18D-BD1821A72383}"
201201
EndProject
202+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "customizing-the-sdk", "docs\trace\customizing-the-sdk\customizing-the-sdk.csproj", "{64E3D8BB-93AB-4571-93F7-ED8D64DFFD06}"
203+
EndProject
202204
Global
203205
GlobalSection(SolutionConfigurationPlatforms) = preSolution
204206
Debug|Any CPU = Debug|Any CPU
@@ -393,6 +395,10 @@ Global
393395
{08D29501-F0A3-468F-B18D-BD1821A72383}.Debug|Any CPU.Build.0 = Debug|Any CPU
394396
{08D29501-F0A3-468F-B18D-BD1821A72383}.Release|Any CPU.ActiveCfg = Release|Any CPU
395397
{08D29501-F0A3-468F-B18D-BD1821A72383}.Release|Any CPU.Build.0 = Release|Any CPU
398+
{64E3D8BB-93AB-4571-93F7-ED8D64DFFD06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
399+
{64E3D8BB-93AB-4571-93F7-ED8D64DFFD06}.Debug|Any CPU.Build.0 = Debug|Any CPU
400+
{64E3D8BB-93AB-4571-93F7-ED8D64DFFD06}.Release|Any CPU.ActiveCfg = Release|Any CPU
401+
{64E3D8BB-93AB-4571-93F7-ED8D64DFFD06}.Release|Any CPU.Build.0 = Release|Any CPU
396402
EndGlobalSection
397403
GlobalSection(SolutionProperties) = preSolution
398404
HideSolutionNode = FALSE
@@ -423,6 +429,7 @@ Global
423429
{13C10C9A-07E8-43EB-91F5-C2B116FBE0FC} = {3862190B-E2C5-418E-AFDC-DB281FB5C705}
424430
{972396A8-E35B-499C-9BA1-765E9B8822E1} = {77C7929A-2EED-4AA6-8705-B5C443C8AA0F}
425431
{08D29501-F0A3-468F-B18D-BD1821A72383} = {5B7FB835-3FFF-4BC2-99C5-A5B5FAE3C818}
432+
{64E3D8BB-93AB-4571-93F7-ED8D64DFFD06} = {5B7FB835-3FFF-4BC2-99C5-A5B5FAE3C818}
426433
EndGlobalSection
427434
GlobalSection(ExtensibilityGlobals) = postSolution
428435
SolutionGuid = {55639B5C-0770-4A22-AB56-859604650521}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
[![Slack](https://img.shields.io/badge/slack-@cncf/otel/dotnet-brightgreen.svg?logo=slack)](https://cloud-native.slack.com/archives/C01N3BC2W7Q)
44
[![codecov.io](https://codecov.io/gh/open-telemetry/opentelemetry-dotnet/branch/main/graphs/badge.svg?)](https://codecov.io/gh/open-telemetry/opentelemetry-dotnet/)
5-
[![Release](https://img.shields.io/github/v/release/open-telemetry/opentelemetry-dotnet?include_prereleases&style=)](https://github.com/open-telemetry/opentelemetry-dotnet/releases/)
6-
[![Nuget](https://img.shields.io/nuget/vpre/OpenTelemetry.svg)](https://www.nuget.org/profiles/OpenTelemetry)
5+
[![Release](https://img.shields.io/github/v/release/open-telemetry/opentelemetry-dotnet)](https://github.com/open-telemetry/opentelemetry-dotnet/releases/)
6+
[![Nuget](https://img.shields.io/nuget/v/OpenTelemetry.svg)](https://www.nuget.org/profiles/OpenTelemetry)
77
[![NuGet](https://img.shields.io/nuget/dt/OpenTelemetry.svg)](https://www.nuget.org/profiles/OpenTelemetry)
88

99
The .NET [OpenTelemetry](https://opentelemetry.io/) client.

VERSIONING.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ changes. For example,
5656
shows the public APIs, per target framework for the
5757
`OpenTelemetry.Instrumentation.AspNetCore` package.
5858

59-
Since no stable version has been released so far, every API is listed in the
60-
"Unshipped.txt" file. Once 1.0.0 is shipped, it'll be moved to "Shipped.txt"
61-
file.
59+
APIs which are released as part of stable packages will be listed in the
60+
"Shipped.txt" file, and those APIs which are released as part of
61+
[pre-release](#pre-releases) packages in the "Unshipped.txt". APIs will be moved
62+
from "Unshipped.txt" to "Shipped.txt" when the packages move from
63+
[pre-release](#pre-releases) to stable.
6264

6365
## Packaging
6466

build/RELEASING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Only for Maintainers.
1818
$ended = $false
1919
foreach ($line in $lines)
2020
{
21-
if($line -like "## *" -and $started -ne $true)
21+
if($line -like "## Unreleased" -and $started -ne $true)
2222
{
2323
$started = $true
2424
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// <copyright file="Program.cs" company="OpenTelemetry Authors">
2+
// Copyright The OpenTelemetry Authors
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
// </copyright>
16+
17+
using System.Diagnostics;
18+
using OpenTelemetry;
19+
using OpenTelemetry.Trace;
20+
21+
public class Program
22+
{
23+
private static readonly ActivitySource MyLibraryActivitySource = new ActivitySource(
24+
"MyCompany.MyProduct.MyLibrary");
25+
26+
private static readonly ActivitySource ComponentAActivitySource = new ActivitySource(
27+
"AbcCompany.XyzProduct.ComponentA");
28+
29+
private static readonly ActivitySource ComponentBActivitySource = new ActivitySource(
30+
"AbcCompany.XyzProduct.ComponentB");
31+
32+
private static readonly ActivitySource SomeOtherActivitySource = new ActivitySource(
33+
"SomeCompany.SomeProduct.SomeComponent");
34+
35+
public static void Main()
36+
{
37+
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
38+
39+
// The following adds subscription to activities from Activity Source
40+
// named "MyCompany.MyProduct.MyLibrary" only.
41+
.AddSource("MyCompany.MyProduct.MyLibrary")
42+
43+
// The following adds subscription to activities from all Activity Sources
44+
// whose name starts with "AbcCompany.XyzProduct.".
45+
.AddSource("AbcCompany.XyzProduct.*")
46+
.AddConsoleExporter()
47+
.Build();
48+
49+
// This activity source is enabled.
50+
using (var activity = MyLibraryActivitySource.StartActivity("SayHello"))
51+
{
52+
activity?.SetTag("foo", 1);
53+
activity?.SetTag("bar", "Hello, World!");
54+
}
55+
56+
// This activity source is enabled through wild card "AbcCompany.XyzProduct.*"
57+
using (var activity = ComponentAActivitySource.StartActivity("SayHello"))
58+
{
59+
activity?.SetTag("foo", 1);
60+
activity?.SetTag("bar", "Hello, World!");
61+
}
62+
63+
// This activity source is enabled through wild card "AbcCompany.XyzProduct.*"
64+
using (var activity = ComponentBActivitySource.StartActivity("SayHello"))
65+
{
66+
activity?.SetTag("foo", 1);
67+
activity?.SetTag("bar", "Hello, World!");
68+
}
69+
70+
// This activity source is not enabled, so activity will
71+
// be null here.
72+
using (var activity = SomeOtherActivitySource.StartActivity("SayHello"))
73+
{
74+
activity?.SetTag("foo", 1);
75+
activity?.SetTag("bar", "Hello, World!");
76+
}
77+
}
78+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Customizing OpenTelemetry .NET SDK
2+
3+
**This doc is work-in-progress.**
4+
5+
## TracerProvider
6+
7+
As shown in the [getting-started](../getting-started/README.md) doc, a valid
8+
[`TracerProvider`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#tracer-provider)
9+
must be configured and built to collect traces with OpenTelemetry .NET Sdk.
10+
`TracerProvider` holds all the configuration for tracing like samplers,
11+
processors, etc. Naturally, almost all the customizations must be done on the
12+
`TracerProvider`.
13+
14+
## Building a TracerProvider
15+
16+
Building a `TracerProvider` is done using `TracerProviderBuilder` which must be
17+
obtained by calling `Sdk.CreateTracerProviderBuilder()`. `TracerProviderBuilder`
18+
exposes various methods which configures the provider it is going to build. These
19+
includes methods like `SetSampler`, `AddProcessor` etc, and are explained in
20+
subsequent sections of this document. Once configuration is done, calling
21+
`Build()` on the `TracerProviderBuilder` builds the `TracerProvider` instance.
22+
Once built, changes to its configuration is not allowed, with the exception of
23+
adding more processors. In most cases, a single `TracerProvider` is created at
24+
the application startup, and is disposed when application shuts down.
25+
26+
The snippet below shows how to build a basic `TracerProvider`. This will create
27+
a provider with default configuration, and is not particularly useful. The
28+
subsequent sections shows how to build a more useful provider.
29+
30+
```csharp
31+
using OpenTelemetry;
32+
using OpenTelemetry.Trace;
33+
34+
using var tracerProvider = Sdk.CreateTracerProviderBuilder().Build();
35+
```
36+
37+
## TracerProvider configuration
38+
39+
`TracerProvider` holds the tracing configuration, which includes the following:
40+
41+
1. The list of `ActivitySource`s (aka Tracers) from which traces are collected.
42+
2. The list of instrumentations enabled via
43+
[InstrumentationLibrary](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#instrumentation-library).
44+
3. The list of
45+
[Processors](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#span-processor),
46+
including exporting processors which exports traces to
47+
[Exporters](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#span-exporter)
48+
4. The
49+
[Resource](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md)
50+
associated with the traces.
51+
5. The
52+
[Sampler](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#sampler)
53+
to be used.
54+
55+
### Activity Source
56+
57+
`ActivitySource` denotes a
58+
[`Tracer`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#tracer),
59+
which is used to start activities. The SDK follows an explicit opt-in model for
60+
listening to activity sources. i.e, by default, it listens to no sources. Every
61+
activity source which produce telemetry must be explicitly added to the tracer
62+
provider to start collecting traces from them.
63+
64+
`AddSource` method on `TracerProviderBuilder` can be used to add a
65+
`ActivitySource` to the provider. The name of the `ActivitySource`
66+
(case-insensitive) must be the argument to this method. Multiple `AddSource` can
67+
be called to add more than one source. It also supports wild-card subscription
68+
model as well.
69+
70+
It is not possible to add sources *after* the provider is built, by calling the
71+
`Build()` method on the `TracerProviderBuilder`.
72+
73+
The snippet below shows how to add activity sources to the provider.
74+
75+
```csharp
76+
using OpenTelemetry;
77+
using OpenTelemetry.Trace;
78+
79+
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
80+
// The following subscribes to activities from Activity Source
81+
// named "MyCompany.MyProduct.MyLibrary" only.
82+
.AddSource("MyCompany.MyProduct.MyLibrary")
83+
// The following subscribes to activities from all Activity Sources
84+
// whose name starts with "AbcCompany.XyzProduct.".
85+
.AddSource("AbcCompany.XyzProduct.*")
86+
.Build();
87+
```
88+
89+
See [Program.cs](./Program.cs) for complete example.
90+
91+
**Note**
92+
A common mistake while configuring `TracerProvider` is forgetting to add
93+
all `ActivitySources` to the provider. It is recommended to leverage the
94+
wild card subscription model where it makes sense. For example, if your
95+
application is expecting to enable tracing from a number of libraries
96+
from a company "Abc", the you can use `AddSource("Abc.*")` to enable
97+
all sources whose name starts with "Abc.".
98+
99+
### Instrumentation
100+
101+
// TODO
102+
103+
### Processor
104+
105+
// TODO
106+
107+
### Resource
108+
109+
// TODO
110+
111+
### Sampler
112+
113+
// TODO
114+
115+
## Context Propagation
116+
117+
// TODO: OpenTelemetry Sdk contents about Context.
118+
// TODO: Links to built-in instrumentations doing Propagation.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<ItemGroup>
3+
<!---
4+
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="$(OpenTelemetryExporterConsolePkgVer)" />
5+
-->
6+
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.Console\OpenTelemetry.Exporter.Console.csproj" />
7+
</ItemGroup>
8+
</Project>

docs/trace/getting-started/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,7 @@ to learn more.
7777

7878
## Learn more
7979

80+
* If you want to customize the Sdk, refer to [customizing
81+
the SDK](../customizing-the-sdk/README.md).
8082
* If you want to build a custom exporter/processor/sampler, refer to [extending
8183
the SDK](../extending-the-sdk/README.md).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
abstract OpenTelemetry.Trace.TracerProviderBuilder.AddLegacySource(string operationName) -> OpenTelemetry.Trace.TracerProviderBuilder
12
OpenTelemetry.Trace.TracerProviderBuilder.TracerProviderBuilder() -> void

0 commit comments

Comments
 (0)