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

new http.Agent() is created for each socket in collector exporter instead of using single agent for all requests #1840

Closed
blumamir opened this issue Jan 17, 2021 · 1 comment · Fixed by #1863
Labels
bug Something isn't working

Comments

@blumamir
Copy link
Member

blumamir commented Jan 17, 2021

What version of OpenTelemetry are you using?

v0.14.0

What version of Node are you using?

12

This code from collector exporter creates a new Agent for each HTTP export request via the collector exporter:

export function sendWithHttp<ExportItem, ServiceRequest>(...): void {

  ...

  const request = parsedUrl.protocol === 'http:' ? http.request : https.request;
  const Agent = parsedUrl.protocol === 'http:' ? http.Agent : https.Agent;
  if (collector.keepAlive) {
    options.agent = new Agent({
      ...collector.httpAgentOptions,
      keepAlive: true,
    });
  }

  const req = request(options, (res: http.IncomingMessage) => {

I might be missing something, but shouldn't all the HTTP requests reuse the same Agent, in order to benefit from its connection persistence and reuse?

@blumamir blumamir added the bug Something isn't working label Jan 17, 2021
@blumamir
Copy link
Member Author

I checked how axios and aws-sdk are using the agent.
It looks like they accept the agent as config parameter, rather than newing it in the library. This enables the user to configure it freely, and to share the connection pool and limits between multiple HTTP clients or exporters.
On the other hand, the user needs to be active about setting the use of agent, and it doesn't happen automatically by default.

in axios, this can be set in request config:

  // `httpAgent` and `httpsAgent` define a custom agent to be used when performing http
  // and https requests, respectively, in node.js. This allows options to be added like
  // `keepAlive` that are not enabled by default.
  httpAgent: new http.Agent({ keepAlive: true }),
  httpsAgent: new https.Agent({ keepAlive: true }),

In aws-sdk:

const AWS = require('aws-sdk')
// http or https
const https = require('https');
const agent = new https.Agent({
  keepAlive: true
});

const dynamodb = new AWS.DynamoDB({
  httpOptions: {
    agent
  }
});

pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this issue Dec 15, 2023
…ions (open-telemetry#1840)

* docs(user-interaction): update docs to include examples of config options

* add example to prevent span creation

* fix lint

* address PR comments

* update link to list of events

* syntax updates

Co-authored-by: Martin Kuba <[email protected]>

---------

Co-authored-by: Martin Kuba <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant