UNPKG

pinpoint-node-agent

Version:
60 lines (49 loc) 1.41 kB
/** * Pinpoint Node.js Agent * Copyright 2020-present NAVER Corp. * Apache License v2.0 */ 'use strict' const SpanEventBuilder = require('./span-event-builder') const SpanEventRecorder = require('./span-event-recorder2') /** * DefaultCallStack.java in Java agent */ class CallStack { constructor(traceRoot) { this.traceRoot = traceRoot this.stack = [] this.sequence = 0 this.depth = 1 } makeSpanEventRecorder(stackId) { const recorder = new SpanEventRecorder(SpanEventBuilder.make(stackId), this.traceRoot) this.push(recorder.getSpanEventBuilder()) return recorder } push(spanEventBuilder) { if (spanEventBuilder.needsSequence()) { spanEventBuilder.setSequence(this.sequence++) } if (spanEventBuilder.needsDepth()) { spanEventBuilder.setDepth(this.depth++) } this.stack.push(spanEventBuilder) } // pop in java agent pop(builder) { const index = this.stack.findIndex(item => item === builder) if (index < 0) { return } this.depth-- if (index < this.stack.length - 1) { return this.stack.splice(index, 1)[0] } return this.stack.pop() } getByStackId(stackId) { return this.stack.find(item => item.stackId === stackId) } } module.exports = CallStack