Giter Site home page Giter Site logo

Comments (2)

dko-slapdash avatar dko-slapdash commented on August 19, 2024

Here is a patch which adds agent option to Libhoney.

diff --git a/node_modules/libhoney/dist/libhoney.cjs.js b/node_modules/libhoney/dist/libhoney.cjs.js
index 9249824..9a4bb0b 100644
--- a/node_modules/libhoney/dist/libhoney.cjs.js
+++ b/node_modules/libhoney/dist/libhoney.cjs.js
@@ -443,6 +443,7 @@ class Transmission {
 
     this._userAgentAddition = options.userAgentAddition || "";
     this._proxy = options.proxy;
+    this._agent = options.agent;
 
     // Included for testing; to stub out randomness and verify that an event
     // was dropped.
@@ -565,6 +566,11 @@ class Transmission {
               userAgent = `${LIBHONEY_VERSION} ${trimmedAddition} ${NODE_VERSION}`;
             }
 
+            let agent = typeof this._agent === "function" ? this._agent() : this._agent;
+            if (agent) {
+              req.agent(agent);
+            }
+
             let start = Date.now();
             req
               .set("X-Honeycomb-Team", batch.writeKey)

Usage:

new Libhoney({ ..., agent: new https.Agent({ keepAlive: true, maxSockets: 10 })});

Works very well, dropped the rate of new HTTPS connections dramatically for us.

from libhoney-js.

MikeGoldsmith avatar MikeGoldsmith commented on August 19, 2024

Hi @dko-slapdash - thanks for the creating the issue and proposing a solution.

I generally like what you've suggested. I'm a little wary of allowing a user to provide their own custom agent as it they could accidentally use the wrong implementation (http vs https) for their destination URL. However, I think good documentation here would help.

An alternative solution would be to expose discrete options for keepalive and maxsockets and we create the agent, but then we'd need to pick a default maxsockets if one isn't set which could also be tricky.

Please could you create a PR with your suggestion, and we can iterate from there. Thanks 👍

from libhoney-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.