0
votes

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.

1

1 Answers

0
votes

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