Skip to content

Adding logging tag to identify requests #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 29, 2018
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

For clients that use multiple streams in parallel, it is currently pretty hard to identify what log message correlate to which stream. This PR fixes this and tags the logline with a unique request ID that is used throughout an operations lifetime:

Firestore (0.14.1) 2018-06-27T17:45:08.120Z ##### [Firestore]: Initialized Firestore
Firestore (0.14.1) 2018-06-27T17:45:08.123Z qsSNg [WriteBatch.commit]: Sending 1 writes
Firestore (0.14.1) 2018-06-27T17:45:08.150Z ##### [Firestore]: Initialized Firestore GAPIC Client
Firestore (0.14.1) 2018-06-27T17:45:08.152Z ##### [Firestore._ensureClient]: Detected project ID: node-review
Firestore (0.14.1) 2018-06-27T17:45:08.155Z qsSNg [Firestore.request]: Sending request: {"database":"projects/node-review/databases/(default)","writes":[{"update":{"name":"projects/node-review/databases/(default)/documents/node_0.14.1_thn4G5JVQ5sMinovfHQU/oxeXCjUOkiZlQvmrTxpx","fields":{"foo":{"valueType":"stringValue","stringValue":"a"}}},"currentDocument":{"exists":false}}]}
Firestore (0.14.1) 2018-06-27T17:45:08.672Z qsSNg [Firestore.request]: Received response: {"writeResults":[{"transformResults":[],"updateTime":{"seconds":"1530121508","nanos":620688000}}],"commitTime":{"seconds":"1530121508","nanos":620688000}}
Firestore (0.14.1) 2018-06-27T17:45:08.672Z cHU8c [Firestore.readStream]: Sending request: {"database":"projects/node-review/databases/(default)","documents":["projects/node-review/databases/(default)/documents/node_0.14.1_thn4G5JVQ5sMinovfHQU/oxeXCjUOkiZlQvmrTxpx"]}
Firestore (0.14.1) 2018-06-27T17:45:08.781Z cHU8c [Firestore.readStream]: Received response: {"transaction":[],"readTime":{"seconds":"1530121508","nanos":741889000},"found":{"fields":{"foo":{"stringValue":"a","valueType":"stringValue"}},"name":"projects/node-review/databases/(default)/documents/node_0.14.1_thn4G5JVQ5sMinovfHQU/oxeXCjUOkiZlQvmrTxpx","createTime":{"seconds":"1530121508","nanos":620688000},"updateTime":{"seconds":"1530121508","nanos":620688000}},"result":"found"}
Firestore (0.14.1) 2018-06-27T17:45:08.782Z cHU8c [Firestore._initializeStream]: Releasing stream
Firestore (0.14.1) 2018-06-27T17:45:08.783Z cHU8c [Firestore.getAll_]: Received document: projects/node-review/databases/(default)/documents/node_0.14.1_thn4G5JVQ5sMinovfHQU/oxeXCjUOkiZlQvmrTxpx
Firestore (0.14.1) 2018-06-27T17:45:08.784Z cHU8c [Firestore._initializeStream]: Received stream end
Firestore (0.14.1) 2018-06-27T17:45:08.785Z cHU8c [Firestore.getAll_]: Received 1 results

This is overall a pretty ugly implementation. If you can think of a better way, let me know.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 27, 2018
self._backoff.resetToMax();
}

resetStream();
} else {
Firestore.log('Watch.onSnapshot', 'Stream ended, sending error: ', err);

This comment was marked as spam.

Copy link

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good. Just a few nits to think about.

src/index.js Outdated
@@ -518,6 +518,7 @@ follow these steps, YOUR APP MAY BREAK.`);
}

let transaction = new Transaction(this, previousTransaction);
let requestTag = transaction.requestTag;

This comment was marked as spam.

This comment was marked as spam.

* @returns {string} A random 5-character wide identifier.
*/
static requestTag() {
return Firestore.autoId().substr(0, 5);

This comment was marked as spam.

This comment was marked as spam.

src/reference.js Outdated

return this._firestore
.request('listCollectionIds', request)
.request('listCollectionIds', request, requestTag)

This comment was marked as spam.

This comment was marked as spam.

src/index.js Outdated
@@ -1160,7 +1236,7 @@ follow these steps, YOUR APP MAY BREAK.`);
* @private
* @type {Firestore~logFunction}
*/
Firestore.log = function() {};
Firestore.log = function(methodName, logMessage, varargs) {};

This comment was marked as spam.

This comment was marked as spam.

src/index.js Outdated
@@ -1172,13 +1248,15 @@ Firestore.log = function() {};
Firestore.setLogFunction = function(logger) {
validate.isFunction('logger', logger);

Firestore.log = function(methodName, varargs) {
varargs = Array.prototype.slice.call(arguments, 1);
Firestore.log = function(methodName, requestTag, varargs) {

This comment was marked as spam.

This comment was marked as spam.

@@ -299,7 +314,7 @@ class Transaction {
}

return this._firestore
.request('beginTransaction', request, /* allowRetries= */ true)
.request('beginTransaction', request, this._requestTag, true)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* @private
* @return {string} A unique client-generated identifier for this transaction.
*/
get requestTag() {

This comment was marked as spam.

This comment was marked as spam.

* @param {Error} error An error object.
* @return {boolean} Whether the error is permanent.
*/
isPermanentError(error) {

This comment was marked as spam.

This comment was marked as spam.

@codecov
Copy link

codecov bot commented Jun 27, 2018

Codecov Report

Merging #228 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #228   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          13     13           
  Lines        1837   1846    +9     
=====================================
+ Hits         1837   1846    +9
Impacted Files Coverage Δ
src/watch.js 100% <100%> (ø) ⬆️
src/transaction.js 100% <100%> (ø) ⬆️
src/reference.js 100% <100%> (ø) ⬆️
src/index.js 100% <100%> (ø) ⬆️
src/write-batch.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c1f409...4f57bd9. Read the comment docs.

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. Comments addressed.

src/index.js Outdated
@@ -518,6 +518,7 @@ follow these steps, YOUR APP MAY BREAK.`);
}

let transaction = new Transaction(this, previousTransaction);
let requestTag = transaction.requestTag;

This comment was marked as spam.

* @returns {string} A random 5-character wide identifier.
*/
static requestTag() {
return Firestore.autoId().substr(0, 5);

This comment was marked as spam.

src/index.js Outdated
@@ -1160,7 +1236,7 @@ follow these steps, YOUR APP MAY BREAK.`);
* @private
* @type {Firestore~logFunction}
*/
Firestore.log = function() {};
Firestore.log = function(methodName, logMessage, varargs) {};

This comment was marked as spam.

src/index.js Outdated
@@ -1172,13 +1248,15 @@ Firestore.log = function() {};
Firestore.setLogFunction = function(logger) {
validate.isFunction('logger', logger);

Firestore.log = function(methodName, varargs) {
varargs = Array.prototype.slice.call(arguments, 1);
Firestore.log = function(methodName, requestTag, varargs) {

This comment was marked as spam.

src/reference.js Outdated

return this._firestore
.request('listCollectionIds', request)
.request('listCollectionIds', request, requestTag)

This comment was marked as spam.

* @private
* @return {string} A unique client-generated identifier for this transaction.
*/
get requestTag() {

This comment was marked as spam.

* @param {Error} error An error object.
* @return {boolean} Whether the error is permanent.
*/
isPermanentError(error) {

This comment was marked as spam.

@ghost ghost added the in progress label Jun 29, 2018
Copy link

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a nit.

Copy link

@laurenzlong laurenzlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved based on Hiranya's review, and the fact that his comment was addressed.

@schmidt-sebastian schmidt-sebastian merged commit 2755458 into master Jun 29, 2018
@ghost ghost removed the in progress label Jun 29, 2018
@schmidt-sebastian schmidt-sebastian deleted the requestlogging branch July 24, 2018 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants