First, download and install the .NET Core SDK on your computer.
Create a new console application and run it:
dotnet new console --output getting-started
cd getting-started
dotnet run
You should see the following output:
Hello World!
Install the OpenTelemetry.Exporter.Console package:
dotnet add package OpenTelemetry.Exporter.Console -v 0.7.0-beta.1
Update the Program.cs
file with the code from Program.cs:
Run the application again (using dotnet run
) and you should see the trace
output from the console.
Activity.Id: 00-8389584945550f40820b96ce1ceb9299-745239d26e408342-01
Activity.DisplayName: SayHello
Activity.Kind: Internal
Activity.StartTime: 2020-08-12T15:59:10.4461835Z
Activity.Duration: 00:00:00.0066039
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 an OpenTelemetry
Tracer.
The ActivitySource
instance is used to start an Activity
which represents an
OpenTelemetry
Span.
An OpenTelemetry
TracerProvider
is configured to subscribe to the activities from the source
MyCompany.MyProduct.MyLibrary
, and export it to ConsoleExporter
.
ConsoleExporter
simply displays it on the console.