Enrich with OpenTelemetry APIs
.NET
Required dependencies
Add the following dependencies to your project by running:
dotnet add package OpenTelemetry
Creating Activity
To create a new Activity
, use the ActivitySource
class.
using System.Diagnostics;
public static class Telemetry
{
// Name it after the service name for your app.
// It can come from a config file, constants file, etc.
public static readonly ActivitySource MyActivitySource = new(TelemetryConstants.ServiceName);
public static void MyMethod()
{
using (var activity = MyActivitySource.StartActivity("MyMethod"))
{
// Your code here
}
}
}
Additional information
For more use cases, see the OpenTelemetry .NET API documentation.