diff --git a/lib/api/index.js b/lib/api/index.js index db26cbe1..6f91b7a8 100644 --- a/lib/api/index.js +++ b/lib/api/index.js @@ -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; @@ -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() { diff --git a/lib/api/index.test.js b/lib/api/index.test.js index fb12c16e..4e6d638f 100644 --- a/lib/api/index.test.js +++ b/lib/api/index.test.js @@ -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({ @@ -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({ diff --git a/lib/api/libhoney.js b/lib/api/libhoney.js index f110300a..39ca30ec 100644 --- a/lib/api/libhoney.js +++ b/lib/api/libhoney.js @@ -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"; @@ -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; diff --git a/lib/util.js b/lib/util.js index fbe47aca..603d723e 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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; -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c1ef03c2..119cdc69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,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" }, @@ -4549,9 +4549,9 @@ } }, "node_modules/libhoney": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/libhoney/-/libhoney-4.1.0.tgz", - "integrity": "sha512-U8oCouZXzjlO67wAhDyvnskn9MJFIzTWkxpzsAawUU4nQLMSdISgaGL64eqAeElLRnjlA4hhREr8zOz1So0+yg==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/libhoney/-/libhoney-4.2.0.tgz", + "integrity": "sha512-XFb7uP3IPzhTU45pwjBuaRfRyYmnlBEOnbfzdpec538JH5Xds/3sE1UWeYD1IfARuGUFZWQ215b3fbOW+WeFVA==", "dependencies": { "proxy-agent": "^6.3.0", "superagent": "^8.0.0", @@ -9965,9 +9965,9 @@ } }, "libhoney": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/libhoney/-/libhoney-4.1.0.tgz", - "integrity": "sha512-U8oCouZXzjlO67wAhDyvnskn9MJFIzTWkxpzsAawUU4nQLMSdISgaGL64eqAeElLRnjlA4hhREr8zOz1So0+yg==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/libhoney/-/libhoney-4.2.0.tgz", + "integrity": "sha512-XFb7uP3IPzhTU45pwjBuaRfRyYmnlBEOnbfzdpec538JH5Xds/3sE1UWeYD1IfARuGUFZWQ215b3fbOW+WeFVA==", "requires": { "proxy-agent": "^6.3.0", "superagent": "^8.0.0", diff --git a/package.json b/package.json index 6be20331..dbf117ee 100644 --- a/package.json +++ b/package.json @@ -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" }