by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Daniel Dyla
    @dyladan
    ah, in that case your options in the browser are limited from an automatic-tracing point of view
    you could try the stack context manager which is the default in the web
    Henrik Feldt
    @haf
    And how do I set the active span there?
    Daniel Dyla
    @dyladan
    but it is very limited in async contexts
    Henrik Feldt
    @haf
    I don't care much about having callbacks spawning children
    I really only care they are associated with my parent span
    Daniel Dyla
    @dyladan
    You create a context by using the helper functions from @opentelemetry/core like setActiveSpan.
    const span = startSpan(); api.context.with(setActiveSpan(span, api.context.active()), () => {/* do something */});
    Henrik Feldt
    @haf
    What does 'setActiveSpan' do?
    Why doesn't tracer.startSpan set it?
    And what if I don't have the callback available when I use context to set it?
    Do I just use setActiveSpan then?
    image.png
    image.png
    It would seem there's no Liskov substitution possible here either.
    Doesn't work.
    :(
    Daniel Dyla
    @dyladan
    You have to change setActiveSpan(context, span) to setActiveSpan(context.active(), span)
    Also, all that does is create a new context with the span active, so you have to use the context API to propagate that new context
    Henrik Feldt
    @haf
    Isn't it better to override the tracer and keep the getCurrentSpan returning the parent span?
    If the user wants to chain into a child span, surely they'll pass the parent?
    What of the stacked contexts then?
    Daniel Dyla
    @dyladan
    const ctx = setActiveSpan(context.active(), span);
    context.with(ctx, () => { /* do something */ });
    Henrik Feldt
    @haf
    But I don't want to use with, because I don't have the callback available; I'm writing a library
    Daniel Dyla
    @dyladan
    I think without knowing more about your usecase I can't provide useful advice
    i'm not sure what you mean by not having the callback available: you can call the user callback in that do something block and the context will be active in the user's callback
    I assume the user will provide you with some sort of callback
    also, if you're writing a library, you don't have to worry about setting the context manager. that will be done by your end users
    Bartlomiej Obecny
    @obecny
    if you are writing your own library with different needs then just write your own context manager where you have full control of everything
    Henrik Feldt
    @haf
    Is context.active a shortcut to the global singleton context manager? Is the invariant that there's always an active context?
    Daniel Dyla
    @dyladan
    yes and yes
    Henrik Feldt
    @haf
    My use-case is really not that special; I want a globally active root span at all times.
    Which I can cycle when I change pages
    Daniel Dyla
    @dyladan
    if no active context has been set, then the context is the "root" context
    which is empty
    Henrik Feldt
    @haf
    Am I supposed to use an interface from core, or an object model from core, or the api implementations? Which are replaceable? Can I use either and still use the plugins?
    Daniel Dyla
    @dyladan
    for context? The api exports a context implementation which is a concrete class, but there is a PR open right now to make context just an interface
    Henrik Feldt
    @haf
    I'm thinking I would like to use the fetch/xhr plugins and have them automatically chain off of my page span
    Thanks for taking the time to answer my questions
    What are the globals? Can any plugin change any global value?
    Not just for context; also Span and SpanContext seem to have duplicate definitions in both api and core and then there's also tracing
    Daniel Dyla
    @dyladan
    As a library author you should only be depending on the API
    your end users can choose or not choose to use an SDK
    tracing is an SDK implementation of the Tracing API
    the implementations in core are likely left over from a previous refactor. i'll look into removing them to avoid confusion
    Henrik Feldt
    @haf
    Ah, I think I'm on the edge there. It's a library for an APM product, so I need to instantiate actual e.g. processors. But I would like a data model for Spans that keeps track of how long the Span has been running. One that is not just an interface, but an implementation. Is API the place to look?
    Henrik Feldt
    @haf
    In fact; here it is: https://github.com/logary/logary-js/blob/master/README.md if you'd like to see how I'm trying to do it (the browser and node plugins in particular)
    Naseem
    @naseemkullah
    Any common causes for "You can only call end() on a span once." ?
    A service seems to get them every so often and I see no obvious clues from logs immediately before or after.
    legendecas
    @legendecas

    Any common causes for "You can only call end() on a span once." ?
    A service seems to get them every so often and I see no obvious clues from logs immediately before or after.

    The span will be sent to SpanProcessor on the call of end(). If the end was called multiple times, there will be no feasible approach to determine the time to send the span to SpanProcessor hence to Exporters AFAICT.

    1 reply
    Pedro Deodato
    @pedrodeodato

    Hello, all! Again struggling with Spans covering two processes (JS and C#), with Jaeger... Both sides are instrumented, and Jaeger shows all the spans but the span that covers the request from the JS to the C# is shown in a different trace... On a JS trace I see the client-side spans just fine, with a huge time where "nothing happens" (in fact, request is being processed) and on another JS trace I see the request (starting on the C#, passing through every instrumented bit in C# and returning to JS - so, context propagation should be fine). My trace configuration code is:

    window._opentelemetry = require('@opentelemetry/api');
    window._tracing = require("@opentelemetry/tracing");
    window._core = require("@opentelemetry/core");
    window._zipkin = require('@opentelemetry/exporter-zipkin');
    window._xhr = require('@opentelemetry/plugin-xml-http-request');
    window._web = require('@opentelemetry/web');
    window._zone = require('@opentelemetry/context-zone');
    window._document = require('@opentelemetry/plugin-document-load');
    
    const providerWithZone = new window._web.WebTracerProvider({
      plugins: [
        //new window._document.DocumentLoad(),
        new window._xhr.XMLHttpRequestPlugin({
          propagateTraceHeaderCorsUrls: ['http://localhost:8090']
        })
      ]
    });
    
    const options = {
      url: 'http://localhost:8888/http://host.docker.internal:9411/api/v2/spans',
      serviceName: 'testJaegerJS'
    }
    window.zipkinExporter = new window._zipkin.ZipkinExporter(options);
    
    providerWithZone.addSpanProcessor(new window._tracing.BatchSpanProcessor(window.zipkinExporter));
    
    providerWithZone.register({
      contextManager: new window._zone.ZoneContextManager(),
    });
    
    window.zipkinTracer = window._tracing.getTracer();
    window.span2 = window.zipkinTracer.startSpan('main');
    
    // Right here the request is sent, processed by the C#, returned to the JS side and then:
    
    var childSpan = window.zipkinTracer.startSpan('child', {
        parent: window.span2
    });
    
    childSpan.end();
    window.span2.end();

    My problem is that my "main" span only shows "main" and "child" ... all the request activity, including the spans from the C# are shown on a different trace, called "HTTP POST" (no idea where this came from...)! Any hints? My idea is that the span that the request carries with it is gathered from a different tracer than my "window.zipkinTracer", as that would explain a separate trace on Jaeger, just for the request... If so, how can I use that tracer to also start my spans ("main" and "child"), so that all of them are presented in a single trace on Jaeger?? Thanks again for all the help!