-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Diagnostics; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Resources; | ||
using OpenTelemetry.Trace; | ||
|
||
Console.WriteLine("Hello, World!"); | ||
|
||
var builder = Sdk.CreateTracerProviderBuilder(); | ||
|
||
using var tracerProvider = builder.SetResourceBuilder(ResourceBuilder.CreateDefault() | ||
.AddService("TraceTest")) | ||
.AddSource("Sample.DistributedTracing") | ||
.AddConsoleExporter() | ||
.AddZipkinExporter(options => { }) | ||
.Build(); | ||
|
||
var activitySource = new ActivitySource("Sample.DistributedTracing", "1.0.0"); | ||
|
||
using (var activity = activitySource.StartActivity("Do", ActivityKind.Server)) | ||
{ | ||
activity?.SetTag("tag1", "foo"); | ||
activity?.SetTag("tag2", "bar"); | ||
|
||
await StepOne(); | ||
activity?.AddEvent(new ActivityEvent("StepOne end.")); | ||
|
||
await StepTwo(); | ||
activity?.AddEvent(new ActivityEvent("StepTwo end.")); | ||
|
||
activity?.SetTag("otel.status_code", DateTime.Now.Microsecond % 2 == 0 ? "OK" : "ERROR"); | ||
activity?.SetTag("otel.status_description", "Use this text give more information about the error"); | ||
} | ||
|
||
Console.ReadLine(); | ||
activitySource.Dispose(); | ||
|
||
async Task StepOne() | ||
{ | ||
using (var activity = activitySource.StartActivity(ActivityKind.Client)) | ||
{ | ||
Console.WriteLine("One"); | ||
await Task.Delay(50); | ||
await StepOneOne(); | ||
} | ||
} | ||
|
||
async Task StepOneOne() | ||
{ | ||
using (var activity = activitySource.StartActivity(ActivityKind.Server)) | ||
{ | ||
Console.WriteLine("OneOne"); | ||
await Task.Delay(50); | ||
} | ||
} | ||
|
||
async Task StepTwo() | ||
{ | ||
using (var activity = activitySource.StartActivity(ActivityKind.Producer)) | ||
{ | ||
Console.WriteLine("Two"); | ||
await Task.Delay(500); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.8.0" /> | ||
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.8.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |