question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Traces not being emitted for custom instrumentation

See original GitHub issue

Trying to get our APM going with some custom and agent woven instrumentation using a GlobalTracer, running in Java 8 on undertow servlet container. Our custom code is very similar to the example code:

...
        Tracer tracer = GlobalTracer.get();

        Scope scope = tracer.buildSpan("operation-name").startActive(true);
        try {
            scope.span().setTag(DDTags.SERVICE_NAME, "my-new-service");

            // The code you're tracing
            Thread.sleep(1000);

        // If you don't call close(), the span data will NOT make it to Datadog!
        } finally {
            scope.close();
        }
...

But these custom events never appear in the APM UI, or the logs via LoggingWriter. Digging into your tracing code, it appears write() is never being called for these traces in the expireReference method.

  private void expireReference() {
    final int count = pendingReferenceCount.decrementAndGet();
    if (count == 0) {
      write();
    }
    log.debug("traceId: {} -- Expired reference. count = {}", traceId, count);
  }

because the pendingReferenceCount is always greater than 1 for custom traces, but it is 0 for agent woven instrumentation. Its not clear to me what this counter is aiming to achieve or how / when it gets incremented. Is this style of tracing (custom and auto agent) supported? Are there any gotchas? From the docs it looks like I only have to make sure to call close() on the span and things should work, as per the code close() is definitely being called, but ends up in the expireReferences method in PendingTrace.java and never gets written out.

I can see the counter gets incremented in registerContinuation and registerSpan, and we are running in a servlet container so continuations are possible, I’m not sure what to try next.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nhoughtocommented, Sep 5, 2018

Repro test could be hard, will need to unpick it from the rest of the app 😢

I’ll put it on the list and see how hard it is, we are blocked by #429 anyway atm.

0reactions
randomandersoncommented, Oct 24, 2019

Closing as there has been no activity on this issue in over a year. Please create a new issue if the problem still persists.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting: Not seeing transaction traces
Problem. You do not see transaction traces in the APM UI. Solution. If you are not seeing a transaction trace in APM, there...
Read more >
APM Troubleshooting - Datadog Docs
Confirm APM setup and Agent status. During startup, Datadog tracing libraries emit logs that reflect the configurations applied in a JSON object, as...
Read more >
Guide to Instrumentation with OpenTracing and Jaeger | Logz.io
Every journey in distributed tracing starts with instrumenting an application to emit or extract trace data from each service as they execute. There...
Read more >
tracing - Rust - Docs.rs
It signifies something that happened while a trace was being recorded. Event s are comparable to the log records emitted by unstructured logging...
Read more >
4. Best Practices for Instrumentation - Distributed Tracing in ...
Best practices do not exist in a vacuum. The data your instrumentation generates will be collected by a trace analysis system, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found