Skip to content

Support customized Activity trace id generation #46704

Closed

Description

Background and Motivation

The .NET runtime provides APIs to generate Activity, which can be adopted and processed as trace context and eventually emitted to multiple backend vendors by OpenTelemetry .NET SDK for the purpose of tracing. Currently .NET runtime only allows an activity's trace id to be randomly generated and there is no public API available to override it. While for some backend vendors, trace context with a non-random customized trace id is more preferred. For instance, AWS X-Ray backend will only process trace context with a trace id containing a timestamp. In this case, is it possible for the runtime to support customized activity trace id in Activity class, like adding API similar as Activity.SetTraceId()?

Previous discussion: open-telemetry/opentelemetry-specification#896

Proposal Edited by @tarekgh

Proposed API

namespace System.Diagnostics
{
    public partial class Activity : IDisposable
    {
        // alternative proposed names: 
        //     GenerateTraceId 
        //     TraceIdCreationFunction
        public static Func<ActivityTraceId>? TraceIdGenerationFunction { get; set; } 
    }
}

Usage Examples

    Activity.TraceIdGenerationFunction = () => ActivityTraceId.CreateRandom();
    
    ...


    using (Activity activity = source.StartActivity("OperationName"))
    {
        Console.WriteLine(activity?.TraceId);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions