@elastic/apm-rum-core
Advanced tools
Comparing version 5.4.0 to 5.5.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [5.5.0](https://github.com/elastic/apm-agent-rum-js/compare/@elastic/apm-rum-core@5.4.0...@elastic/apm-rum-core@5.5.0) (2020-07-29) | ||
### Features | ||
* **rum-core:** compress payload sent to APM Server ([#572](https://github.com/elastic/apm-agent-rum-js/issues/572)) ([a8f02c6](https://github.com/elastic/apm-agent-rum-js/commit/a8f02c663e2579a3a427c7f461416d17f45b7c62)) | ||
# [5.4.0](https://github.com/elastic/apm-agent-rum-js/compare/@elastic/apm-rum-core@5.3.1...@elastic/apm-rum-core@5.4.0) (2020-07-06) | ||
@@ -8,0 +19,0 @@ |
@@ -9,3 +9,3 @@ import Queue from './queue'; | ||
import { Promise } from './polyfills'; | ||
import { compressMetadata, compressTransaction, compressError } from './compress'; | ||
import { compressMetadata, compressTransaction, compressError, compressPayload } from './compress'; | ||
import { __DEV__ } from '../state'; | ||
@@ -56,7 +56,18 @@ var THROTTLE_INTERVAL = 60000; | ||
_proto._postJson = function _postJson(endPoint, payload) { | ||
return this._makeHttpRequest('POST', endPoint, { | ||
payload: payload, | ||
headers: { | ||
'Content-Type': 'application/x-ndjson' | ||
var _this2 = this; | ||
var headers = { | ||
'Content-Type': 'application/x-ndjson' | ||
}; | ||
return compressPayload(payload, headers).catch(function (error) { | ||
if (__DEV__) { | ||
_this2._loggingService.debug('Compressing the payload using CompressionStream API failed', error.message); | ||
} | ||
return { | ||
payload: payload, | ||
headers: headers | ||
}; | ||
}).then(function (result) { | ||
return _this2._makeHttpRequest('POST', endPoint, result); | ||
}).then(function (_ref) { | ||
@@ -152,3 +163,3 @@ var responseText = _ref.responseText; | ||
_proto.fetchConfig = function fetchConfig(serviceName, environment) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -190,3 +201,3 @@ var serverUrl = this._configService.get('serverUrl'); | ||
_this2._configService.setLocalConfig(remoteConfig); | ||
_this3._configService.setLocalConfig(remoteConfig); | ||
} | ||
@@ -197,3 +208,3 @@ | ||
}).catch(function (reason) { | ||
var error = _this2._constructError(reason); | ||
var error = _this3._constructError(reason); | ||
@@ -254,3 +265,3 @@ return Promise.reject(error); | ||
_proto.ndjsonTransactions = function ndjsonTransactions(transactions, compress) { | ||
var _this3 = this; | ||
var _this4 = this; | ||
@@ -275,3 +286,3 @@ var key = compress ? 'x' : 'transaction'; | ||
if (tr.breakdown) { | ||
breakdowns = _this3.ndjsonMetricsets(tr.breakdown); | ||
breakdowns = _this4.ndjsonMetricsets(tr.breakdown); | ||
delete tr.breakdown; | ||
@@ -278,0 +289,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { Promise } from './polyfills'; | ||
import { NAVIGATION_TIMING_MARKS, COMPRESSED_NAV_TIMING_MARKS } from '../performance-monitoring/capture-navigation'; | ||
@@ -263,2 +264,27 @@ | ||
}); | ||
} | ||
export function compressPayload(payload, headers, type) { | ||
if (type === void 0) { | ||
type = 'gzip'; | ||
} | ||
var isCompressionStreamSupported = typeof CompressionStream === 'function'; | ||
return new Promise(function (resolve) { | ||
if (!isCompressionStreamSupported) { | ||
return resolve({ | ||
payload: payload, | ||
headers: headers | ||
}); | ||
} | ||
var payloadStream = new Blob([payload]).stream(); | ||
var compressedStream = payloadStream.pipeThrough(new CompressionStream(type)); | ||
return new Response(compressedStream).blob().then(function (payload) { | ||
headers['Content-Encoding'] = type; | ||
return resolve({ | ||
payload: payload, | ||
headers: headers | ||
}); | ||
}); | ||
}); | ||
} |
@@ -72,7 +72,18 @@ "use strict"; | ||
_proto._postJson = function _postJson(endPoint, payload) { | ||
return this._makeHttpRequest('POST', endPoint, { | ||
payload: payload, | ||
headers: { | ||
'Content-Type': 'application/x-ndjson' | ||
var _this2 = this; | ||
var headers = { | ||
'Content-Type': 'application/x-ndjson' | ||
}; | ||
return (0, _compress.compressPayload)(payload, headers).catch(function (error) { | ||
if (_state.__DEV__) { | ||
_this2._loggingService.debug('Compressing the payload using CompressionStream API failed', error.message); | ||
} | ||
return { | ||
payload: payload, | ||
headers: headers | ||
}; | ||
}).then(function (result) { | ||
return _this2._makeHttpRequest('POST', endPoint, result); | ||
}).then(function (_ref) { | ||
@@ -168,3 +179,3 @@ var responseText = _ref.responseText; | ||
_proto.fetchConfig = function fetchConfig(serviceName, environment) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -206,3 +217,3 @@ var serverUrl = this._configService.get('serverUrl'); | ||
_this2._configService.setLocalConfig(remoteConfig); | ||
_this3._configService.setLocalConfig(remoteConfig); | ||
} | ||
@@ -213,3 +224,3 @@ | ||
}).catch(function (reason) { | ||
var error = _this2._constructError(reason); | ||
var error = _this3._constructError(reason); | ||
@@ -270,3 +281,3 @@ return _polyfills.Promise.reject(error); | ||
_proto.ndjsonTransactions = function ndjsonTransactions(transactions, compress) { | ||
var _this3 = this; | ||
var _this4 = this; | ||
@@ -291,3 +302,3 @@ var key = compress ? 'x' : 'transaction'; | ||
if (tr.breakdown) { | ||
breakdowns = _this3.ndjsonMetricsets(tr.breakdown); | ||
breakdowns = _this4.ndjsonMetricsets(tr.breakdown); | ||
delete tr.breakdown; | ||
@@ -294,0 +305,0 @@ } |
@@ -8,3 +8,6 @@ "use strict"; | ||
exports.compressMetricsets = compressMetricsets; | ||
exports.compressPayload = compressPayload; | ||
var _polyfills = require("./polyfills"); | ||
var _captureNavigation = require("../performance-monitoring/capture-navigation"); | ||
@@ -277,2 +280,28 @@ | ||
}); | ||
} | ||
function compressPayload(payload, headers, type) { | ||
if (type === void 0) { | ||
type = 'gzip'; | ||
} | ||
var isCompressionStreamSupported = typeof CompressionStream === 'function'; | ||
return new _polyfills.Promise(function (resolve) { | ||
if (!isCompressionStreamSupported) { | ||
return resolve({ | ||
payload: payload, | ||
headers: headers | ||
}); | ||
} | ||
var payloadStream = new Blob([payload]).stream(); | ||
var compressedStream = payloadStream.pipeThrough(new CompressionStream(type)); | ||
return new Response(compressedStream).blob().then(function (payload) { | ||
headers['Content-Encoding'] = type; | ||
return resolve({ | ||
payload: payload, | ||
headers: headers | ||
}); | ||
}); | ||
}); | ||
} |
{ | ||
"name": "@elastic/apm-rum-core", | ||
"version": "5.4.0", | ||
"version": "5.5.0", | ||
"description": "Elastic apm core", | ||
@@ -43,3 +43,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "a6e9dc6371a0eba81da27db05353e5ce2e53efce" | ||
"gitHead": "3b9ee09ae9b7802caba1e7b618f9b21166f3641b" | ||
} |
@@ -37,3 +37,4 @@ /** | ||
compressTransaction, | ||
compressError | ||
compressError, | ||
compressPayload | ||
} from './compress' | ||
@@ -81,8 +82,17 @@ import { __DEV__ } from '../state' | ||
_postJson(endPoint, payload) { | ||
return this._makeHttpRequest('POST', endPoint, { | ||
payload, | ||
headers: { | ||
'Content-Type': 'application/x-ndjson' | ||
} | ||
}).then(({ responseText }) => responseText) | ||
const headers = { | ||
'Content-Type': 'application/x-ndjson' | ||
} | ||
return compressPayload(payload, headers) | ||
.catch(error => { | ||
if (__DEV__) { | ||
this._loggingService.debug( | ||
'Compressing the payload using CompressionStream API failed', | ||
error.message | ||
) | ||
} | ||
return { payload, headers } | ||
}) | ||
.then(result => this._makeHttpRequest('POST', endPoint, result)) | ||
.then(({ responseText }) => responseText) | ||
} | ||
@@ -89,0 +99,0 @@ |
@@ -26,2 +26,3 @@ /** | ||
import { Promise } from './polyfills' | ||
import { | ||
@@ -275,1 +276,40 @@ NAVIGATION_TIMING_MARKS, | ||
} | ||
/** | ||
* Compress the payload object using the draft | ||
* CompressionStream spec supported only in Chromium browsers | ||
* Spec : https://wicg.github.io/compression/ | ||
*/ | ||
export function compressPayload(payload, headers, type = 'gzip') { | ||
const isCompressionStreamSupported = typeof CompressionStream === 'function' | ||
return new Promise(resolve => { | ||
/** | ||
* Resolve with unmodified payload if the compression stream | ||
* is not supported in browser | ||
*/ | ||
if (!isCompressionStreamSupported) { | ||
return resolve({ payload, headers }) | ||
} | ||
/** | ||
* create a blob with the original payload data and convert it | ||
* as readable stream | ||
*/ | ||
const payloadStream = new Blob([payload]).stream() | ||
/** | ||
* pipe the readable stream from blob through the compression stream which is a | ||
* transform stream that reads blobs contents to its destination (writable) | ||
*/ | ||
const compressedStream = payloadStream.pipeThrough( | ||
new CompressionStream(type) | ||
) | ||
/** | ||
* Response accepts a readable stream as input and reads its to completion | ||
* to generate the Blob content | ||
*/ | ||
return new Response(compressedStream).blob().then(payload => { | ||
headers['Content-Encoding'] = type | ||
return resolve({ payload, headers }) | ||
}) | ||
}) | ||
} |
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
477091
13628