Skip to content

Commit

Permalink
Add node/version to the user agent header. (#299)
Browse files Browse the repository at this point in the history
* Add node version to user-agent header. 
* Test expected versions are in the header and that it is in the correct order
  • Loading branch information
emilyashley authored Sep 13, 2022
1 parent e50c0d8 commit 28bf5a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/__tests__/transmission_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,18 @@ describe("base transmission", () => {
dataset: "test-transmission1",
addition: "",
probe: userAgent =>
userAgent.indexOf("libhoney") === 0 &&
// user-agent order: libhoney, node, no addition present
userAgent.indexOf("libhoney-js/<@LIBHONEY_JS_VERSION@>") === 0 &&
userAgent.indexOf(`node/${process.version}`) > 1 &&
userAgent.indexOf("addition") === -1
},
{
dataset: "test-transmission2",
addition: "user-agent addition",
probe: userAgent =>
userAgent.indexOf("libhoney") === 0 &&
userAgent.indexOf("addition") !== -1
// user-agent order: libhoney, addition, node
userAgent.indexOf("libhoney-js/<@LIBHONEY_JS_VERSION@>") === 0 &&
userAgent.indexOf("addition") < userAgent.indexOf(`node/${process.version}`)
}
];

Expand Down
7 changes: 4 additions & 3 deletions src/transmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import superagent from "superagent";
import urljoin from "urljoin";

const USER_AGENT = "libhoney-js/<@LIBHONEY_JS_VERSION@>";
const LIBHONEY_VERSION = "libhoney-js/<@LIBHONEY_JS_VERSION@>";
const NODE_VERSION = `node/${process.version}`;

const _global =
typeof window !== "undefined"
Expand Down Expand Up @@ -356,10 +357,10 @@ export class Transmission {
return;
}

let userAgent = USER_AGENT;
let userAgent = `${LIBHONEY_VERSION} ${NODE_VERSION}`;
let trimmedAddition = this._userAgentAddition.trim();
if (trimmedAddition) {
userAgent = `${USER_AGENT} ${trimmedAddition}`;
userAgent = `${LIBHONEY_VERSION} ${trimmedAddition} ${NODE_VERSION}`;
}

let start = Date.now();
Expand Down

0 comments on commit 28bf5a9

Please sign in to comment.