@tryghost/metrics 3.4.0 → 3.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,6 +14,53 @@ Ghost metrics facade for collecting and emitting operational metrics across serv
14
14
 
15
15
  ## Usage
16
16
 
17
+ The default export is a pre-configured `GhostMetrics` instance, built from the
18
+ `loggingrc` file at the process root if one exists. The `GhostMetrics` class is
19
+ attached to it for creating additional instances.
20
+
21
+ ```js
22
+ const metrics = require('@tryghost/metrics');
23
+
24
+ await metrics.metric('memory-usage', process.memoryUsage().heapUsed);
25
+
26
+ const custom = new metrics.GhostMetrics({
27
+ domain: 'my-service',
28
+ metrics: { transports: ['stdout'] },
29
+ });
30
+ ```
31
+
32
+ ### Types
33
+
34
+ Types ship with the package. `GhostMetrics` is exported as both a value (the
35
+ class) and a type (an instance of it), alongside the options and shipper types:
36
+
37
+ ```ts
38
+ import metrics, { GhostMetrics } from '@tryghost/metrics';
39
+ import type {
40
+ GhostMetrics as GhostMetricsInstance,
41
+ GhostMetricsOptions,
42
+ MetricsOptions,
43
+ ElasticsearchOptions,
44
+ MetricShipper,
45
+ } from '@tryghost/metrics';
46
+
47
+ const options: GhostMetricsOptions = { domain: 'my-service' };
48
+ const custom: GhostMetricsInstance = new GhostMetrics(options);
49
+
50
+ function ship(instance: GhostMetricsInstance, name: string, value: unknown) {
51
+ return instance.metric(name, value);
52
+ }
53
+ ```
54
+
55
+ In a CommonJS file the whole surface is reachable through a single import:
56
+
57
+ ```ts
58
+ import metrics = require('@tryghost/metrics');
59
+
60
+ const custom: metrics.GhostMetrics = new metrics.GhostMetrics({ domain: 'my-service' });
61
+ const options: metrics.GhostMetricsOptions = {};
62
+ ```
63
+
17
64
  ## Develop
18
65
 
19
66
  This is a mono repository, managed with [Nx](https://nx.dev).
package/lib/metrics.d.ts CHANGED
@@ -1,18 +1,23 @@
1
- import GhostMetrics = require('./GhostMetrics');
1
+ import GhostMetricsClass = require('./GhostMetrics');
2
2
 
3
3
  /**
4
4
  * A pre-configured `GhostMetrics` instance (built from `loggingrc` if present),
5
5
  * with the `GhostMetrics` class attached for creating additional instances.
6
6
  */
7
- declare const metrics: GhostMetrics & {
8
- GhostMetrics: typeof GhostMetrics;
7
+ declare const metrics: GhostMetricsClass & {
8
+ GhostMetrics: typeof GhostMetricsClass;
9
9
  };
10
10
 
11
11
  declare namespace metrics {
12
- export type ElasticsearchOptions = GhostMetrics.ElasticsearchOptions;
13
- export type MetricsOptions = GhostMetrics.MetricsOptions;
14
- export type GhostMetricsOptions = GhostMetrics.GhostMetricsOptions;
15
- export type MetricShipper = GhostMetrics.MetricShipper;
12
+ /**
13
+ * Instance type of the `GhostMetrics` class, so consumers can annotate
14
+ * values with `GhostMetrics` without reaching for `InstanceType<>`.
15
+ */
16
+ export type GhostMetrics = GhostMetricsClass;
17
+ export type ElasticsearchOptions = GhostMetricsClass.ElasticsearchOptions;
18
+ export type MetricsOptions = GhostMetricsClass.MetricsOptions;
19
+ export type GhostMetricsOptions = GhostMetricsClass.GhostMetricsOptions;
20
+ export type MetricShipper = GhostMetricsClass.MetricShipper;
16
21
  }
17
22
 
18
23
  export = metrics;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/metrics",
3
- "version": "3.4.0",
3
+ "version": "3.4.2",
4
4
  "license": "MIT",
5
5
  "author": "Ghost Foundation",
6
6
  "repository": {
@@ -20,13 +20,13 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "json-stringify-safe": "5.0.1",
23
- "@tryghost/pretty-stream": "2.3.6",
24
- "@tryghost/elasticsearch": "5.4.3",
25
- "@tryghost/root-utils": "2.3.6"
23
+ "@tryghost/elasticsearch": "^5.4.5",
24
+ "@tryghost/pretty-stream": "^2.3.8",
25
+ "@tryghost/root-utils": "^2.3.8"
26
26
  },
27
27
  "devDependencies": {
28
28
  "rewire": "9.0.1",
29
- "sinon": "22.0.0"
29
+ "sinon": "22.1.0"
30
30
  },
31
31
  "scripts": {
32
32
  "dev": "echo \"Implement me!\"",