in lib/instrumentation/index.js [844:903]
Instrumentation.prototype._encodeAndSendSpan = function (span) {
const duration = span.isComposite()
? span.getCompositeSum()
: span.duration();
if (
span.discardable &&
duration / 1000 < this._agent._conf.exitSpanMinDuration
) {
span.transaction.captureDroppedSpan(span);
return;
}
const agent = this._agent;
// Note this error as an "inflight" event. See Agent#flush().
const inflightEvents = agent._inflightEvents;
inflightEvents.add(span.id);
agent.logger.debug('encoding span %o', {
span: span.id,
parent: span.parentId,
trace: span.traceId,
name: span.name,
type: span.type,
});
span._encode(function (err, payload) {
if (err) {
agent.logger.error('error encoding span %o', {
span: span.id,
parent: span.parentId,
trace: span.traceId,
name: span.name,
type: span.type,
error: err.message,
});
} else {
payload = agent._spanFilters.process(payload);
if (!payload) {
agent.logger.debug('span ignored by filter %o', {
span: span.id,
parent: span.parentId,
trace: span.traceId,
name: span.name,
type: span.type,
});
} else {
agent.logger.debug('sending span %o', {
span: span.id,
parent: span.parentId,
trace: span.traceId,
name: span.name,
type: span.type,
});
if (agent._apmClient) {
agent._apmClient.sendSpan(payload);
}
}
}
inflightEvents.delete(span.id);
});
};