Skip to content

Commit 95a4456

Browse files
committed
Adjust proposal
1 parent 656e7c8 commit 95a4456

3 files changed

Lines changed: 28 additions & 30 deletions

File tree

src/createStatsDClient.test.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,28 @@ describe('createStatsDClient', () => {
1212
});
1313

1414
it('should handle null config values', () => {
15-
expect(
16-
createStatsDClient(StatsD, {
17-
metricsServer: null,
18-
name: 'test',
19-
}),
20-
).toBeInstanceOf(Object);
15+
delete process.env.DD_ENV;
16+
delete process.env.DD_SERVICE;
17+
delete process.env.DD_VERSION;
18+
19+
const client = createStatsDClient(StatsD, {
20+
metricsServer: null,
21+
name: 'test',
22+
});
23+
24+
client.timing('timing', new Date(1));
25+
26+
expect(client.mockBuffer).toMatchInlineSnapshot(`
27+
[
28+
"test.timing:1754822723343|ms",
29+
]
30+
`);
2131
});
2232

2333
it('should support the environment config option', () => {
24-
process.env.DD_ENV = 'my_env';
25-
process.env.DD_SERVICE = 'my_service';
26-
process.env.DD_VERSION = 'my_version';
34+
delete process.env.DD_ENV;
35+
delete process.env.DD_SERVICE;
36+
delete process.env.DD_VERSION;
2737

2838
const client = createStatsDClient(StatsD, {
2939
environment: 'deprecated-but-still-here',
@@ -40,14 +50,13 @@ describe('createStatsDClient', () => {
4050
`);
4151
});
4252

43-
it('should allow reading Datadog tags from environment', () => {
44-
process.env.DD_ENV = 'my_env';
53+
it('should append DD_ENV from environment', () => {
54+
process.env.DD_ENV = 'env_var';
4555
process.env.DD_SERVICE = 'my_service';
4656
process.env.DD_VERSION = 'my_version';
4757

4858
const client = createStatsDClient(StatsD, {
49-
environment: 'dd_env_takes_precedence_over_me',
50-
includeDataDogTags: true,
59+
environment: 'client_config',
5160
metricsServer: null,
5261
name: 'test',
5362
});
@@ -56,7 +65,7 @@ describe('createStatsDClient', () => {
5665

5766
expect(client.mockBuffer).toMatchInlineSnapshot(`
5867
[
59-
"test.counter:1|c|#env:my_env,service:my_service,version:my_version",
68+
"test.counter:1|c|#env:client_config,env:env_var",
6069
]
6170
`);
6271
});

src/createStatsDClient.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ type StatsD<T extends InternalStatsD> = new (options?: {
2121
* Configuration for building a StatsD client
2222
*/
2323
export interface StatsDConfig extends AppConfig {
24-
/**
25-
* Whether to read `DD_ENV`, `DD_SERVICE`, `DD_VERSION` environment variables
26-
* to populate global `env`, `service`, `version` tags.
27-
*
28-
* If this is set to `true`, `DD_ENV` will override the value provided in the
29-
* `environment` config option.
30-
*
31-
* For Gantry this should be set to `false`, as unified service tags are
32-
* automatically propagated to the Datadog agent sidecar during deployment.
33-
*
34-
* Defaults to `false`.
35-
*/
36-
includeDataDogTags?: boolean;
37-
3824
/**
3925
* Optional hostname of the metrics server
4026
*
@@ -67,7 +53,7 @@ export const createStatsDClient = <T extends InternalStatsD>(
6753
mock: !config.metricsServer,
6854
host,
6955
errorHandler,
70-
includeDataDogTags: config.includeDataDogTags ?? false,
56+
includeDataDogTags: false,
7157

7258
prefix: `${config.name}.`,
7359
globalTags: globalTags(config),

src/globalTags.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ import type { AppConfig } from './AppConfig.js';
33
export const globalTags = (config: AppConfig): string[] => {
44
const { environment } = config;
55

6-
return environment ? [`env:${environment}`] : [];
6+
return [
7+
...(environment ? [`env:${environment}`] : []),
8+
...(process?.env?.DD_ENV ? [`env:${process.env.DD_ENV}`] : []),
9+
];
710
};

0 commit comments

Comments
 (0)