Skip to content

Commit e59a99f

Browse files
authored
Remove global version tag and CloudWatch client (#310)
BREAKING CHANGE: The following clients have breaking changes: - CloudWatch client has been removed. It was deprecated in [v4.2.0](https://github.com/seek-oss/datadog-custom-metrics/releases/tag/v4.2.0) (March 2023) and there is very limited usage remaining at SEEK. Migrate to the Lambda Extension client. - StatsD client no longer attaches the global `version` tag to custom metrics, and `env` is now optional. These tags are automatically applied via telemetry agents in SEEK's typical container workload hosting environments. | Environment | `env` | `version` | :-- | :-- | :-- | Automat | Automat environment name (`development` \| `production`) | `{deployment}-{version}`, e.g. `myDeploymentName-abcdefa.123` | Gantry | Gantry environment name | `VERSION` environment variable, e.g. `abcdefa.123` Some Gantry services may have a Gantry environment name like `prod-1` and then supply a different value like `createStatsDClient({ environment: 'production' })` in code. This behaviour has been retained. It results in metrics that are tagged with both `env:prod-1` and `env:production`, and may be useful for forward compatibility with Automat's `development` | `production`.
1 parent f54638c commit e59a99f

11 files changed

+41
-266
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,34 @@ yarn add seek-datadog-custom-metrics
1414

1515
## Tagging convention
1616

17-
All custom metrics are prefixed by `AppConfig.name`.
18-
Two global tags are also added to every custom metric:
17+
All custom metrics are prefixed by `{config.name}.`.
18+
19+
One global tag may be optionally added to every custom metric:
1920

2021
- `AppConfig.environment` becomes `env:${value}`
21-
- `AppConfig.version` becomes `version:${value}`
2222

23-
These tags are consistent with tags sent by [Gantry](https://github.com/SEEK-Jobs/gantry) via Datadog's AWS integration.
23+
This behaviour has been retained for compatibility.
24+
Review whether you can rely on the `env` set by your Datadog agent;
25+
this will be the Automat or Gantry environment name at SEEK.
26+
27+
In some scenarios, you may still want to manually set a different environment.
28+
Some Gantry services may have a Gantry environment name like `prod-1` and then supply a different value like `production` here.
29+
This behaviour has been retained.
30+
It results in metrics that are tagged with both `env:prod-1` and `env:production`,
31+
and may be useful for forward compatibility with Automat's `development` | `production`.
2432

2533
## API reference
2634

2735
### `createStatsDClient`
2836

29-
`createStatsDClient` creates a [hot-shots](https://github.com/brightcove/hot-shots) client configured with our [tagging convention](#tagging-convention).
37+
`createStatsDClient` creates a [hot-shots](https://github.com/brightcove/hot-shots) client.
3038
This is intended for containerized services, particularly those deployed with [Gantry](https://github.com/SEEK-Jobs/gantry).
3139

3240
```typescript
3341
import { StatsD } from 'hot-shots';
3442
import { createStatsDClient } from 'seek-datadog-custom-metrics';
3543

36-
// Expects `name`, `version`, `environment` and `metricsServer` properties
44+
// Expects `name` and `metricsServer` properties
3745
import config from '../config';
3846

3947
// This example assumes Bunyan/pino

src/AppConfig.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@
33
*/
44
export interface AppConfig {
55
/**
6-
* Name of the application
6+
* Environment of the application
77
*
8-
* This is used to prefix custom metric names. It will typically be the name
9-
* of the app's GitHub repository.
10-
*/
11-
name: string;
12-
13-
/**
14-
* Version of the application
8+
* @deprecated Review whether you can rely on the `env` set by your Datadog
9+
* agent; this will be the Automat or Gantry environment name at SEEK.
1510
*
16-
* This is used to tag custom metrics. It will typically include a CI build
17-
* number and/or a commit hash.
11+
* In some scenarios, you may still want to manually set a different
12+
* environment here. Some Gantry services may have a Gantry environment name
13+
* like `prod-1` and then supply a different value like `production` here.
14+
* This behaviour has been retained. It results in metrics that are tagged
15+
* with both `env:prod-1` and `env:production`, and may be useful for forward
16+
* compatibility with Automat's `development` | `production`.
1817
*/
19-
version?: string | null | undefined;
18+
environment?: string;
2019

2120
/**
22-
* Environment of the application
21+
* Name of the application
2322
*
24-
* This is used to tag custom metrics. Typical examples are `prod` and `dev`.
23+
* This is used to prefix custom metric names. It should typically be the name
24+
* of the component that is being instrumented and match the Datadog `service`
25+
* tag and/or `DD_SERVICE` environment variable.
2526
*/
26-
environment: string;
27+
name: string;
2728
}

src/MetricsClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* Abstract interface for recording metrics
33
*
4-
* This was intended to cover both the StatsD and CloudWatch clients. As the
5-
* CloudWatch client type is now deprecated, consumers can use the richer
6-
* `StatsD` type from `hot-shots` instead.
4+
* @deprecated This was initially intended to cover both the StatsD and
5+
* CloudWatch clients. As the CloudWatch client is now removed, consumers can
6+
* use the richer `StatsD` type from `hot-shots` instead.
77
*/
88
export interface MetricsClient {
99
/**

src/createCloudWatchClient.test.ts

Lines changed: 0 additions & 138 deletions
This file was deleted.

src/createCloudWatchClient.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/createStatsDClient.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ describe('createStatsDClient', () => {
77
expect(
88
createStatsDClient(StatsD, {
99
name: 'test',
10-
environment: 'jest',
11-
version: '0',
10+
environment: 'deprecated-but-still-here',
1211
}),
1312
).toBeInstanceOf(Object);
1413
});
@@ -17,9 +16,6 @@ describe('createStatsDClient', () => {
1716
expect(
1817
createStatsDClient(StatsD, {
1918
name: 'test',
20-
environment: 'jest',
21-
version: null,
22-
2319
metricsServer: null,
2420
}),
2521
).toBeInstanceOf(Object);

src/createTimedSpan.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { createTimedSpan } from './createTimedSpan';
55

66
const metricsClient = createStatsDClient(StatsD, {
77
name: 'jest',
8-
version: '0.0.1',
9-
environment: 'dev',
108
});
119

1210
const timedSpan = createTimedSpan(metricsClient);

src/globalTags.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { globalTags } from './globalTags';
22

33
describe('globalTags', () => {
4-
it('should generate `env` and `version` tags', () => {
5-
expect(
6-
globalTags({ name: 'unused', environment: 'prod', version: '1234' }),
7-
).toEqual(['env:prod', 'version:1234']);
4+
it('should generate `env` tag when environment is supplied', () => {
5+
expect(globalTags({ name: 'unused', environment: 'prod' })).toStrictEqual([
6+
'env:prod',
7+
]);
88
});
99

10-
it("should generate only `env` when `version` isn't specified", () => {
11-
expect(globalTags({ name: 'unused', environment: 'dev' })).toEqual([
12-
'env:dev',
13-
]);
10+
it('should generate no tags when environment is not specified', () => {
11+
expect(globalTags({ name: 'unused' })).toStrictEqual([]);
1412
});
1513
});

src/globalTags.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { AppConfig } from './AppConfig';
22

33
export const globalTags = (config: AppConfig): string[] => {
4-
const { environment, version } = config;
4+
const { environment } = config;
55

6-
return [`env:${environment}`, ...(version ? [`version:${version}`] : [])];
6+
return environment ? [`env:${environment}`] : [];
77
};

src/index.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
createCloudWatchClient,
32
createLambdaExtensionClient,
43
createNoOpClient,
54
createStatsDClient,
@@ -12,10 +11,6 @@ describe('index', () => {
1211
expect(createStatsDClient).toBeInstanceOf(Function);
1312
});
1413

15-
it('should export a createCloudWatchClient function', () => {
16-
expect(createCloudWatchClient).toBeInstanceOf(Function);
17-
});
18-
1914
it('should export a createLambdaExtensionClient function', () => {
2015
expect(createLambdaExtensionClient).toBeInstanceOf(Function);
2116
});

0 commit comments

Comments
 (0)