Skip to content

Commit 8382f5e

Browse files
author
Mark Kuhn
authored
Add support to clear custom dimensions (#136)
* add support to clear custom dimensions * update readme * dependency updates
1 parent cc8ac0e commit 8382f5e

File tree

5 files changed

+571
-311
lines changed

5 files changed

+571
-311
lines changed

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ putDimensions({ Operation: "Aggregator" })
157157
putDimensions({ Operation: "Aggregator", DeviceType: "Actuator" })
158158
```
159159

160-
- **setDimensions**(Record<String, String>[] dimensions...)
160+
- **setDimensions**(Record<String, String> | Record<String, String>[] dimensions, boolean useDefault)
161161

162-
Explicitly override all dimensions. This will remove the default dimensions.
162+
Explicitly override all dimensions. This will remove the default dimensions unless the `useDefault` parameter is set to `true` (defaults to false).
163163

164164
**WARNING**: Every distinct value will result in a new CloudWatch Metric.
165165
If the cardinality of a particular value is expected to be high, you should consider
@@ -173,9 +173,26 @@ Requirements:
173173
Examples:
174174

175175
```js
176-
setDimensions(
176+
// Overwrites custom dimensions - keeps default dimensions
177+
setDimensions({Operation: "Aggregator"}, true)
178+
```
179+
180+
```js
181+
// Overwrites custom dimensions - removes default dimensions
182+
setDimensions([
177183
{ Operation: "Aggregator" },
178-
{ Operation: "Aggregator", DeviceType: "Actuator" })
184+
{ Operation: "Aggregator", DeviceType: "Actuator" }
185+
])
186+
```
187+
188+
- **resetDimensions**(boolean useDefault)
189+
190+
Explicitly clear all custom dimensions. Set `useDefault` to `true` to keep the default dimensions.
191+
192+
Example:
193+
194+
```js
195+
resetDimensions(false) // this will clear all custom dimensions as well as disable default dimensions
179196
```
180197

181198
- **setNamespace**(String value)
@@ -188,7 +205,7 @@ Requirements:
188205
- Name must be ASCII characters only
189206
- Namespaces must meet CloudWatch Namespace requirements, otherwise a `InvalidNamespaceError` will be thrown. See [Namespace](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace) for valid values.
190207

191-
Examples:
208+
Example:
192209

193210
```js
194211
setNamespace("MyApplication");
@@ -212,7 +229,24 @@ setTimestamp(new Date().getTime())
212229

213230
- **flush**()
214231

215-
Flushes the current MetricsContext to the configured sink and resets all properties, dimensions and metric values. The namespace and default dimensions will be preserved across flushes. Timestamp will be preserved if set explicitly via `setTimestamp()`.
232+
Flushes the current MetricsContext to the configured sink and resets all properties and metric values. The namespace and default dimensions will be preserved across flushes. Custom dimensions are preserved by default, but this behavior can be changed by setting `logger.flushPreserveDimensions = false`. Timestamp will be preserved if set explicitly via `setTimestamp()`.
233+
234+
Examples:
235+
236+
```js
237+
logger.flush() // custom and default dimensions will be preserved after each flush
238+
```
239+
240+
```js
241+
logger.flushPreserveDimensions = false
242+
logger.flush() // only default dimensions will be preserved after flush()
243+
```
244+
245+
```js
246+
logger.flushPreserveDimensions = false
247+
logger.resetDimensions(false)
248+
logger.flush() // default dimensions are disabled - no dimensions will be preserved after flush()
249+
```
216250

217251
## Configuration
218252

0 commit comments

Comments
 (0)