From 1f487995a90ef961af83ffcf4affc6a6223004e8 Mon Sep 17 00:00:00 2001 From: Alan Storm Date: Wed, 11 May 2022 14:36:16 -0700 Subject: [PATCH 1/3] feat: setRecorded for traceparent/tracecontext --- lib/tracecontext/index.js | 4 ++++ lib/tracecontext/traceparent.js | 14 ++++++++++++-- test/tracecontext/traceparent.test.js | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/tracecontext/index.js b/lib/tracecontext/index.js index 83274ae49e..f37ef21a56 100644 --- a/lib/tracecontext/index.js +++ b/lib/tracecontext/index.js @@ -82,6 +82,10 @@ class TraceContext { setter(carrier, 'tracestate', tracestate) } } + + setRecorded () { + return this.traceparent.setRecorded() + } } TraceContext.FLAGS = TraceParent.FLAGS diff --git a/lib/tracecontext/traceparent.js b/lib/tracecontext/traceparent.js index 8a9cf86227..e38258a8a0 100644 --- a/lib/tracecontext/traceparent.js +++ b/lib/tracecontext/traceparent.js @@ -107,8 +107,10 @@ class TraceParent { constructor (buffer) { this[bufferSymbol] = buffer Object.defineProperty(this, 'recorded', { - value: !!(buffer[OFFSETS.flags] & FLAGS.recorded), - enumerable: true + enumerable: true, + get: function () { + return !!(this[bufferSymbol][OFFSETS.flags] & FLAGS.recorded) + } }) defineLazyProp(this, 'version', hexSliceFn(buffer, OFFSETS.version, OFFSETS.traceId)) @@ -144,6 +146,14 @@ class TraceParent { return makeChild(Buffer.from(this[bufferSymbol])) } + setRecorded (value) { + if (value) { + this[bufferSymbol][OFFSETS.flags] |= FLAGS.recorded + } else { + this[bufferSymbol][OFFSETS.flags] &= ~FLAGS.recorded + } + } + toString () { return `${this.version}-${this.traceId}-${this.id}-${this.flags}` } diff --git a/test/tracecontext/traceparent.test.js b/test/tracecontext/traceparent.test.js index c25b21f3c5..77ce275ff7 100644 --- a/test/tracecontext/traceparent.test.js +++ b/test/tracecontext/traceparent.test.js @@ -176,3 +176,17 @@ test('ensureParentId', t => { t.end() }) + +test('setRecorded', t => { + const traceParent = TraceParent.fromString(header) + + t.ok(traceParent.recorded) + + traceParent.setRecorded(false) + t.ok(!traceParent.recorded) + + traceParent.setRecorded(true) + t.ok(traceParent.recorded) + + t.end() +}) From d2515f1fa995800b4fbc0f1aa73f39c9df2954bd Mon Sep 17 00:00:00 2001 From: Alan Storm Date: Wed, 11 May 2022 14:43:55 -0700 Subject: [PATCH 2/3] fix: CHANGELOG --- CHANGELOG.asciidoc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index f4582a8685..8bd9f6842d 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -28,6 +28,18 @@ Notes: [[release-notes-3.x]] === Node.js Agent version 3.x +==== Unreleased + +[float] +===== Breaking changes + +[float] +===== Features + +- Added a `setRecorded` method to the TraceParent class. ({pull}2687[#2687]) + +[float] +===== Bug fixes [[release-notes-3.33.0]] ==== 3.33.0 2022/05/05 From 1eadbb87a835495fa3b21f5e83f9f098ac1cb606 Mon Sep 17 00:00:00 2001 From: Alan Storm Date: Thu, 12 May 2022 08:51:46 -0700 Subject: [PATCH 3/3] fix: remove privateish api --- CHANGELOG.asciidoc | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 8bd9f6842d..e134becb77 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -28,19 +28,6 @@ Notes: [[release-notes-3.x]] === Node.js Agent version 3.x -==== Unreleased - -[float] -===== Breaking changes - -[float] -===== Features - -- Added a `setRecorded` method to the TraceParent class. ({pull}2687[#2687]) - -[float] -===== Bug fixes - [[release-notes-3.33.0]] ==== 3.33.0 2022/05/05