elastic-apm-http-client
Advanced tools
Comparing version 9.5.1 to 9.6.0
# elastic-apm-http-client changelog | ||
## v9.6.0 | ||
- Fix config initialization such that the keep-alive agent is used all the | ||
time, as intended. Before this change the keep-alive HTTP(S) agent would only | ||
be used if a second call to `client.config(...)` was made. For the [Elastic | ||
APM Agent](https://github.com/elastic/apm-agent-nodejs)'s usage of this | ||
module, that was when any of the express, fastify, restify, hapi, or koa | ||
modules was instrumented. ([#139](https://github.com/elastic/apm-nodejs-http-client/pull/139)) | ||
A compatibility note for direct users of this APM http-client: | ||
Options passed to the | ||
[`Writable`](https://nodejs.org/api/stream.html#stream_new_stream_writable_options) | ||
and [`http[s].Agent`](https://nodejs.org/api/http.html#http_new_agent_options) | ||
constructors no longer include the full options object passed to the | ||
[Client constructor](https://github.com/elastic/apm-nodejs-http-client/blob/master/README.md#new-clientoptions). | ||
Therefore usage of *undocumented* options can no longer be used. | ||
## v9.5.1 | ||
@@ -4,0 +21,0 @@ |
72
index.js
'use strict' | ||
const http = require('http') | ||
const https = require('https') | ||
const util = require('util') | ||
@@ -14,2 +16,3 @@ const os = require('os') | ||
const StreamChopper = require('stream-chopper') | ||
const ndjson = require('./lib/ndjson') | ||
@@ -60,17 +63,8 @@ const truncate = require('./lib/truncate') | ||
this.config(opts) | ||
Writable.call(this, { objectMode: true }) | ||
Writable.call(this, this._conf) | ||
const errorproxy = (err) => { | ||
if (this.destroyed === false) this.emit('request-error', err) | ||
} | ||
const fail = () => { | ||
if (this._writableState.ending === false) this.destroy() | ||
} | ||
this._corkTimer = null | ||
this._received = 0 // number of events given to the client for reporting | ||
this.sent = 0 // number of events written to the socket | ||
this._agent = null | ||
this._active = false | ||
@@ -82,18 +76,4 @@ this._onflushed = null | ||
switch (this._conf.serverUrl.protocol.slice(0, -1)) { // 'http:' => 'http' | ||
case 'http': { | ||
this._transport = require('http') | ||
break | ||
} | ||
case 'https': { | ||
this._transport = require('https') | ||
break | ||
} | ||
default: { | ||
throw new Error('Unknown protocol ' + this._conf.serverUrl.protocol.slice(0, -1)) | ||
} | ||
} | ||
this.config(opts) | ||
this._agent = new this._transport.Agent(this._conf) | ||
// start stream in corked mode, uncork when cloud | ||
@@ -118,2 +98,5 @@ // metadata is fetched and assigned. Also, the | ||
const errorproxy = (err) => { | ||
if (this.destroyed === false) this.emit('request-error', err) | ||
} | ||
this._chopper = new StreamChopper({ | ||
@@ -128,2 +111,5 @@ size: this._conf.size, | ||
const fail = () => { | ||
if (this._writableState.ending === false) this.destroy() | ||
} | ||
eos(this._chopper, fail) | ||
@@ -134,7 +120,9 @@ | ||
if (this._conf.centralConfig) this._pollConfig() | ||
if (this._conf.centralConfig) { | ||
this._pollConfig() | ||
} | ||
} | ||
Client.prototype.config = function (opts) { | ||
this._conf = Object.assign(this._conf || {}, opts, { objectMode: true }) | ||
this._conf = Object.assign(this._conf || {}, opts) | ||
@@ -163,3 +151,3 @@ this._conf.globalLabels = normalizeGlobalLabels(this._conf.globalLabels) | ||
// process | ||
// processed values | ||
this._conf.serverUrl = new URL(this._conf.serverUrl) | ||
@@ -179,2 +167,28 @@ | ||
switch (this._conf.serverUrl.protocol) { | ||
case 'http:': | ||
this._transport = http | ||
break | ||
case 'https:': | ||
this._transport = https | ||
break | ||
default: | ||
throw new Error('Unknown protocol ' + this._conf.serverUrl.protocol) | ||
} | ||
// Only reset `this._agent` if the serverUrl has changed to avoid | ||
// unnecessarily abandoning keep-alive connections. | ||
if (!this._agent || (opts && 'serverUrl' in opts)) { | ||
if (this._agent) { | ||
this._agent.destroy() | ||
} | ||
var agentOpts = { | ||
keepAlive: this._conf.keepAlive, | ||
keepAliveMsecs: this._conf.keepAliveMsecs, | ||
maxSockets: this._conf.maxSockets, | ||
maxFreeSockets: this._conf.maxFreeSockets | ||
} | ||
this._agent = new this._transport.Agent(agentOpts) | ||
} | ||
// http request options | ||
@@ -181,0 +195,0 @@ this._conf.requestIntake = getIntakeRequestOptions(this._conf, this._agent) |
{ | ||
"name": "elastic-apm-http-client", | ||
"version": "9.5.1", | ||
"version": "9.6.0", | ||
"description": "A low-level HTTP client for communicating with the Elastic APM intake API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# elastic-apm-http-client | ||
[![npm](https://img.shields.io/npm/v/elastic-apm-http-client.svg)](https://www.npmjs.com/package/elastic-apm-http-client) | ||
[![Test status in Travis](https://github.com/elastic/apm-nodejs-http-client/workflows/Test/badge.svg)](https://github.com/elastic/apm-nodejs-http-client/actions) | ||
[![Test status in GitHub Actions](https://github.com/elastic/apm-nodejs-http-client/workflows/Test/badge.svg)](https://github.com/elastic/apm-nodejs-http-client/actions) | ||
[![Build Status in Jenkins](https://apm-ci.elastic.co/buildStatus/icon?job=apm-agent-nodejs%2Fapm-nodejs-http-client-mbp%2Fmaster)](https://apm-ci.elastic.co/job/apm-agent-nodejs/job/apm-nodejs-http-client-mbp/job/master/) | ||
@@ -230,3 +230,2 @@ [![codecov](https://img.shields.io/codecov/c/github/elastic/apm-nodejs-http-client.svg)](https://codecov.io/gh/elastic/apm-nodejs-http-client) | ||
- The protocol part of the `serverUrl` (`http` vs `https`) | ||
- `size` | ||
@@ -233,0 +232,0 @@ - `time` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52648
1122
309