Odigos will automatically instrument your services and record semantic spans from popular modules. Many users find the automatic instrumentation data sufficient for their needs.

However, if there is anything specific to your application that you want to record, you can enrich the data by adding custom spans to your code.

This is sometimes referred to as manual instrumentation.

Use Cases

Examples of custom spans you might want to add to your code include:

  • Spans for the execution of some potentially heavy or slow computation in you service.
  • Tracing for internal or third party libraries for which you don’t have automatic or integrated instrumentation.
  • Spans to describe some logical operations in your business logic that are meaningful in your domain.

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.