Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Traces not visible in Zipkin UI, when open tracing is used #95

Closed
debashish2014 opened this issue Jul 3, 2019 · 7 comments · Fixed by #131
Closed

Traces not visible in Zipkin UI, when open tracing is used #95

debashish2014 opened this issue Jul 3, 2019 · 7 comments · Fixed by #131
Labels
bug Something isn't working

Comments

@debashish2014
Copy link

Hi,

I have written below code, to see if the opentracing api can be used with this driver. It does not seem to work as I don't see anything in the Zipkin UI. However, the sample code shown in the Readme works perfectly fine.

Am I missing anything?

using OpenTracing;
using OpenTracing.Tag;
using Petabridge.Tracing.Zipkin;
using System;

namespace Zipkin.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var url = "http://localhost:9411";
            var tracer = new ZipkinTracer(new ZipkinTracerOptions(url, "ZipkinTest", debug: true));

            Console.WriteLine("Connected to Zipkin at {0}", url);
 
            using (IScope scope = tracer.BuildSpan("someWork").StartActive(finishSpanOnDispose: true))
            {
                try
                {
                    scope.Span.Log("some work");
                }
                catch (Exception ex)
                {
                    Tags.Error.Set(scope.Span, true);
                }
            }

            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));
        }
    }
}

@Aaronontheweb
Copy link
Member

We use the OpenTracing API for this heavily in https://phobos.petabridge.com - it works. Might be a configuration issue - are you still having this issue?

@bastijnv
Copy link

bastijnv commented Jan 28, 2020

Having the same issue. Seems the using(){} with finish on dispose is not functioning as expected. Running the same code but using span.Start() and span.Finish() works.

@Aaronontheweb
Copy link
Member

Dispose on the Span object itself calls Finish

public void Dispose()
{
Finish();
}

Maybe the issue is what's happening inside the Scope object - I don't believe we have a reproduction for that, so we can take a look.

@bastijnv
Copy link

bastijnv commented Jan 28, 2020

Yes. My bad. Using statement has nothing to do with it. Indeed when using scopes via StartActive() it will no longer send traces. Another strange thing is that when I switch sample code to


var sb = _tracer.BuildSpan("no-op").WithTag("empty", true);
var span = sb.Start();
await Task.Delay(1000);
span.Finish();

on a simple GET method it will keep sending spans indefinitely cycling the same threads while it is not executing/reaching that code block multiple times. Though that seems to be a different issue (if not just my misunderstanding of what happens) and should not pollute this thread.

@IgorFedchenko
Copy link
Contributor

IgorFedchenko commented Jan 29, 2020

@Aaronontheweb @bastijnv
The issue here is that ISpanBuilder.StartActive is using IScopeManager internally so keep track of active span (some details [here[(https://github.com/opentracing/opentracing-csharp#scopes-and-within-process-propagation)). You have to set ScopeManager property of ZipkinTracerOptions to have StartActive working.

Currently there is no built-in implementation of IScopeManager in Petabridge.Tracing.Zipkin, except NoopScopeManager class which always returnes NoopSpanBuilder, so basically ISpanBuilder.StartActive resolves to NoopSpan.Instance, which does nothing. That's why nothing is sent to Zipkin.

As a quick solution you might consider using AsyncLocalScopeManager implementation of IScopeManager that is built in OpenTracing package, like this:

 var tracer = new ZipkinTracer(new ZipkinTracerOptions(url, "ZipkinTest", debug: true)
{
    ScopeManager = new AsyncLocalScopeManager()
});

@Aaronontheweb This is not clear from README, but what do you think about using AsyncLocalScopeManager as a default scope manager instead of NoopScopeManager? This may help people have this StartActive method working out of the box.
If you agree, I will submit small PR for that, with reproducing spec

@Aaronontheweb
Copy link
Member

Aaronontheweb commented Jan 29, 2020 via email

@Aaronontheweb
Copy link
Member

So the reason why I never ran into this bug - Phobos sets up a scope manager by default in its configuration. This is definitely an issue on our end.

@Aaronontheweb Aaronontheweb added the bug Something isn't working label Jan 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
4 participants