GithubHelp home page GithubHelp logo

avkom / opentracing-dotnet-activespan Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 20 KB

This library provides wrappers around .NET OpenTracing interfaces (opentracing-csharp) which provide a reference to the current active Span and propagate the current tracing Span throughout the application without changing the application's code.

License: MIT License

C# 100.00%

opentracing-dotnet-activespan's Introduction

opentracing-dotnet-activespan

Trace context extensions for opentracing-csharp.

This library provides wrappers and extension methods around OpenTracing interfaces which can be used for propagating the current tracing Span throughout the application without changing the application's code.

However, if the application is starting new threads or is using thread pools, the thread-local context is not going to be carried over into the execution in the next thread. To maintain context propagation, a wrapper TraceTaskScheduler and TraceTaskFactory are provided that automatically transfers the context onto the new threads.

Features:

  1. ISpan IAdvancedTracer.ActiveSpan { get; } provides a reference to a current active span.
  2. ITracer.BuildSpan(string operationName) adds reference "child of" from a new created span to a current active span automatically. If you do not want this reference, use IAdvancedTracer.BuildIgnoreActive(string operationName) method instead.
  3. ISpan ISpanBuilder.Start() starts a new span and makes it active automatically. If you do not want to make it active, use ISpan TraceExtensions.StartNonActive(this ISpanBuilder spanBuilder) extension method instead.
  4. You can make this span active later by using void TraceExtensions.MakeActive(this ISpan span) extension method.
  5. void ISpan.Dispose()/void ISpan.Finish()/void ISpan.Finish(DateTimeOffset finishTimestamp) restores previous value of active span automatically.

Usage:

ITracer zipkinTracer = new ZipkinTracer(...);
ITraceContext traceContext = new TraceContext();
IAdvancedTracer tracer = new AdvancedTracer(zipkinTracer, traceContext);

using (tracer
    .BuildSpan("1") // Add a reference "child of" to the span "1" from the current active span.
    .Start()) // Make the span "1" active automatically.
{
    ...
    
    tracer.ActiveSpan.SetTag("key", "value");
    
    ...
    
    using (tracer
        .BuildSpan("1.1") // Add a reference "child of" from span "1.1" to the active span "1" automatically.
        .Start()) // Make the span "1.1" active automatically.
    {
        ...
        tracer.ActiveSpan.SetTag("key2", "value2");
        ...
    } // The span "1.1" is not anymore active. Span "1" is active again.
    
    ...
    
    using (ISpan span12 = tracer
        .BuildSpanIgnoreActive("1.2") // Do not add reference "child of" from span "1.2" to the active span "1" automatically.
        .FollowsFrom(tracer.ActiveSpan) // Add a reference "follows from" from span "1.2" to the active span "1" manually.
        .StartNonActive()) // Do not make span "1.2" active automatically. The span "1" remains active.
    {
        ...
        span12.MakeActive(); // Make the span "1.2" active manually.
        tracer.ActiveSpan.SetTag("key2", "value2");
        ...
    } // The span "1.2" is not anymore active. Span "1" is active again.
    
    ...
    
} // The span "1" is not anymore active. The active span has its previous value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.