From e603b458af6a036bc248cbe53f30a12c262ba1e8 Mon Sep 17 00:00:00 2001 From: Simon Schick Date: Mon, 30 Sep 2019 16:00:15 +0400 Subject: [PATCH 1/3] Ignore file-upload meteor-method by ostrio:files The package ostrio:files registers meteor-method calls starting by "_FilesCollectionWrite_" followed by the name of the file-collection. These method-calls are used to upload files to the server. Monitoring these methods (which come in rapidly as we want to upload the file fastest possible) would result in sending the full file in a EJSON encoded way also to the monitoring system. --- instrumenting/session.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumenting/session.js b/instrumenting/session.js index 6881d13..9d2aba6 100644 --- a/instrumenting/session.js +++ b/instrumenting/session.js @@ -12,7 +12,8 @@ function start(agent, Session) { agent.setCustomContext(msg.params || {}); agent.setUserContext({ id: this.userId || 'Not authorized' }); - if (transaction) { + // _FilesCollectionWrite_ is a prefix for meteor-methods used by meteor/ostrio:files. It sends files via DDP to the server. Monitoring it would send the file - byte-serialized - on to the monitoring system. + if (transaction && (!msg.method || !msg.method.startsWith('_FilesCollectionWrite_'))) { transaction.addLabels({ params: JSON.stringify(msg.params) }); From 07dc8cf1f7c9bd530e12c63673307520f3c67b5e Mon Sep 17 00:00:00 2001 From: Simon Schick Date: Wed, 12 Feb 2020 13:24:25 +0400 Subject: [PATCH 2/3] Higher ignore and mentioned the change in reporting in the docs --- README.md | 1 + instrumenting/session.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8f4ec5e..aa65eea 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Complete list of [Agent options](https://www.elastic.co/guide/en/apm/agent/nodej ## What it monitors 1. Meteor methods: method params, result, exceptions, stack trace + * Ignores methods starting with `_FilesCollectionWrite_`. (See: https://github.com/Meteor-Community-Packages/meteor-elastic-apm/issues/30) 2. Meteor pub/sub: tracks publications response time, params, exceptions, result 3. Meteor collection methods(find, insert, etc...): params, result, execution time 4. MongoDB cursor method(fetch, map, etc...): params, result, execution time diff --git a/instrumenting/session.js b/instrumenting/session.js index 9d2aba6..c1f85ef 100644 --- a/instrumenting/session.js +++ b/instrumenting/session.js @@ -4,7 +4,15 @@ function start(agent, Session) { function wrapSession(sessionProto) { shimmer.wrap(sessionProto, 'processMessage', function(original) { return function(msg) { - if (msg.msg === 'method' || msg.msg === 'sub') { + if ( + ( + msg.msg === 'method' + // _FilesCollectionWrite_ is a prefix for meteor-methods used by meteor/ostrio:files which is used to + // send files via DDP to the server. Monitoring these routes send the file - byte-serialized - to the monitoring system. + && !msg.method.startsWith('_FilesCollectionWrite_') + ) + || msg.msg === 'sub' + ) { const name = msg.msg === 'method' ? msg.method : msg.name; const type = msg.msg; const transaction = agent.startTransaction(name, type); @@ -12,8 +20,7 @@ function start(agent, Session) { agent.setCustomContext(msg.params || {}); agent.setUserContext({ id: this.userId || 'Not authorized' }); - // _FilesCollectionWrite_ is a prefix for meteor-methods used by meteor/ostrio:files. It sends files via DDP to the server. Monitoring it would send the file - byte-serialized - on to the monitoring system. - if (transaction && (!msg.method || !msg.method.startsWith('_FilesCollectionWrite_'))) { + if (transaction) { transaction.addLabels({ params: JSON.stringify(msg.params) }); From 56ab7ba20b5686a911af81f27d8989fcb678ede1 Mon Sep 17 00:00:00 2001 From: Simon Schick Date: Wed, 12 Feb 2020 13:31:31 +0400 Subject: [PATCH 3/3] Fixed eslint complains --- instrumenting/session.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/instrumenting/session.js b/instrumenting/session.js index c1f85ef..d9fa3b0 100644 --- a/instrumenting/session.js +++ b/instrumenting/session.js @@ -5,13 +5,11 @@ function start(agent, Session) { shimmer.wrap(sessionProto, 'processMessage', function(original) { return function(msg) { if ( - ( - msg.msg === 'method' + (msg.msg === 'method' && // _FilesCollectionWrite_ is a prefix for meteor-methods used by meteor/ostrio:files which is used to // send files via DDP to the server. Monitoring these routes send the file - byte-serialized - to the monitoring system. - && !msg.method.startsWith('_FilesCollectionWrite_') - ) - || msg.msg === 'sub' + !msg.method.startsWith('_FilesCollectionWrite_')) || + msg.msg === 'sub' ) { const name = msg.msg === 'method' ? msg.method : msg.name; const type = msg.msg;