|
| 1 | +.. _queryStats-toggle-logging: |
| 2 | + |
| 3 | +============================= |
| 4 | +Toggle $queryStats Log Output |
| 5 | +============================= |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 1 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +.. |queryStats| replace:: :pipeline:`$queryStats` |
| 16 | + |
| 17 | +.. include:: /includes/aggregation/queryStats/logging-intro.rst |
| 18 | + |
| 19 | +Including ``$queryStats`` output in the logs provides more information |
| 20 | +on specific ``$queryStats`` operations, but can negatively impact |
| 21 | +cluster performance as log updates take more time and resources. |
| 22 | + |
| 23 | +About this Task |
| 24 | +--------------- |
| 25 | + |
| 26 | +When MongoDB logs ``$queryStats`` output, the results are redacted and |
| 27 | +anonymized. ``$queryStats`` output does not contain literals or field |
| 28 | +values. |
| 29 | + |
| 30 | +For an example of transformed ``$queryStats`` output, see |
| 31 | +:ref:`queryStats-example-transformed`. |
| 32 | + |
| 33 | +Steps |
| 34 | +----- |
| 35 | + |
| 36 | +.. procedure:: |
| 37 | + :style: normal |
| 38 | + |
| 39 | + .. step:: Open the :guilabel:`Database Deployments` page for your project |
| 40 | + |
| 41 | + .. step:: Click :guilabel:`Edit Config` |
| 42 | + |
| 43 | + .. step:: Select your cluster from the dropdown |
| 44 | + |
| 45 | + .. step:: Open the :guilabel:`Additional Settings` dropdown |
| 46 | + |
| 47 | + .. step:: Open the :guilabel:`More Configuration Options` dropdown |
| 48 | + |
| 49 | + .. step:: Toggle the :guilabel:`Enable Logging of Redacted and Anonymized Query Data` setting |
| 50 | + |
| 51 | + .. step:: Click :guilabel:`Review Changes` |
| 52 | + |
| 53 | + .. step:: Click :guilabel:`Apply Changes` |
| 54 | + |
| 55 | +Examples |
| 56 | +-------- |
| 57 | + |
| 58 | +The following examples show the differences in log messages when |
| 59 | +``$queryStats`` output is included. |
| 60 | + |
| 61 | +.. note:: |
| 62 | + |
| 63 | + The example log entries are reformatted for readability. |
| 64 | + |
| 65 | +``$queryStats`` Output Omitted (Default Behavior) |
| 66 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 67 | + |
| 68 | +.. code-block:: javascript |
| 69 | + :copyable: false |
| 70 | + |
| 71 | + { |
| 72 | + "t":{"$date":"2023-11-27T20:58:59.212+00:00"},"s":"D1", "c":"QRYSTATS", |
| 73 | + "id":7808300, "ctx":"conn31","msg":"Logging invocation |
| 74 | + $queryStats","attr":{"commandSpec":{"transformIdentifiers":{"algorithm":"hmac-sha-256","hmacKey":"###"}} |
| 75 | + } |
| 76 | + |
| 77 | +``$queryStats`` Output Included |
| 78 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 79 | + |
| 80 | +.. code-block:: javascript |
| 81 | + :copyable: false |
| 82 | + |
| 83 | + { |
| 84 | + "t":{"$date":"2023-11-27T20:58:59.212+00:00"},"s":"D1", "c":"QRYSTATS", |
| 85 | + "id":7808300, "ctx":"conn31","msg":"Logging invocation |
| 86 | + $queryStats","attr":{"commandSpec":{"transformIdentifiers":{"algorithm":"hmac-sha-256","hmacKey":"###"}} |
| 87 | + } |
| 88 | + |
| 89 | + { |
| 90 | + "t":{"$date":"2023-11-27T20:58:59.212+00:00"},"s":"D3", "c":"QRYSTATS", |
| 91 | + "id":7808301, "ctx":"conn31","msg":"Logging all outputs of |
| 92 | + $queryStats","attr":{"thisOutput":"{key: {queryShape: {cmdNs: {db: |
| 93 | + \"hYt+nW/sr1/Zc3YR8nlGWFoesJdvywkw+cR9rMGzXU4=\", coll: |
| 94 | + \"TRx6R3rvstYgX96gNmeOi5E3QVsOqzRbv7A9j3q7OvM=\"}, command: \"find\", |
| 95 | + filter: {Wb/Uu22DzKZ/Os+ZvLgPKFKGZPV4cIMZ3Ybv1HfYih4=: {$lt: |
| 96 | + \"?date\"}}, projection: {r5zQZllsGoqQuQp4Jm0eH2M6RrMqH84KHowcFaiverg=: |
| 97 | + true}, sort: {r5zQZllsGoqQuQp4Jm0eH2M6RrMqH84KHowcFaiverg=: 1}}, |
| 98 | + readConcern: {}, collectionType: \"nonExistent\"}, metrics: |
| 99 | + {lastExecutionMicros: 208, execCount: 21, totalExecMicros: {sum: 6079, |
| 100 | + max: 1875, min: 198, sumOfSquares: 4401645}, firstResponseExecMicros: |
| 101 | + {sum: 6079, max: 1875, min: 198, sumOfSquares: 4401645}, docsReturned: |
| 102 | + {sum: 0, max: 0, min: 0, sumOfSquares: 0}, firstSeenTimestamp: |
| 103 | + 2023-11-27T19:15:51.317Z, latestSeenTimestamp: |
| 104 | + 2023-11-27T20:55:51.309Z}, asOf: 2023-11-27T20:58:59.212Z}"} |
| 105 | + } |
| 106 | + |
| 107 | + { |
| 108 | + "t":{"$date":"2023-11-27T20:58:59.213+00:00"},"s":"D3", "c":"QRYSTATS", |
| 109 | + "id":7808301, "ctx":"conn31","msg":"Logging all outputs of |
| 110 | + $queryStats","attr":{"thisOutput":"{key: {queryShape: {cmdNs: {db: |
| 111 | + \"j+Caz+gxt7vl++gmeCAWrvyhDL17WaNrSIDi6Au7VI0=\", coll: |
| 112 | + \"f/LCkK/kVEbt4fk2NNbyDPhxas+kzCLLcVbjeNBbhyg=\"}, let: |
| 113 | + {pUZAyEEImSXcu8deG05tfIf6F/H92YsFnkZXIeRQtgc=: \"?number\"}, command: |
| 114 | + \"aggregate\", pipeline: [{$group: {_id: \"?number\", |
| 115 | + 5E6FSc5VxCvIZK0jrqkY3k3aX51jSc73hQwO/8kH0lo=: {$sum: \"?number\"}}}], |
| 116 | + explain: true, allowDiskUse: false}, client: {driver: {name: |
| 117 | + \"nodejs|mongosh\", version: \"5.1.0\"}, os: {type: \"Darwin\", name: |
| 118 | + \"darwin\", architecture: \"arm64\", version: \"22.6.0\"}, platform: |
| 119 | + \"Node.js v16.19.1, LE (unified)\", version: \"5.1.0|1.8.0\", |
| 120 | + application: {name: \"mongosh 1.8.0\"}}, collectionType: \"collection\", |
| 121 | + cursor: {batchSize: \"?number\"}}, metrics: {lastExecutionMicros: 0, |
| 122 | + execCount: 1, totalExecMicros: {sum: 0, max: 0, min: 0, sumOfSquares: |
| 123 | + 0}, firstResponseExecMicros: {sum: 0, max: 0, min: 0, sumOfSquares: 0}, |
| 124 | + docsReturned: {sum: 0, max: 0, min: 0, sumOfSquares: 0}, |
| 125 | + firstSeenTimestamp: 2023-11-27T19:31:36.463Z, latestSeenTimestamp: |
| 126 | + 2023-11-27T19:31:36.463Z}, asOf: 2023-11-27T20:58:59.213Z}"} |
| 127 | + } |
| 128 | + |
| 129 | + // Additional $queryStats output... |
| 130 | + |
| 131 | +Learn More |
| 132 | +---------- |
| 133 | + |
| 134 | +- :ref:`auditing` |
| 135 | + |
| 136 | +- :ref:`audit-message` |
| 137 | + |
| 138 | +- :atlas:`Configure a Custom Auditing Filter </database-auditing/#std-label-auditing-custom-filter>` |
0 commit comments