Repository: honeycombio/beeline-nodejs
Pull request #455 (2021-09-20 07:01:31)

Bump prettier from 2.4.0 to 2.4.1
Bumps [prettier](https://github.com/prettier/prettier) from 2.4.0 to 2.4.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/prettier/prettier/releases">prettier's releases</a>.</em></p>
<blockquote>
<h2>2.4.1</h2>
<p>🔗 <a href="https://github.com/prettier/prettier/blob/main/CHANGELOG.md#241">Changelog</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/prettier/prettier/blob/main/CHANGELOG.md">prettier's changelog</a>.</em></p>
<blockquote>
<h1>2.4.1</h1>
<p><a href="https://github.com/prettier/prettier/compare/2.4.0...2.4.1">diff</a></p>
<h4>Fix wildcard syntax in <code>@forward</code> (<a href="https://github-redirect.dependabot.com/prettier/prettier/pull/11482">#11482</a>) (<a href="https://github-redirect.dependabot.com/prettier/prettier/pull/11487">#11487</a> by <a href="https://github.com/niksy"><code>@​niksy</code></a>)</h4>
<!-- raw HTML omitted -->
<pre lang="scss"><code>// Input
@forward &quot;library&quot; as btn-*;
<p>// Prettier 2.4.0
<a href="https://github.com/forward"><code>@​forward</code></a> &quot;library&quot; as btn- *;</p>
<p>// Prettier 2.4.1
<a href="https://github.com/forward"><code>@​forward</code></a> &quot;library&quot; as btn-*;
</code></pre></p>
<h4>Add new CLI option <code>debug-print-ast</code> (<a href="https://github-redirect.dependabot.com/prettier/prettier/pull/11514">#11514</a> by <a href="https://github.com/sosukesuzuki"><code>@​sosukesuzuki</code></a>)</h4>
<p>A new <code>--debug-print-ast</code> CLI flag for debugging.</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/prettier/prettier/commit/7ced9e66549b8d5a8e3a74473af462f86fb0245c"><code>7ced9e6</code></a> Release 2.4.1</li>
<li><a href="https://github.com/prettier/prettier/commit/59b5eb4e1faf912dd46759c98b45cfe5807e7a9f"><code>59b5eb4</code></a> Fix wildcard syntax in <code>@forward</code> (<a href="https://github-redirect.dependabot.com/prettier/prettier/issues/11482">#11482</a>) (<a href="https://github-redirect.dependabot.com/prettier/prettier/issues/11487">#11487</a>)</li>
<li><a href="https://github.com/prettier/prettier/commit/aa63269743e510ed1eaedaa4e9465430c9ff807d"><code>aa63269</code></a> Add new CLI option <code>debug-print-ast</code> (<a href="https://github-redirect.dependabot.com/prettier/prettier/issues/11514">#11514</a>)</li>
<li><a href="https://github.com/prettier/prettier/commit/ae33e494a91ced3e80f139ca075cb27bc645acb2"><code>ae33e49</code></a> fix(docs): lint-staged install instructions (<a href="https://github-redirect.dependabot.com/prettier/prettier/issues/11363">#11363</a>)</li>
<li><a href="https://github.com/prettier/prettier/commit/a1a7502f4f77498d24085862e9fd40f46c056f1e"><code>a1a7502</code></a> Update integrating-with-linters.md (<a href="https://github-redirect.dependabot.com/prettier/prettier/issues/11399">#11399</a>)</li>
<li><a href="https://github.com/prettier/prettier/commit/f63e15d1cd37167984dc329a34fc050343e3a91b"><code>f63e15d</code></a> Build(deps): Bump typescript from 4.4.2 to 4.4.3 (<a href="https://github-redirect.dependabot.com/prettier/prettier/issues/11507">#11507</a>)</li>
<li><a href="https://github.com/prettier/prettier/commit/dec24722d65ea45afcf63af30857bea35ade4ed5"><code>dec2472</code></a> Build(deps-dev): Bump <code>@​babel/preset-env</code> from 7.15.4 to 7.15.6 (<a href="https://github-redirect.dependabot.com/prettier/prettier/issues/11499">#11499</a>)</li>
<li><a href="https://github.com/prettier/prettier/commit/ac3912cd4725b104290c8b1b95b801bbdfcce404"><code>ac3912c</code></a> Build(deps-dev): Bump eslint-plugin-unicorn from 35.0.0 to 36.0.0 (<a href="https://github-redirect.dependabot.com/prettier/prettier/issues/11504">#11504</a>)</li>
<li><a href="https://github.com/prettier/prettier/commit/bf5a027794316f3df2ea47dd06cee2f22940a735"><code>bf5a027</code></a> Revert workaround for node 16.9 (<a href="https://github-redirect.dependabot.com/prettier/prettier/issues/11493">#11493</a>)</li>
<li><a href="https://github.com/prettier/prettier/commit/ddee8dbaaecac095c9e2951bd6a1bddfb60fdfeb"><code>ddee8db</code></a> Build(deps): Bump espree from 8.0.0 to 9.0.0 (<a href="https://github-redirect.dependabot.com/prettier/prettier/issues/11509">#11509</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/prettier/prettier/compare/2.4.0...2.4.1">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=prettier&package-manager=npm_and_yarn&previous-version=2.4.0&new-version=2.4.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/lib/api/libhoney.js b/lib/api/libhoney.js
index 5083b08..675b671 100644
--- a/lib/api/libhoney.js
+++ b/lib/api/libhoney.js
@@ -290,7 +290,7 @@ module.exports = class LibhoneyEventAPI {
       // valid, since we can end up in our instrumentation outside of requests we're tracking
       return;
     }
-    Object.assign(context.stack[0].payload, map);
+    Object.assign(context.stack[context.stack.length - 1].payload, map);
   }
 
   /**
@@ -302,7 +302,7 @@ module.exports = class LibhoneyEventAPI {
       // valid, since we can end up in our instrumentation outside of requests we're tracking
       return;
     }
-    delete context.stack[0].payload[key];
+    delete context.stack[context.stack.length - 1].payload[key];
   }
 
   addTraceContext(map) {
diff --git a/lib/api/mock.js b/lib/api/mock.js
index 5a528ec..27424df 100644
--- a/lib/api/mock.js
+++ b/lib/api/mock.js
@@ -85,7 +85,7 @@ module.exports = class MockEventAPI {
     if (!context || context.stack.length === 0) {
       return;
     }
-    Object.assign(context.stack[0], map);
+    Object.assign(context.stack[context.stack.length - 1], map);
   }
 
   /**
@@ -93,7 +93,7 @@ module.exports = class MockEventAPI {
    */
   removeContext(key) {
     let context = tracker.getTracked();
-    delete context.stack[0].payload[key];
+    delete context.stack[context.stack.length - 1].payload[key];
   }
 
   addTraceContext(map) {
diff --git a/lib/instrumentation/trace-util.js b/lib/instrumentation/trace-util.js
index f640a37..d884ce4 100644
--- a/lib/instrumentation/trace-util.js
+++ b/lib/instrumentation/trace-util.js
@@ -59,9 +59,7 @@ exports.getTraceContext = (traceIdSource, req) => {
   const { honeycomb, aws } = api;
   if (typeof traceIdSource === "undefined" || typeof traceIdSource === "string") {
     let headers =
-      typeof traceIdSource === "undefined"
-        ? [honeycomb.TRACE_HTTP_HEADER, "X-Request-ID", aws.TRACE_HTTP_HEADER]
-        : [traceIdSource];
+      typeof traceIdSource === "undefined" ? [honeycomb.TRACE_HTTP_HEADER] : [traceIdSource];
     let valueAndHeader = getValueFromHeaders(req.headers, headers);
 
     if (!valueAndHeader) {
diff --git a/package-lock.json b/package-lock.json
index 3ffa1c4..6100608 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6,7 +6,7 @@
   "packages": {
     "": {
       "name": "honeycomb-beeline",
-      "version": "2.8.0",
+      "version": "2.8.1",
       "license": "Apache-2.0",
       "dependencies": {
         "@opentelemetry/api": "^1.0.2",
@@ -6873,9 +6873,9 @@
       }
     },
     "node_modules/prettier": {
-      "version": "2.4.0",
-      "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.0.tgz",
-      "integrity": "sha512-DsEPLY1dE5HF3BxCRBmD4uYZ+5DCbvatnolqTqcxEgKVZnL2kUfyu7b8pPQ5+hTBkdhU9SLUmK0/pHb07RE4WQ==",
+      "version": "2.4.1",
+      "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.1.tgz",
+      "integrity": "sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==",
       "dev": true,
       "bin": {
         "prettier": "bin-prettier.js"
@@ -13689,9 +13689,9 @@
       "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ="
     },
     "prettier": {
-      "version": "2.4.0",
-      "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.0.tgz",
-      "integrity": "sha512-DsEPLY1dE5HF3BxCRBmD4uYZ+5DCbvatnolqTqcxEgKVZnL2kUfyu7b8pPQ5+hTBkdhU9SLUmK0/pHb07RE4WQ==",
+      "version": "2.4.1",
+      "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.1.tgz",
+      "integrity": "sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==",
       "dev": true
     },
     "pretty-format": {


Test patch:
diff --git a/lib/api/index.test.js b/lib/api/index.test.js
index b7d4e0f..b4f4b2a 100644
--- a/lib/api/index.test.js
+++ b/lib/api/index.test.js
@@ -648,6 +648,76 @@ test("async spans share custom context", () => {
   expect(asyncData["app.custom"]).toBe("value");
 });
 
+test("addContext works on the current span", () => {
+  const honey = api._apiForTesting().honey;
+
+  let parentSpan = api.startTrace({ name: "parent" });
+  api.addContext({ field: "a" });
+
+  let childSpan = api.startSpan({ name: "child" });
+  api.addContext({ field: "b" });
+
+  let grandchildSpan = api.startSpan({ name: "grandchild" });
+  api.addContext({ field: "c" });
+
+  api.finishSpan(grandchildSpan);
+  api.finishSpan(childSpan);
+  api.finishTrace(parentSpan);
+
+  expect(honey.transmission.events.length).toBe(3);
+
+  let parentEvent = honey.transmission.events[2].postData;
+  let childEvent = honey.transmission.events[1].postData;
+  let grandchildEvent = honey.transmission.events[0].postData;
+
+  expect(parentEvent["name"]).toBe("parent");
+  expect(childEvent["name"]).toBe("child");
+  expect(grandchildEvent["name"]).toBe("grandchild");
+
+  expect(parentEvent["field"]).toBe("a");
+  expect(childEvent["field"]).toBe("b");
+  expect(grandchildEvent["field"]).toBe("c");
+});
+
+test("removeContext works on the current span", () => {
+  const honey = api._apiForTesting().honey;
+
+  let parentSpan = api.startTrace({ name: "parent" });
+  api.addContext({ a: 1, b: 2 });
+  api.removeContext("b");
+
+  let childSpan = api.startSpan({ name: "child" });
+  api.addContext({ b: 2, c: 3 });
+  api.removeContext("c");
+
+  let grandchildSpan = api.startSpan({ name: "grandchild" });
+  api.addContext({ c: 3, d: 4 });
+  api.removeContext("d");
+
+  api.finishSpan(grandchildSpan);
+  api.finishSpan(childSpan);
+  api.finishTrace(parentSpan);
+
+  expect(honey.transmission.events.length).toBe(3);
+
+  let parentEvent = honey.transmission.events[2].postData;
+  let childEvent = honey.transmission.events[1].postData;
+  let grandchildEvent = honey.transmission.events[0].postData;
+
+  expect(parentEvent["name"]).toBe("parent");
+  expect(childEvent["name"]).toBe("child");
+  expect(grandchildEvent["name"]).toBe("grandchild");
+
+  expect(parentEvent["a"]).toBe(1);
+  expect(parentEvent["b"]).toBeUndefined();
+
+  expect(childEvent["b"]).toBe(2);
+  expect(childEvent["c"]).toBeUndefined();
+
+  expect(grandchildEvent["c"]).toBe(3);
+  expect(grandchildEvent["d"]).toBeUndefined();
+});
+
 describe("presend hook", () => {
   it("calls the presend hook function if provided", () => {
     const mockPresendHook = jest.fn();