Skip to content

Commit 230adab

Browse files
authored
[docs] Top-level doc showing how to initialize the OpenTelemetry SDK (#5762)
1 parent b15f9a8 commit 230adab

File tree

5 files changed

+306
-118
lines changed

5 files changed

+306
-118
lines changed

OpenTelemetry.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ EndProject
124124
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "test\Benchmarks\Benchmarks.csproj", "{DE9130A4-F30A-49D7-8834-41DE3021218B}"
125125
EndProject
126126
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{7C87CAF9-79D7-4C26-9FFB-F3F1FB6911F1}"
127+
ProjectSection(SolutionItems) = preProject
128+
docs\README.md = docs\README.md
129+
EndProjectSection
127130
EndProject
128131
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{2C7DD1DA-C229-4D9E-9AF0-BCD5CD3E4948}"
129132
ProjectSection(SolutionItems) = preProject
@@ -132,6 +135,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{2C
132135
EndProjectSection
133136
EndProject
134137
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "trace", "trace", "{5B7FB835-3FFF-4BC2-99C5-A5B5FAE3C818}"
138+
ProjectSection(SolutionItems) = preProject
139+
docs\trace\README.md = docs\trace\README.md
140+
EndProjectSection
135141
EndProject
136142
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "metrics", "metrics", "{3277B1C0-BDFE-4460-9B0D-D9A661FB48DB}"
137143
ProjectSection(SolutionItems) = preProject

README.md

Lines changed: 127 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,27 @@
66
[![NuGet](https://img.shields.io/nuget/dt/OpenTelemetry.svg)](https://www.nuget.org/profiles/OpenTelemetry)
77
[![Build](https://github.com/open-telemetry/opentelemetry-dotnet/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/open-telemetry/opentelemetry-dotnet/actions/workflows/ci.yml)
88

9-
The .NET [OpenTelemetry](https://opentelemetry.io/) client.
9+
The .NET [OpenTelemetry](https://opentelemetry.io/) implementation.
1010

11-
## Supported .NET Versions
11+
<details>
12+
<summary>Table of Contents</summary>
13+
14+
* [Supported .NET versions](#supported-net-versions)
15+
* [Project status](#project-status)
16+
* [Getting started](#getting-started)
17+
* [Getting started with Logging](#getting-started-with-logging)
18+
* [Getting started with Metrics](#getting-started-with-metrics)
19+
* [Getting started with Tracing](#getting-started-with-tracing)
20+
* [Repository structure](#repository-structure)
21+
* [Troubleshooting](#troubleshooting)
22+
* [Extensibility](#extensibility)
23+
* [Releases](#releases)
24+
* [Contributing](#contributing)
25+
* [References](#references)
26+
27+
</details>
28+
29+
## Supported .NET versions
1230

1331
Packages shipped from this repository generally support all the officially
1432
supported versions of [.NET](https://dotnet.microsoft.com/download/dotnet) and
@@ -17,36 +35,88 @@ older Windows-based .NET implementation), except `.NET Framework 3.5`.
1735
Any exceptions to this are noted in the individual `README.md`
1836
files.
1937

20-
## Project Status
38+
## Project status
2139

22-
**Stable** across all 3 signals i.e. `Logs`, `Metrics`, and `Traces`.
40+
**Stable** across all 3 signals (`Logs`, `Metrics`, and `Traces`).
2341

24-
See [Spec Compliance
25-
Matrix](https://github.com/open-telemetry/opentelemetry-specification/blob/main/spec-compliance-matrix.md)
26-
to understand which portions of the specification has been implemented in this
27-
repo.
42+
> [!CAUTION]
43+
> Certain components, marked as
44+
[pre-release](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/VERSIONING.md#pre-releases),
45+
are still work in progress and can undergo breaking changes before stable
46+
release. Check the individual `README.md` file for each component to understand its
47+
current state.
2848

29-
## Getting Started
49+
To understand which portions of the [OpenTelemetry
50+
Specification](https://github.com/open-telemetry/opentelemetry-specification)
51+
have been implemented in OpenTelemetry .NET see: [Spec Compliance
52+
Matrix](https://github.com/open-telemetry/opentelemetry-specification/blob/main/spec-compliance-matrix.md).
3053

31-
If you are new here, please read the getting started docs:
54+
## Getting started
3255

33-
* [Logs](./docs/logs/README.md)
34-
* [Metrics](./docs/metrics/README.md)
35-
* [Traces](./docs/trace/README.md)
56+
If you are new here, please read the getting started docs:
3657

37-
This repository includes multiple installable components, available on
38-
[NuGet](https://www.nuget.org/profiles/OpenTelemetry). Each component has its
39-
individual `README.md` file, which covers the instruction on how to install and
40-
how to get started. To find all the available components, please take a look at
41-
the `src` folder.
58+
### Getting started with Logging
59+
60+
If you are new to
61+
[logging](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/README.md),
62+
it is recommended to first follow the [getting started in 5 minutes - ASP.NET
63+
Core Application](./docs/logs/getting-started-aspnetcore/README.md) guide or
64+
the [getting started in 5 minutes - Console
65+
Application](./docs/logs/getting-started-console/README.md) guide to get up
66+
and running.
67+
68+
For general information and best practices see: [OpenTelemetry .NET
69+
Logs](./docs/logs/README.md). For a more detailed explanation of SDK logging
70+
features see: [Customizing OpenTelemetry .NET SDK for
71+
Logs](./docs/logs/customizing-the-sdk/README.md).
72+
73+
### Getting started with Metrics
74+
75+
If you are new to
76+
[metrics](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/README.md),
77+
it is recommended to first follow the [getting started in 5 minutes - ASP.NET
78+
Core Application](./docs/metrics/getting-started-aspnetcore/README.md) guide
79+
or the [getting started in 5 minutes - Console
80+
Application](./docs/metrics/getting-started-console/README.md) guide to get
81+
up and running.
82+
83+
For general information and best practices see: [OpenTelemetry .NET
84+
Metrics](./docs/metrics/README.md). For a more detailed explanation of SDK
85+
metric features see: [Customizing OpenTelemetry .NET SDK for
86+
Metrics](./docs/metrics/customizing-the-sdk/README.md).
87+
88+
### Getting started with Tracing
89+
90+
If you are new to
91+
[traces](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/README.md),
92+
it is recommended to first follow the [getting started in 5 minutes - ASP.NET
93+
Core Application](./docs/trace/getting-started-aspnetcore/README.md) guide
94+
or the [getting started in 5 minutes - Console
95+
Application](./docs/trace/getting-started-console/README.md) guide to get up
96+
and running.
97+
98+
For general information and best practices see: [OpenTelemetry .NET
99+
Traces](./docs/trace/README.md). For a more detailed explanation of SDK tracing
100+
features see: [Customizing OpenTelemetry .NET SDK for
101+
Tracing](./docs/trace/customizing-the-sdk/README.md).
102+
103+
## Repository structure
104+
105+
This repository includes only what is defined in the [OpenTelemetry
106+
Specification](https://github.com/open-telemetry/opentelemetry-specification)
107+
and is shipped as separate packages through
108+
[NuGet](https://www.nuget.org/profiles/OpenTelemetry). Each component has an
109+
individual `README.md` and `CHANGELOG.md` file which covers the instructions on
110+
how to install and get started, and details about the individual changes made
111+
(respectively). To find all the available components, please take a look at the
112+
`src` folder.
42113

43114
Here are the most commonly used components:
44115

45-
* [OpenTelemetry .NET API](./src/OpenTelemetry.Api/README.md)
46-
* [OpenTelemetry .NET SDK](./src/OpenTelemetry/README.md)
47-
48-
[Instrumentation libraries](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#instrumentation-library)
49-
can be found in [contrib repository](https://github.com/open-telemetry/opentelemetry-dotnet-contrib).
116+
* [OpenTelemetry API](./src/OpenTelemetry.Api/README.md)
117+
* [OpenTelemetry SDK](./src/OpenTelemetry/README.md)
118+
* [OpenTelemetry Hosting
119+
Extensions](./src/OpenTelemetry.Extensions.Hosting/README.md)
50120

51121
Here are the [exporter
52122
libraries](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#exporter-library):
@@ -59,16 +129,19 @@ libraries](https://github.com/open-telemetry/opentelemetry-specification/blob/ma
59129
* [Prometheus HttpListener](./src/OpenTelemetry.Exporter.Prometheus.HttpListener/README.md)
60130
* [Zipkin](./src/OpenTelemetry.Exporter.Zipkin/README.md)
61131

62-
See the [OpenTelemetry
63-
registry](https://opentelemetry.io/ecosystem/registry/?language=dotnet) and
64-
[OpenTelemetry .NET Contrib
65-
repo](https://github.com/open-telemetry/opentelemetry-dotnet-contrib) for more
66-
components.
132+
Additional packages including [instrumentation
133+
libraries](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#instrumentation-library),
134+
exporters, resource detectors, and extensions can be found in the
135+
[opentelemetry-dotnet-contrib
136+
repository](https://github.com/open-telemetry/opentelemetry-dotnet-contrib)
137+
and/or the [OpenTelemetry
138+
registry](https://opentelemetry.io/ecosystem/registry/?language=dotnet).
67139

68140
## Troubleshooting
69141

70-
See [Troubleshooting](./src/OpenTelemetry/README.md#troubleshooting).
71-
Additionally check readme file for the individual components for any additional
142+
For general instructions see:
143+
[Troubleshooting](./src/OpenTelemetry/README.md#troubleshooting). Additionally
144+
`README.md` files for individual components may contain more detailed
72145
troubleshooting information.
73146

74147
## Extensibility
@@ -80,17 +153,36 @@ extension scenarios:
80153
library](./docs/trace/extending-the-sdk/README.md#instrumentation-library).
81154
* Building a custom exporter for
82155
[logs](./docs/logs/extending-the-sdk/README.md#exporter),
83-
[metrics](./docs/metrics/extending-the-sdk/README.md#exporter) and
156+
[metrics](./docs/metrics/extending-the-sdk/README.md#exporter), and
84157
[traces](./docs/trace/extending-the-sdk/README.md#exporter).
85158
* Building a custom processor for
86159
[logs](./docs/logs/extending-the-sdk/README.md#processor) and
87160
[traces](./docs/trace/extending-the-sdk/README.md#processor).
88161
* Building a custom sampler for
89162
[traces](./docs/trace/extending-the-sdk/README.md#sampler).
90163

164+
## Releases
165+
166+
For details about upcoming planned releases see:
167+
[Milestones](https://github.com/open-telemetry/opentelemetry-dotnet/milestones).
168+
The dates and features described in issues and milestones are estimates and
169+
subject to change.
170+
171+
For highlights and annoucements for stable releases see: [Release
172+
Notes](./RELEASENOTES.md).
173+
174+
To access packages, source code, and/or view a list of changes for all
175+
components in a release see:
176+
[Releases](https://github.com/open-telemetry/opentelemetry-dotnet/releases).
177+
178+
Nightly builds from this repo are published to [MyGet](https://www.myget.org),
179+
and can be installed using the
180+
`https://www.myget.org/F/opentelemetry/api/v3/index.json` source.
181+
91182
## Contributing
92183

93-
See [CONTRIBUTING.md](CONTRIBUTING.md)
184+
For information about contributing to the project see:
185+
[CONTRIBUTING.md](CONTRIBUTING.md).
94186

95187
We meet weekly on Tuesdays, and the time of the meeting alternates between 9AM
96188
PT and 4PM PT. The meeting is subject to change depending on contributors'
@@ -144,23 +236,7 @@ Maintainer/Approver/Triager](https://github.com/open-telemetry/community/blob/ma
144236

145237
[![contributors](https://contributors-img.web.app/image?repo=open-telemetry/opentelemetry-dotnet)](https://github.com/open-telemetry/opentelemetry-dotnet/graphs/contributors)
146238

147-
## Release Schedule
148-
149-
See the [project
150-
milestones](https://github.com/open-telemetry/opentelemetry-dotnet/milestones)
151-
for details on upcoming releases. The dates and features described in issues and
152-
milestones are estimates, and subject to change.
153-
154-
See the [release
155-
notes](https://github.com/open-telemetry/opentelemetry-dotnet/releases) for
156-
existing releases.
157-
158-
> [!CAUTION]
159-
> Certain components, marked as
160-
[pre-release](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/VERSIONING.md#pre-releases),
161-
are still work in progress and can undergo breaking changes before stable
162-
release. Check the individual `README.md` file for each component to understand its
163-
current state.
239+
## References
164240

165-
Daily builds from this repo are published to MyGet, and can be installed from
166-
[this source](https://www.myget.org/F/opentelemetry/api/v3/index.json).
241+
* [OpenTelemetry Project](https://opentelemetry.io/)
242+
* [OpenTelemetry Specification](https://github.com/open-telemetry/opentelemetry-specification)

docs/README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# OpenTelemetry .NET SDK
2+
3+
## Initialize the SDK
4+
5+
There are two different common initialization styles supported by OpenTelemetry.
6+
7+
### Initialize the SDK using a host
8+
9+
Users building applications based on
10+
[Microsoft.Extensions.Hosting](https://www.nuget.org/packages/Microsoft.Extensions.Hosting)
11+
should utilize the
12+
[OpenTelemetry.Extensions.Hosting](../src/OpenTelemetry.Extensions.Hosting/README.md)
13+
package to initialize OpenTelemetry. This style provides a deep integration
14+
between the host infrastructure (`IServiceCollection`, `IServiceProvider`,
15+
`IConfiguration`, etc.) and OpenTelemetry.
16+
17+
[AspNetCore](https://learn.microsoft.com/aspnet/core/fundamentals/host/web-host)
18+
applications are the most common to use the hosting model but there is also a
19+
[Generic Host](https://learn.microsoft.com/dotnet/core/extensions/generic-host)
20+
which may be used in console, service, and worker applications.
21+
22+
> [!NOTE]
23+
> When using `OpenTelemetry.Extensions.Hosting` only a single pipeline will be
24+
> created for each configured signal (logging, metrics, and/or tracing). Users
25+
> who need more granular control can create additional pipelines using the
26+
> manual style below.
27+
28+
First install the
29+
[OpenTelemetry.Extensions.Hosting](../src/OpenTelemetry.Extensions.Hosting/README.md)
30+
package.
31+
32+
Second call the `AddOpenTelemetry` extension using the host
33+
`IServiceCollection`:
34+
35+
```csharp
36+
var builder = WebApplication.CreateBuilder(args);
37+
38+
// Clear the default logging providers added by the host
39+
builder.Logging.ClearProviders();
40+
41+
// Initialize OpenTelemetry
42+
builder.Services.AddOpenTelemetry()
43+
.ConfigureResource(resource => /* Resource configuration goes here */)
44+
.WithLogging(logging => /* Logging configuration goes here */)
45+
.WithMetrics(metrics => /* Metrics configuration goes here */)
46+
.WithTracing(tracing => /* Tracing configuration goes here */));
47+
```
48+
49+
> [!NOTE]
50+
> Calling `WithLogging` automatically registers the OpenTelemetry
51+
> `ILoggerProvider` and enables `ILogger` integration.
52+
53+
### Initialize the SDK manually
54+
55+
Users running on .NET Framework or running without a host may initialize
56+
OpenTelemetry manually.
57+
58+
> [!IMPORTANT]
59+
> When initializing OpenTelemetry manually make sure to ALWAYS dispose the SDK
60+
> and/or providers when the application is shutting down. Disposing
61+
> OpenTelemetry gives the SDK a chance to flush any telemetry held in memory.
62+
> Skipping this step may result in data loss.
63+
64+
First install the [OpenTelemetry SDK](../src/OpenTelemetry/README.md) package or
65+
an exporter package such as
66+
[OpenTelemetry.Exporter.OpenTelemetryProtocol](../src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md).
67+
Exporter packages typically reference the SDK and will make it available via
68+
transitive reference.
69+
70+
Second use one of the following initialization APIs (depending on the SDK
71+
version being used):
72+
73+
#### Using 1.10.0 or newer
74+
75+
The `OpenTelemetrySdk.Create` API can be used to initialize all signals off a
76+
single root builder and supports cross-cutting extensions such as
77+
`ConfigureResource` which configures a `Resource` to be used by all enabled
78+
signals. An `OpenTelemetrySdk` instance is returned which may be used to access
79+
providers for each signal. Calling `Dispose` on the returned instance will
80+
gracefully shutdown the SDK and flush any telemetry held in memory.
81+
82+
> [!NOTE]
83+
> When calling `OpenTelemetrySdk.Create` a dedicated `IServiceCollection` and
84+
> `IServiceProvider` will be created for the SDK and shared by all signals. An
85+
> `IConfiguration` is created automatically from environment variables.
86+
87+
```csharp
88+
using OpenTelemetry;
89+
90+
var sdk = OpenTelemetrySdk.Create(builder => builder
91+
.ConfigureResource(resource => /* Resource configuration goes here */)
92+
.WithLogging(logging => /* Logging configuration goes here */)
93+
.WithMetrics(metrics => /* Metrics configuration goes here */)
94+
.WithTracing(tracing => /* Tracing configuration goes here */));
95+
96+
// During application shutdown
97+
sdk.Dispose();
98+
```
99+
100+
To obtain an `ILogger` instance for emitting logs when using the
101+
`OpenTelemetrySdk.Create` API call the `GetLoggerFactory` extension method using
102+
the returned `OpenTelemetrySdk` instance:
103+
104+
```csharp
105+
var logger = sdk.GetLoggerFactory().CreateLogger<Program>()
106+
logger.LogInformation("Application started");
107+
```
108+
109+
#### Using 1.9.0 or older
110+
111+
The following shows how to create providers for each individual signal. Each
112+
provider is independent and must be managed and disposed explicitly. There is no
113+
mechanism using this style to perform cross-cutting actions across signals.
114+
115+
```csharp
116+
using Microsoft.Extensions.Logging;
117+
using OpenTelemetry;
118+
119+
var tracerProvider = Sdk.CreateTracerProviderBuilder()
120+
/* Tracing configuration goes here */
121+
.Build();
122+
123+
var meterProvider = Sdk.CreateMeterProviderBuilder()
124+
/* Metrics configuration goes here */
125+
.Build();
126+
127+
var loggerFactory = LoggerFactory.Create(builder => builder
128+
.AddOpenTelemetry(options => /* Logging configuration goes here */));
129+
130+
// During application shutdown
131+
tracerProvider.Dispose();
132+
meterProvider.Dispose();
133+
loggerFactory.Dispose();
134+
```

src/OpenTelemetry.Api/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,4 +539,8 @@ seeing these internal logs.
539539
540540
## References
541541
542-
* [OpenTelemetry Project](https://opentelemetry.io/)
542+
* [OpenTelemetry Baggage API specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/baggage/api.md)
543+
* [OpenTelemetry Logs Bridge API specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/bridge-api.md)
544+
* [OpenTelemetry Metrics API specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md)
545+
* [OpenTelemetry Propagators API specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/api-propagators.md)
546+
* [OpenTelemetry Tracing API specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md)

0 commit comments

Comments
 (0)