Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Skipped too big values (arg, return value, local var) at method instr…
Browse files Browse the repository at this point in the history
…umentation
  • Loading branch information
Serkan ÖZAL committed Aug 2, 2020
1 parent e6e3435 commit d6602cf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
27 changes: 22 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -87,7 +87,6 @@
"dependencies": {
"@thundra/instrumenter": "^1.2.0",
"@thundra/warmup": "1.0.0",
"opentracing": "0.14.1",
"json-stringify-safe": "^5.0.1",
"koalas": "^1.0.2",
"lodash.flatten": "^4.4.0",
Expand All @@ -96,6 +95,8 @@
"lodash.trim": "^4.5.1",
"md5": "^2.2.1",
"module-details-from-path": "^1.0.3",
"object-sizeof": "^1.6.1",
"opentracing": "0.14.1",
"require-in-the-middle": "^3.1.0",
"semver": "^5.5.0",
"shimmer": "^1.2.0",
Expand Down
21 changes: 20 additions & 1 deletion src/opentracing/instrument/Instrumenter.ts
Expand Up @@ -13,9 +13,11 @@ const Module = require('module');
const path = require('path');
const get = require('lodash.get');
const stringify = require('json-stringify-safe');
const sizeof = require('object-sizeof');

const TRACE_DEF_SEPARATOR: string = '.';
const MAX_LINES: number = 100;
const MAX_VAR_VALUE_SIZE: number = 1024; // 1KB

/**
* Instruments specified/configured modules/method during load time
Expand Down Expand Up @@ -92,6 +94,17 @@ class Instrumenter {
}
}

private checkValueSize(value: any): boolean {
try {
const valueSize = sizeof(value);
return valueSize <= MAX_VAR_VALUE_SIZE;
} catch (e) {
ThundraLogger.debug('Unable to check value size');
ThundraLogger.debug(e);
return true;
}
}

private packValue(value: any) {
// `==` is used on purpose (instead of `===`) as it covers both undefined and null values
if (value == null) {
Expand All @@ -104,9 +117,15 @@ class Instrumenter {
if (value instanceof Map || value instanceof Set) {
value = [...value];
}
let valueJson = null;
if (!this.checkValueSize(value)) {
return '<skipped: value too big>';
}
let valueJson: string = null;
try {
valueJson = stringify(value);
if (valueJson && valueJson.length > MAX_VAR_VALUE_SIZE) {
return '<skipped: value too big>';
}
return JSON.parse(valueJson);
} catch (e1) {
if (ThundraLogger.isDebugEnabled()) {
Expand Down

0 comments on commit d6602cf

Please sign in to comment.