diff --git a/src/index.ts b/src/index.ts index e7ba0d7d..3f7212bd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -529,7 +529,9 @@ export default class TRAPIQueryHandler { const pathfinderHandler = new PathfinderQueryHandler(this.logs, this.queryGraph, this); const pathfinderResponse = await pathfinderHandler.query(); - this.getResponse = () => pathfinderResponse; + if (pathfinderResponse) { + this.getResponse = () => pathfinderResponse; + } } async _handleInferredEdges(): Promise { @@ -625,7 +627,7 @@ export default class TRAPIQueryHandler { 'INFO', null, `Execution Summary: (${KGNodes}) nodes / (${kgEdges}) edges / (${results}) results; (${resultQueries}/${queries}) queries${cached ? ` (${cached} cached qEdges)` : '' - } returned results from(${sources.length}) unique API${sources.length === 1 ? 's' : ''}`, + } returned results from(${sources.length}) unique API ${sources.length === 1 ? 's' : ''}`, ).getLog(), new LogEntry('INFO', null, `APIs: ${sources.join(', ')} `).getLog(), ]; diff --git a/src/inferred_mode/inferred_mode.ts b/src/inferred_mode/inferred_mode.ts index bddd3d38..81ddc655 100644 --- a/src/inferred_mode/inferred_mode.ts +++ b/src/inferred_mode/inferred_mode.ts @@ -645,7 +645,9 @@ export default class InferredQueryHandler { .getSummaryLog(response, response.logs as StampedLog[], resultQueries) .forEach((log) => response.logs.push(log)); } - response.logs = (response.logs as StampedLog[]).map((log) => log.toJSON()); + if (!this.pathfinder) { + response.logs = (response.logs as StampedLog[]).map((log) => log.toJSON()); + } return response; } diff --git a/src/inferred_mode/pathfinder.ts b/src/inferred_mode/pathfinder.ts index 3d8cc815..17a92a7c 100644 --- a/src/inferred_mode/pathfinder.ts +++ b/src/inferred_mode/pathfinder.ts @@ -2,7 +2,7 @@ import TRAPIQueryHandler, { QueryHandlerOptions } from '../index'; import { TrapiResponse, TrapiQEdge, TrapiResult, TrapiQueryGraph, TrapiQNode, TrapiAnalysis } from '../types'; import InferredQueryHandler from './inferred_mode'; import { scaled_sigmoid, inverse_scaled_sigmoid } from '../results_assembly/score'; -import { LogEntry, StampedLog } from '@biothings-explorer/utils'; +import { LogEntry, StampedLog, Telemetry } from '@biothings-explorer/utils'; import Debug from 'debug'; const debug = Debug('bte:biothings-explorer-trapi:pathfinder'); @@ -97,10 +97,15 @@ export default class PathfinderQueryHandler { this.parse(creativeResponse); + // logs + creativeResponse.logs = this.logs.map(log => log.toJSON()); + return creativeResponse; } parse(creativeResponse: TrapiResponse) { + const span = Telemetry.startSpan({ description: 'pathfinderParse' }); + this.originalAnalyses = (creativeResponse as any).original_analyses; delete (creativeResponse as any).original_analyses; @@ -134,7 +139,7 @@ export default class PathfinderQueryHandler { } } - const message1 = '[Pathfinder]: Performing serach for intermediate nodes.'; + const message1 = '[Pathfinder]: Performing search for intermediate nodes.'; debug(message1); this.logs.push(new LogEntry('INFO', null, message1).getLog()); @@ -153,10 +158,14 @@ export default class PathfinderQueryHandler { debug(message2); this.logs.push(new LogEntry('INFO', null, message2).getLog()); + span.finish(); + return creativeResponse; } _searchForIntermediates(creativeResponse: TrapiResponse, dfsNodes: DfsGraph, supportGraphsPerNode: { [node: string]: Set }, kgSrc: string, kgDst: string, kgEdge: string): ResultAuxObject { + const span = Telemetry.startSpan({ description: 'pathfinderIntermediateSearch' }); + // perform dfs const stack = [{ node: kgSrc, path: [kgSrc] }]; const newResultObject: ResultObject = {}; @@ -256,6 +265,8 @@ export default class PathfinderQueryHandler { } } + span.finish(); + return { results: newResultObject, graphs: newAuxGraphs }; } } \ No newline at end of file