Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support classic ingest keys, upgrade to libhoney 4.2.0 #726

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need two require's for libhoney and LibhoneyImpl?

PS I prefer libhoney over LibhoneyImpl if we can just keep line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think we do need both, since the LibhoneyImpl is coming from ./libhoney.js in this repo while libhoney is coming direct from the libhoney-js package as libhoney.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I didn't notice the local reference for LibhoneyImpl 👍🏻 It's kinda weird we have a file named the same as one of our dependencies (which we maintain :)).

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
Loading