Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up child span between threads #14

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/controllers/threading/taskHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ try {
debug(error);
}

const runTask = async ({ req, route, port, job: { jobId, queueName } = {} }) => {
const runTask = async ({ req, route, traceparent, tracestate, port, job: { jobId, queueName } = {} }) => {
debug(`Worker thread ${threadId} beginning ${workerData.queue} task.`);

global.SCHEMA_VERSION = "1.4.0";
Expand Down Expand Up @@ -81,7 +81,7 @@ const runTask = async ({ req, route, port, job: { jobId, queueName } = {} }) =>
scope.setSpan(transaction);
});

span = opentelemetry.trace.getTracer('biothings-explorer-thread').startSpan(routeNames[route])
span = opentelemetry.trace.getTracer('biothings-explorer-thread').startSpan(routeNames[route], undefined, opentelemetry.propagation.extract(opentelemetry.context.active(), {traceparent, tracestate}))
span.setAttribute("bte.requestData", JSON.stringify(req.data.queryGraph));
Telemetry.setOtelSpan(span);
} catch (error) {
Expand Down
10 changes: 9 additions & 1 deletion src/controllers/threading/threadHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { MessageChannel, threadId } = require("worker_threads");
const { context, propagation, trace } = require("@opentelemetry/api");
const debug = require("debug")("bte:biothings-explorer-trapi:threading");
const path = require("path");
// const taskHandler = require("./taskHandler");
Expand Down Expand Up @@ -97,7 +98,14 @@ const queueTaskToWorkers = async (pool, req, route, job) => {
let WorkerThreadID;
const abortController = new AbortController();
const { port1: toWorker, port2: fromWorker } = new MessageChannel();
const taskData = { req, route, port: toWorker };

// get otel context
const otelData = {};
propagation.inject(context.active(), otelData);
const { traceparent, tracestate } = otelData;


const taskData = { req, route, traceparent, tracestate, port: toWorker };
if (job) taskData.job = { jobId: job.id, queueName: job.queue.name };
const task = pool.run(taskData, { signal: abortController.signal, transferList: [toWorker] });
if (job) {
Expand Down
Loading