Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elastic-apm-http-client

Package Overview
Dependencies
Maintainers
3
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elastic-apm-http-client - npm Package Compare versions

Comparing version 9.9.0 to 10.0.0

20

CHANGELOG.md
# elastic-apm-http-client changelog
## v10.0.0
- All truncation of string fields (per `truncate*At` config options) have
changed from truncating at a number of unicode chars, rather than a number
of bytes. This is both faster and matches [the json-schema spec](https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.3.1)
for [apm-server intake fields](https://www.elastic.co/guide/en/apm/server/current/events-api.html#events-api-schema-definition)
that specify `maxLength`.
- BREAKING CHANGE: The `truncateQueriesAt` config option has been removed.
- In its place the `truncateLongFieldsAt` config option has been added to cover
`span.context.db.statement` and a number of other possibly-long fields (per
[spec](https://github.com/elastic/apm/blob/master/specs/agents/field-limits.md#long_field_max_length-configuration)).
This *does* mean that in rare cases of long field values longer than the
default 10000 chars, this change will result in those values being truncated.
- The `truncateErrorMessagesAt` config option has been deprecated, in favor
of `truncateLongFieldsAt`. Note, however, that `truncateLongFieldsAt` does
*not* support the special case `-1` value to disable truncation. If
`truncateErrorMessagesAt` is not specified, the value for
`truncateLongFieldsAt` is used. This means the effective default is now 10000,
no longer 2048.
## v9.9.0

@@ -4,0 +24,0 @@

4

index.js

@@ -187,6 +187,6 @@ 'use strict'

if (!this._conf.truncateKeywordsAt) this._conf.truncateKeywordsAt = 1024
if (!this._conf.truncateErrorMessagesAt) this._conf.truncateErrorMessagesAt = 2048
if (!this._conf.truncateStringsAt) this._conf.truncateStringsAt = 1024
if (!this._conf.truncateCustomKeysAt) this._conf.truncateCustomKeysAt = 1024
if (!this._conf.truncateQueriesAt) this._conf.truncateQueriesAt = 10000
if (!this._conf.truncateLongFieldsAt) this._conf.truncateLongFieldsAt = 10000
// The deprecated `truncateErrorMessagesAt` will be honored if specified.
if (!this._conf.bufferWindowTime) this._conf.bufferWindowTime = 20

@@ -193,0 +193,0 @@ if (!this._conf.bufferWindowSize) this._conf.bufferWindowSize = 50

'use strict'
var breadthFilter = require('breadth-filter')
var truncate = require('unicode-byte-truncate')

@@ -12,2 +11,33 @@ exports.metadata = truncMetadata

// Truncate the string `s` to a `max` maximum number of JavaScript characters.
//
// Note that JavaScript uses UCS-2 internally, so characters outside of the
// BMP are represented as surrogate pairs. These count as *two* characters.
// The result is that a string with surrogate pairs will appear to be truncated
// shorter than expected:
// unitrunc('aaaa', 4) // => 'aaaa'
// unitrunc('😂😂😂😂', 4) // => '😂😂'
//
// This will avoid truncating in the middle of a surrogate pair by truncating
// one character earlier. For example:
// unitrunc('foo😂bar', 4) // => 'foo'
function unitrunc (s, max) {
if (s.length > max) {
if (max <= 0) {
return ''
}
// If the last character is a "high" surrogate (D800–DBFF) per
// https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates
// then we would truncate in the middle of a surrogate pair. Move back one
// char to have a clean(er) truncation.
const endChar = s.charCodeAt(max - 1)
if (endChar >= 0xd800 && endChar <= 0xdbff) {
return s.slice(0, max - 1)
} else {
return s.slice(0, max)
}
}
return s
}
function truncMetadata (metadata, opts) {

@@ -102,3 +132,3 @@ return breadthFilter(metadata, {

return truncate(value, max)
return unitrunc(value, max)
}

@@ -135,3 +165,3 @@ })

return truncate(value, max)
return unitrunc(value, max)
}

@@ -174,3 +204,3 @@ })

return truncate(value, max)
return unitrunc(value, max)
}

@@ -234,6 +264,8 @@ })

case 'message':
if (opts.truncateErrorMessagesAt >= 0) {
if (opts.truncateErrorMessagesAt === undefined) {
max = opts.truncateLongFieldsAt
} else if (opts.truncateErrorMessagesAt < 0) {
return value // skip truncation
} else {
max = opts.truncateErrorMessagesAt
} else {
return value
}

@@ -252,6 +284,8 @@ break

case 'message':
if (opts.truncateErrorMessagesAt >= 0) {
if (opts.truncateErrorMessagesAt === undefined) {
max = opts.truncateLongFieldsAt
} else if (opts.truncateErrorMessagesAt < 0) {
return value // skip truncation
} else {
max = opts.truncateErrorMessagesAt
} else {
return value
}

@@ -263,3 +297,3 @@ break

return truncate(value, max)
return unitrunc(value, max)
}

@@ -282,3 +316,3 @@ })

return truncate(value, max)
return unitrunc(value, max)
}

@@ -292,6 +326,12 @@ })

if (path[2] === 'statement') {
return opts.truncateQueriesAt
return opts.truncateLongFieldsAt
}
break
case 'message':
if (path[2] === 'body') {
return opts.truncateLongFieldsAt
}
break
case 'request':

@@ -303,2 +343,5 @@ switch (path[2]) {

case 'body':
return opts.truncateLongFieldsAt
case 'url':

@@ -375,3 +418,8 @@ switch (path[3]) {

const keys = Object.keys(result)
const truncatedKeys = keys.map(k => keywords.includes(k) ? k : truncate(k, max))
const truncatedKeys = keys.map(k => {
if (keywords.includes(k)) {
return k
}
return unitrunc(k, max)
})

@@ -378,0 +426,0 @@ for (const [index, k] of keys.entries()) {

{
"name": "elastic-apm-http-client",
"version": "9.9.0",
"version": "10.0.0",
"description": "A low-level HTTP client for communicating with the Elastic APM intake API",

@@ -29,4 +29,3 @@ "main": "index.js",

"readable-stream": "^3.4.0",
"stream-chopper": "^3.0.1",
"unicode-byte-truncate": "^1.0.0"
"stream-chopper": "^3.0.1"
},

@@ -33,0 +32,0 @@ "devDependencies": {

@@ -121,3 +121,3 @@ # elastic-apm-http-client

internal zlib buffer should be expected as the buffer is flushed after
this limit is reached. The default zlib buffer size is 16 kb (default:
this limit is reached. The default zlib buffer size is 16kB. (default:
`768000` bytes)

@@ -159,14 +159,20 @@ - `time` - The maxiumum number of milliseconds a streaming HTTP request

- `truncateKeywordsAt` - Maximum size in bytes for strings stored as
Elasticsearch keywords. Strings larger than this will be trucated
(default: `1024` bytes)
- `truncateErrorMessagesAt` - The maximum size in bytes for error
messages. Messages above this length will be truncated. Set to `-1` to
disable truncation. This applies to the following properties:
`error.exception.message` and `error.log.message` (default: `2048`
bytes)
- `truncateStringsAt` - The maximum size in bytes for strings.
String values above this length will be truncated (default: `1024` bytes)
- `truncateQueriesAt` - The maximum size in bytes for database queries.
Queries above this length will be truncated (default: `10000` bytes)
- `truncateKeywordsAt` - Maximum size in unicode characters for strings stored
as Elasticsearch keywords. Strings larger than this will be trucated
(default: `1024`)
- `truncateLongFieldsAt` - The maximum size in unicode characters for a
specific set of long string fields. String values above this length will be
truncated. Default: `10000`. This applies to the following fields:
- `transaction.context.request.body`, `error.context.request.body`
- `transaction.context.message.body`, `span.context.message.body`, `error.context.message.body`
- `span.context.db.statement`
- `error.exception.message` (unless `truncateErrorMessagesAt` is specified)
- `error.log.message` (unless `truncateErrorMessagesAt` is specified)
- `truncateStringsAt` - The maximum size in unicode characters for strings.
String values above this length will be truncated (default: `1024`)
- `truncateErrorMessagesAt` - **DEPRECATED:** prefer `truncateLongFieldsAt`.
The maximum size in unicode characters for error messages. Messages above this
length will be truncated. Set to `-1` to disable truncation. This applies to
the following properties: `error.exception.message` and `error.log.message`.
(default: `2048`)

@@ -173,0 +179,0 @@ Debug options:

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc