Skip to content

Commit

Permalink
logs & telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Mar 30, 2024
1 parent f2832f0 commit 286dd47
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down Expand Up @@ -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(),
];
Expand Down
4 changes: 3 additions & 1 deletion src/inferred_mode/inferred_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 13 additions & 2 deletions src/inferred_mode/pathfinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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());

Expand All @@ -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<string> }, kgSrc: string, kgDst: string, kgEdge: string): ResultAuxObject {
const span = Telemetry.startSpan({ description: 'pathfinderIntermediateSearch' });

// perform dfs
const stack = [{ node: kgSrc, path: [kgSrc] }];
const newResultObject: ResultObject = {};
Expand Down Expand Up @@ -256,6 +265,8 @@ export default class PathfinderQueryHandler {
}
}

span.finish();

return { results: newResultObject, graphs: newAuxGraphs };
}
}

0 comments on commit 286dd47

Please sign in to comment.