(filePath, metadata)
| 81 | * Read generated trace from file system, augment & sent it to the remote tracer. |
| 82 | */ |
| 83 | const collectTraces = async (filePath, metadata) => { |
| 84 | const tracer = Tracer.init({ |
| 85 | tags: metadata, |
| 86 | // Setting external env variable `DD_TRACE_DEBUG=true` will emit this log |
| 87 | logLevel: 'error', |
| 88 | // TODO: this is due to generated trace have excessive numbers of spans |
| 89 | // for build-module-*, using default flush causes overflow to the agent. |
| 90 | flushInterval: 20, |
| 91 | flushMinSpans: 10, |
| 92 | }) |
| 93 | |
| 94 | const readLineInterface = createInterface({ |
| 95 | input: createReadStream(filePath), |
| 96 | crlfDelay: Infinity, |
| 97 | }) |
| 98 | |
| 99 | const traces = new Map() |
| 100 | const rootTraces = [] |
| 101 | |
| 102 | // Input trace file contains newline-separated sets of traces, where each line is valid JSON |
| 103 | // type of Array<TraceEvent>. Read it line-by-line to manually reconstruct trace trees. |
| 104 | // |
| 105 | // We have to read through end of the trace - |
| 106 | // Trace events in the input file can appear out of order, so we need to remodel the shape of the span tree before reporting |
| 107 | for await (const line of readLineInterface) { |
| 108 | JSON.parse(line).forEach((trace) => traces.set(trace.id, trace)) |
| 109 | } |
| 110 | |
| 111 | // Link inner, child spans to the parents to reconstruct span with correct relations |
| 112 | for (const event of traces.values()) { |
| 113 | if (event.parentId) { |
| 114 | event.parent = traces.get(event.parentId) |
| 115 | if (event.parent) { |
| 116 | if (!event.parent.children) event.parent.children = [] |
| 117 | event.parent.children.push(event) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if (!event.parent) { |
| 122 | rootTraces.push(event) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | for (const trace of rootTraces) { |
| 127 | reportSpanRecursively(tracer, trace) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Naively validate, collect necessary args. |
no test coverage detected