Skip to content

Commit

Permalink
chore: add debug statements for OTel
Browse files Browse the repository at this point in the history
  • Loading branch information
NeuralFlux committed Oct 3, 2024
1 parent 555e7ee commit aa83d8c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/controllers/opentelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ const sdk = new NodeSDK({
[ATTR_SERVICE_NAME]: "biothings-explorer",
}),
});
debug(`OTel URL ${process.env.JAEGER_HOST ?? 'jaeger-otel-collector'}:${process.env.JAEGER_PORT ?? 4318}/v1/traces`);
sdk.start();
debug("Opentelemetry instrumentation initialized.");
2 changes: 2 additions & 0 deletions src/controllers/threading/taskHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ async function runTask({
});

let activeContext: Context = propagation.extract(context.active(), { traceparent, tracestate });
debug(`OTel task ${traceparent} and ${tracestate}`);
let tracer = trace.getTracer("biothings-explorer-thread")
span = tracer.startSpan(
routeNames[route],
{kind: 1}, // specifies internal span
activeContext,
);
debug(`OTel span created ${span}`);

span.setAttribute("bte.requestData", JSON.stringify(req.data.queryGraph));
Telemetry.setOtelSpan(span);
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/threading/threadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,15 @@ export async function runTask(req: Request, res: Response, route: string, useBul
taskInfo.data.options.caching = false;
}

debug(`OTel ${traceparent} and ${tracestate}`);
if (process.env.USE_THREADING === "false") {
// Threading disabled, just use the provided function in main event loop
debug("OTel enter no threading")
const response = (await tasks[route](taskInfo)) as TrapiResponse;
return response;
} else if (!(queryQueue && useBullSync)) {
// Redis unavailable or query not to sync queue such as asyncquery_status
debug("OTel enter queueTaskToWorkers")
const response = await queueTaskToWorkers(
useBullSync ? global.threadpool.sync : global.threadpool.misc,
taskInfo,
Expand Down Expand Up @@ -298,6 +301,7 @@ export async function runTask(req: Request, res: Response, route: string, useBul
throw new ServerOverloadedError(message, expectedWaitTime);
}

debug("OTel enter queryQueue.add")
const job = await queryQueue.add(taskInfo.data, jobOpts);
try {
const response: TrapiResponse = await (job.finished() as Promise<TrapiResponse>);
Expand Down

0 comments on commit aa83d8c

Please sign in to comment.