0

When nesting spans in Elsatic APM through either the Opentracing API or Elastic APM's API. Some spans are never recorded.

Using import * as apm from '@elastic/apm-rum';:

const transaction = this.apm.startTransaction('transaction-scene-loaded', 'custom'); // recorded
const span = this.apm.startSpan('span-scene-loaded', 'custom'); // recorded
const span2 = this.apm.startSpan('span-loading-state-updated', 'custom'); // Not recorded

span2.end();
span.end();
transaction.end();

Using Elastic's OpenTracing API:

const {
  init: initApm,
  createTracer
} = require('@elastic/apm-rum/dist/bundles/elastic-apm-opentracing.umd.js');

The behavior for spans are just as inconsistent. It is unclear when a transaction begins or ends. Some spans are translated into transactions, and nested spans may not be recorded. If I declare a page wide transaction, Angular's ngOnInit can be recorded by a span, but other event hooks are never recorded.

onLoaded() {
  const span = this.tracer.startSpan('span-scene-loaded'); // Not recorded
  // ...
  span.end();
}

I have tried variations of this. Wrapping span in span, childOf, app-level span, individual instances of span.

Dan
  • 2,455
  • 3
  • 19
  • 53

1 Answers1

0

To include spans into the transactions you should start the spans from the transaction object

...
var span = transaction.startSpan('My custom span')
...

And ending the parent transaction object all the nested spans will be also ended in cascade

https://www.elastic.co/guide/en/apm/agent/js-base/4.x/transaction-api.html#transaction-start-span

Andoni
  • 171
  • 9
  • Tested this with `transaction.startSpan`. Now an entire transaction is missing. `const transaction = this.apm.startTransaction('transaction-scene-loaded', 'custom'); const span = transaction.startSpan('span-scene-loaded');` Nested spans are a separate issue. It seems like we cannot nest spans with this Elastic's API? – Dan Jul 31 '19 at 21:19
  • You have to end() the transaction to let the library is ready to be sent. You can create several spans in the same transaction, but they cannot be nested. They will be shown in this way: https://images.contentstack.io/v3/assets/bltefdd0b53724fa2ce/blt2017694f3195a750/5cb8428dc5f3a89f49185119/sip-of-rum-5.jpg – Andoni Jul 31 '19 at 21:33
  • `end()` has been called, but I omitted it here because of the spacing. I tried a few variations here as well. End span then transaction, just the transaction, on timeout, on destroy, on before unload. Some transactions and some spans are recorded, but nested spans are not always recorded. Some transactions and spans are never recorded, even through the code block ran. – Dan Jul 31 '19 at 22:30