Replace docs example with actual code (#1054)
* Replace doc with actual program * fix * min * fix * review coment * fix format * fix docfx build
This commit is contained in:
parent
ffb1bc68e5
commit
e86e49a2e9
|
|
@ -167,7 +167,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "trace", "trace", "{5B7FB835
|
|||
docs\trace\building-your-own-instrumentation-library.md = docs\trace\building-your-own-instrumentation-library.md
|
||||
docs\trace\building-your-own-processor.md = docs\trace\building-your-own-processor.md
|
||||
docs\trace\building-your-own-sampler.md = docs\trace\building-your-own-sampler.md
|
||||
docs\trace\getting-started.md = docs\trace\getting-started.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "building-your-own-processor", "docs\trace\building-your-own-processor\building-your-own-processor.csproj", "{B1891B31-B021-4074-8E42-B4AC170CD208}"
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@ The .NET [OpenTelemetry](https://opentelemetry.io/) client.
|
|||
|
||||
## Getting Started
|
||||
|
||||
If you are new here, please [get started in 5 minutes](./docs/trace/getting-started.md).
|
||||
|
||||
If you are new here, please [get started in 5 minutes](./docs/trace/getting-started/README.md).
|
||||
This repository includes multiple installable components, available on
|
||||
[NuGet](https://www.nuget.org/profiles/OpenTelemetry).
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@
|
|||
"files": [
|
||||
"docs/**.png",
|
||||
"examples/**.cs",
|
||||
"src/**.cs"
|
||||
"src/**.cs",
|
||||
"docs/**.cs"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,81 +0,0 @@
|
|||
# Getting Started with OpenTelemetry .NET in 5 Minutes
|
||||
|
||||
First, download and install the [.NET Core
|
||||
SDK](https://dotnet.microsoft.com/download) on your computer.
|
||||
|
||||
Create a new console application and run it:
|
||||
|
||||
```sh
|
||||
dotnet new console --output getting-started
|
||||
cd getting-started
|
||||
dotnet run
|
||||
```
|
||||
|
||||
You should see the following output:
|
||||
|
||||
```console
|
||||
Hello World!
|
||||
```
|
||||
|
||||
Install the
|
||||
[OpenTelemetry.Exporter.Console](../../src/OpenTelemetry.Exporter.Console/README.md)
|
||||
package:
|
||||
|
||||
```sh
|
||||
dotnet add package OpenTelemetry.Exporter.Console -v 0.4.0-beta.2
|
||||
```
|
||||
|
||||
Update the `Program.cs` file with the following code:
|
||||
|
||||
```csharp
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
public class Program
|
||||
{
|
||||
private static readonly ActivitySource MyActivitySource = new ActivitySource(
|
||||
"MyCompany.MyProduct.MyLibrary");
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
using var otel = Sdk.CreateTracerProvider(b => b
|
||||
.AddActivitySource("MyCompany.MyProduct.MyLibrary")
|
||||
.UseConsoleExporter());
|
||||
|
||||
using (var activity = MyActivitySource.StartActivity("SayHello"))
|
||||
{
|
||||
activity?.SetTag("foo", 1);
|
||||
activity?.SetTag("bar", "Hello, World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Run the application again (using `dotnet run`) and you should see the trace
|
||||
output from the console.
|
||||
|
||||
```text
|
||||
Activity ID - 00-3ae67370100cdc44a8d461d1b2cf846f-d80f2b1ab6d3bc4b-01
|
||||
Activity DisplayName - SayHello
|
||||
Activity Kind - Internal
|
||||
Activity StartTime - 7/24/2020 1:16:21 AM
|
||||
Activity Duration - 00:00:00.0018754
|
||||
Activity Tags
|
||||
foo : 1
|
||||
bar : Hello, World!
|
||||
```
|
||||
|
||||
Congratulations! You are now collecting traces using OpenTelemetry.
|
||||
|
||||
What does the above program do?
|
||||
|
||||
The program creates an `ActivitySource` which represents [OpenTelemetry
|
||||
Tracer](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#tracer).
|
||||
The activitysource instance is used to start an `Activity` which represent
|
||||
[OpenTelemetry
|
||||
Span](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#span).
|
||||
`Sdk.CreateTracerProvider` sets up the OpenTelemetry Sdk, and
|
||||
configures it to subscribe to the activities from the source
|
||||
`MyCompany.MyProduct.MyLibrary`, and export it to `ConsoleExporter`, which
|
||||
simply displays it on the console.
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Exporter.Console;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
public class Program
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
# Getting Started with OpenTelemetry .NET in 5 Minutes
|
||||
|
||||
First, download and install the [.NET Core
|
||||
SDK](https://dotnet.microsoft.com/download) on your computer.
|
||||
|
||||
Create a new console application and run it:
|
||||
|
||||
```sh
|
||||
dotnet new console --output getting-started cd getting-started dotnet run
|
||||
```
|
||||
|
||||
You should see the following output:
|
||||
|
||||
```console
|
||||
Hello World!
|
||||
```
|
||||
|
||||
Install the
|
||||
[OpenTelemetry.Exporter.Console](../../../src/OpenTelemetry.Exporter.Console/README.md)
|
||||
package:
|
||||
|
||||
```sh
|
||||
dotnet add package OpenTelemetry.Exporter.Console -v 0.4.0-beta.2
|
||||
```
|
||||
|
||||
Update the `Program.cs` file with the code from [Program.cs](./Program.cs):
|
||||
|
||||
Run the application again (using `dotnet run`) and you should see the trace
|
||||
output from the console.
|
||||
|
||||
```text
|
||||
Activity.Id:
|
||||
00-55c1ae1c6c23784bbc4fca463d7e15ca-bfe3220d9e489e4b-01 Activity.ParentId:
|
||||
00-55c1ae1c6c23784bbc4fca463d7e15ca-0000000000000000-00 Activity.DisplayName:
|
||||
SayHello Activity.Kind: Internal Activity.StartTime:
|
||||
2020-08-12T07:37:40.9681787Z Activity.Duration: 00:00:00.0047972
|
||||
Activity.TagObjects:
|
||||
foo: 1 bar: Hello, World! baz: [1, 2, 3]
|
||||
```
|
||||
|
||||
Congratulations! You are now collecting traces using OpenTelemetry.
|
||||
|
||||
What does the above program do?
|
||||
|
||||
The program creates an `ActivitySource` which represents [OpenTelemetry
|
||||
Tracer](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#tracer).
|
||||
The activitysource instance is used to start an `Activity` which represent
|
||||
[OpenTelemetry
|
||||
Span](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#span).
|
||||
An OpenTelemetry
|
||||
[TracerProvider](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#tracerprovider)
|
||||
configured to subscribe to the activities from the source
|
||||
`MyCompany.MyProduct.MyLibrary`, and export it to `ConsoleExporter`.
|
||||
`ConsoleExporter` simply displays it on the console.
|
||||
|
|
@ -23,3 +23,4 @@ for an example of how to use the exporter.
|
|||
## References
|
||||
|
||||
* [OpenTelemetry Project](https://opentelemetry.io/)
|
||||
* [zPages](https://opencensus.io/zpages/)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ the following.
|
|||
## Getting started
|
||||
|
||||
Please follow the tutorial and [get started in 5
|
||||
minutes](../../docs/trace/getting-started.md).
|
||||
minutes](../../docs/trace/getting-started/README.md).
|
||||
|
||||
## Configuration
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue