Skip to content

Commit

Permalink
feat: support classic ingest keys, upgrade to libhoney 4.2.0 (#726)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?

We
[recently](https://github.com/honeycombio/libhoney-js/releases/tag/v4.2.0)
updated libhoney-js to support classic ingest keys. This PR updates the
beeline to this version of libhoney-js and swaps `isClassic` to use the
new exported method from libhoney.

## Short description of the changes

- bumps libhoney-js version from `4.0.0` to `4.2.0`
- removes `utils.isClassic` in favor of `libhoney.isClassic`
- Adds two tests that use classic/non-classic ingest keys to verify it
works
  • Loading branch information
cewkrupa authored Mar 4, 2024
1 parent b7aa196 commit 81ea026
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 20 deletions.
6 changes: 3 additions & 3 deletions lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const process = require("process"),
tracker = require("../async_tracker"),
pkg = require("../../package.json"),
debug = require("debug")(`${pkg.name}:event`),
libhoney = require("libhoney"),
LibhoneyImpl = require("./libhoney"),
MockImpl = require("./mock"),
utils = require("../util");
MockImpl = require("./mock");

const { honeycomb, aws, w3c, util } = propagation;

Expand Down Expand Up @@ -41,7 +41,7 @@ module.exports = {
apiImpl = new impl(opts);

// tell honeycomb propagator whether we should propagate dataset
honeycomb.setPropagateDataset(utils.isClassic(opts.writeKey));
honeycomb.setPropagateDataset(libhoney.isClassic(opts.writeKey));
},

traceActive() {
Expand Down
38 changes: 38 additions & 0 deletions lib/api/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ test("libhoney default config - classic", () => {
expect(honey._builder._fields["service.name"]).toBe("unknown_service:nodejs");
});

test("libhoney default config - classic ingest key", () => {
api._resetForTesting();
api.configure({
impl: "libhoney-event",
transmission: "mock",
writeKey: "hcaic_1234567890123456789012345678901234567890123456789012345678",
});

const honey = api._apiForTesting().honey;
expect(honey.transmission.constructorArg.apiHost).toBe("https://api.honeycomb.io");
expect(honey.transmission.constructorArg.dataset).toBe("nodejs");
expect(honey.transmission.constructorArg.writeKey).toBe("hcaic_1234567890123456789012345678901234567890123456789012345678");
expect(honey.transmission.constructorArg.userAgentAddition).toBe(
`honeycomb-beeline/${pkg.version}`
);
expect(honey._builder._fields["service_name"]).toBe("unknown_service:nodejs");
expect(honey._builder._fields["service.name"]).toBe("unknown_service:nodejs");
});

test("libhoney default config - non-classic", () => {
api._resetForTesting();
api.configure({
Expand All @@ -48,6 +67,25 @@ test("libhoney default config - non-classic", () => {
expect(honey._builder._fields["service.name"]).toBe("unknown_service:nodejs");
});

test("libhoney default config - non-classic ingest key", () => {
api._resetForTesting();
api.configure({
impl: "libhoney-event",
transmission: "mock",
writeKey: "hcxik_01hqk4k20cjeh63wca8vva5stw70nft6m5n8wr8f5mjx3762s8269j50wc",
});

const honey = api._apiForTesting().honey;
expect(honey.transmission.constructorArg.apiHost).toBe("https://api.honeycomb.io");
expect(honey.transmission.constructorArg.dataset).toBe("unknown_service");
expect(honey.transmission.constructorArg.writeKey).toBe("hcxik_01hqk4k20cjeh63wca8vva5stw70nft6m5n8wr8f5mjx3762s8269j50wc");
expect(honey.transmission.constructorArg.userAgentAddition).toBe(
`honeycomb-beeline/${pkg.version}`
);
expect(honey._builder._fields["service_name"]).toBe("unknown_service:nodejs");
expect(honey._builder._fields["service.name"]).toBe("unknown_service:nodejs");
});

test("libhoney config - non-classic - empty service name", () => {
api._resetForTesting();
api.configure({
Expand Down
5 changes: 2 additions & 3 deletions lib/api/libhoney.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const libhoney = require("libhoney"),
schema = require("../schema"),
Span = require("./span"),
pkg = require("../../package.json"),
debug = require("debug")(`${pkg.name}:event`),
util = require("../util");
debug = require("debug")(`${pkg.name}:event`);

const defaultName = "nodejs";

Expand Down Expand Up @@ -91,7 +90,7 @@ module.exports = class LibhoneyEventAPI {
console.warn("empty writeKey configuration option");
}

if (util.isClassic(opts.writeKey)) {
if (libhoney.isClassic(opts.writeKey)) {
let dataset = opts.dataset || process.env["HONEYCOMB_DATASET"];
if (!dataset || dataset.trim() === "") {
dataset = defaultName;
Expand Down
6 changes: 0 additions & 6 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,3 @@ function captureStackTrace(skipFrames = 0, limitFrames = 10) {
// the +1 here to get rid of the `Error\n` line at the top of the stacktrace.
return frames.slice(1 + skipFrames).join("\n");
}

exports.isClassic = isClassic;

function isClassic(writeKey) {
return !writeKey || writeKey.length == 32;
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@opentelemetry/core": "^1.0.0",
"array-flatten": "^3.0.0",
"debug": "^4.2.0",
"libhoney": "^4.0.0",
"libhoney": "^4.2.0",
"on-headers": "^1.0.2",
"shimmer": "^1.2.1"
}
Expand Down

0 comments on commit 81ea026

Please sign in to comment.