From 6072dcf11c93975fe11c17884f8420887b4cdcc7 Mon Sep 17 00:00:00 2001 From: javibookline <98887695+javibookline@users.noreply.github.com> Date: Thu, 31 Mar 2022 13:13:12 +0200 Subject: [PATCH] Add span parameter to Task.getTracingPropagation. Pass proper span to getTracingPropagation calls in Task methods to propagate the proper spanId (#91) --- lib/tasks/task.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/tasks/task.js b/lib/tasks/task.js index 28593a4a..ebe8d087 100644 --- a/lib/tasks/task.js +++ b/lib/tasks/task.js @@ -90,8 +90,11 @@ class Task extends Emitter { return {span, ctx}; } - getTracingPropagation(encoding) { + getTracingPropagation(encoding, span) { // TODO: support encodings beyond b3 https://github.com/openzipkin/b3-propagation + if (span) { + return `${span.spanContext().traceId}-${span.spanContext().spanId}-1`; + } if (this.span) { return `${this.span.spanContext().traceId}-${this.span.spanContext().spanId}-1`; } @@ -137,9 +140,9 @@ class Task extends Emitter { async performAction(results, expectResponse = true) { if (this.actionHook) { const params = results ? Object.assign(results, this.cs.callInfo.toJSON()) : this.cs.callInfo.toJSON(); - const b3 = this.getTracingPropagation(); - const httpHeaders = b3 && {b3}; const span = this.startSpan('verb:hook', {'hook.url': this.actionHook}); + const b3 = this.getTracingPropagation('b3', span); + const httpHeaders = b3 && {b3}; span.setAttributes({'http.body': JSON.stringify(params)}); try { const json = await this.cs.requestor.request('verb:hook', this.actionHook, params, httpHeaders); @@ -162,9 +165,9 @@ class Task extends Emitter { } async performHook(cs, hook, results) { - const b3 = this.getTracingPropagation(); - const httpHeaders = b3 && {b3}; const span = this.startSpan('verb:hook', {'hook.url': hook}); + const b3 = this.getTracingPropagation('b3', span); + const httpHeaders = b3 && {b3}; span.setAttributes({'http.body': JSON.stringify(results)}); try { const json = await cs.requestor.request('verb:hook', hook, results, httpHeaders);