|
1 | | -# OpenTelemetry .NET SDK |
2 | | - |
3 | | -[](https://www.nuget.org/packages/OpenTelemetry) |
4 | | -[](https://www.nuget.org/packages/OpenTelemetry) |
5 | | - |
6 | | -<details> |
7 | | -<summary>Table of Contents</summary> |
8 | | - |
9 | | -* [Installation](#installation) |
10 | | -* [Introduction](#introduction) |
11 | | -* [Troubleshooting](#troubleshooting) |
12 | | - * [Self-diagnostics](#self-diagnostics) |
13 | | - * [Configuration Parameters](#configuration-parameters) |
14 | | - * [Remarks](#remarks) |
15 | | -* [References](#references) |
16 | | - |
17 | | -</details> |
18 | | - |
19 | | -## Installation |
20 | | - |
21 | | -```shell |
22 | | -dotnet add package OpenTelemetry |
23 | | -``` |
24 | | - |
25 | | -## Introduction |
26 | | - |
27 | | -OpenTelemetry SDK is a reference implementation of the OpenTelemetry API. It |
28 | | -implements the Logging API, Metrics API, Tracing API, Resource API, and the |
29 | | -Context API. Once a valid SDK is installed and configured all the OpenTelemetry |
30 | | -API methods, which were no-ops without an SDK, will start emitting telemetry. |
31 | | -This SDK also ships with |
32 | | -[ILogger](https://learn.microsoft.com/dotnet/core/extensions/logging) |
33 | | -integration to automatically capture and enrich logs emitted using |
34 | | -`Microsoft.Extensions.Logging`. |
35 | | - |
36 | | -The SDK deals with concerns such as sampling, processing pipelines (exporting |
37 | | -telemetry to a particular backend, etc.), metrics aggregation, and other |
38 | | -concerns outlined in the [OpenTelemetry |
39 | | -Specification](https://github.com/open-telemetry/opentelemetry-specification). |
40 | | -In most cases, users indirectly install and enable the SDK when they install an |
41 | | -exporter. |
42 | | - |
43 | | -To learn how to set up and configure the OpenTelemetry SDK see: [Getting |
44 | | -started](../../README.md#getting-started). For additional details about |
45 | | -initialization patterns see: [Initialize the |
46 | | -SDK](../../docs/README.md#initialize-the-sdk). |
47 | | - |
48 | | -## Troubleshooting |
49 | | - |
50 | | -All the components shipped from this repo uses |
51 | | -[EventSource](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracing.eventsource) |
52 | | -for its internal logging. The name of the `EventSource` used by OpenTelemetry |
53 | | -SDK is "OpenTelemetry-Sdk". To know the `EventSource` names used by other |
54 | | -components, refer to the individual readme files. |
55 | | - |
56 | | -While it is possible to view these logs using tools such as |
57 | | -[PerfView](https://github.com/microsoft/perfview), |
58 | | -[dotnet-trace](https://docs.microsoft.com/dotnet/core/diagnostics/dotnet-trace) |
59 | | -etc., this SDK also ships a [self-diagnostics](#self-diagnostics) feature, which |
60 | | -helps with troubleshooting. |
61 | | - |
62 | | -### Self-diagnostics |
63 | | - |
64 | | -OpenTelemetry SDK ships with built-in self-diagnostics feature. This feature, |
65 | | -when enabled, will listen to internal logs generated by all OpenTelemetry |
66 | | -components (i.e EventSources whose name starts with "OpenTelemetry-") and writes |
67 | | -them to a log file. |
68 | | - |
69 | | -The self-diagnostics feature can be enabled/changed/disabled while the process |
70 | | -is running (without restarting the process). The SDK will attempt to read the |
71 | | -configuration file every `10` seconds in non-exclusive read-only mode. The SDK |
72 | | -will create or overwrite a file with new logs according to the configuration. |
73 | | -This file will not exceed the configured max size and will be overwritten in a |
74 | | -circular way. |
75 | | - |
76 | | -To enable self-diagnostics, go to the |
77 | | -[current working directory](https://en.wikipedia.org/wiki/Working_directory) of |
78 | | -your process and create a configuration file named `OTEL_DIAGNOSTICS.json` with |
79 | | -the following content: |
80 | | - |
81 | | -```json |
82 | | -{ |
83 | | - "LogDirectory": ".", |
84 | | - "FileSize": 32768, |
85 | | - "LogLevel": "Warning" |
86 | | -} |
87 | | -``` |
88 | | - |
89 | | -To disable self-diagnostics, delete the above file. |
90 | | - |
91 | | -Tip: In most cases, you could just drop the file along your application. |
92 | | -On Windows, you can use [Process Explorer](https://docs.microsoft.com/sysinternals/downloads/process-explorer), |
93 | | -double click on the process to pop up Properties dialog and find "Current |
94 | | -directory" in "Image" tab. |
95 | | -Internally, it looks for the configuration file located in |
96 | | -[GetCurrentDirectory](https://docs.microsoft.com/dotnet/api/system.io.directory.getcurrentdirectory), |
97 | | -and then [AppContext.BaseDirectory](https://docs.microsoft.com/dotnet/api/system.appcontext.basedirectory). |
98 | | -You can also find the exact directory by calling these methods from your code. |
99 | | - |
100 | | -#### Configuration Parameters |
101 | | - |
102 | | -1. `LogDirectory` is the directory where the output log file will be stored. It |
103 | | - can be an absolute path or a relative path to the current directory. |
104 | | - |
105 | | -2. `FileSize` is a positive integer, which specifies the log file size in |
106 | | - [KiB](https://en.wikipedia.org/wiki/Kibibyte). This value must be within |
107 | | - range `[1024, 131072]` (1 MiB \<= size \<= 128 MiB), or it will be rounded to |
108 | | - the closest upper or lower limit. The log file will never exceed this |
109 | | - configured size, and will be overwritten in a circular way. |
110 | | - |
111 | | -3. `LogLevel` is the lowest level of the events to be captured. It has to be one |
112 | | - of the |
113 | | - [values](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracing.eventlevel#fields) |
114 | | - of the [`EventLevel` |
115 | | - enum](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracing.eventlevel). |
116 | | - The level signifies the severity of an event. Lower severity levels encompass |
117 | | - higher severity levels. For example, `Warning` includes the `Error` and |
118 | | - `Critical` levels. |
119 | | - |
120 | | -#### Remarks |
121 | | - |
122 | | -A `FileSize`-KiB log file named as `ExecutableName.ProcessId.log` (e.g. |
123 | | -`foobar.exe.12345.log`) will be generated at the specified directory |
124 | | -`LogDirectory`, into which logs are written to. |
125 | | - |
126 | | -If the SDK fails to parse the `LogDirectory`, `FileSize` or `LogLevel` fields as |
127 | | -the specified format, the configuration file will be treated as invalid and no |
128 | | -log file would be generated. |
129 | | - |
130 | | -When the `LogDirectory` or `FileSize` is found to be changed, the SDK will create |
131 | | -or overwrite a file with new logs according to the new configuration. The |
132 | | -configuration file has to be no more than 4 KiB. In case the file is larger than |
133 | | -4 KiB, only the first 4 KiB of content will be read. |
134 | | - |
135 | | -The log file might not be a proper text file format to achieve the goal of having |
136 | | -minimal overhead and bounded resource usage: it may have trailing `NUL`s if log |
137 | | -text is less than configured size; once write operation reaches the end, it will |
138 | | -start from beginning and overwrite existing text. |
139 | | - |
140 | | -## References |
141 | | - |
142 | | -* [OpenTelemetry Logging SDK specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md) |
143 | | -* [OpenTelemetry Metrics SDK specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md) |
144 | | -* [OpenTelemetry Tracing SDK specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md) |
145 | | -* [OpenTelemetry Resource SDK specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md) |
| 1 | +@(ReadmeLines->'%(Identity.Replace('CONTRIBUTING.md','https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/CONTRIBUTING.md'))') |
0 commit comments