Skip to content

Commit

Permalink
feat(datadog): add type tag
Browse files Browse the repository at this point in the history
Always add a tag for the type of asset. Examples:
* type:js
* type:css
  • Loading branch information
brandondoran committed Nov 1, 2018
1 parent abd6279 commit 0b85b69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -53,5 +53,7 @@ new DataDogStatsReporter(options: DataDogStatsReporterOptions);
- `apiKey: string`: Your DataDog API key
- `gzipSize?: boolean = true`: Report gzipped size if true, uncompressed size if false
- `metricName: string`: The base name for the metric
- `tags?: string[]`: Custom tags for the metric. A `chunk` tag is always added.
- `tags?: string[]`: Custom tags for the metric. The following tags are always added:
* `chunk`: the chunk name
* `type`: the type of asset (js, css, etc)
- `test?: RegExp`: Test to match files against. If not set, stats for all emitted assets will be sent.
10 changes: 7 additions & 3 deletions src/reporters/datadog.ts
Expand Up @@ -52,7 +52,7 @@ export class DataDogStatsReporter implements StatsReporter {
}
}

private filterAssets(stats: any) {
private filterAssets(stats: any): string[] {
const { assets } = stats;
if (!this.test) {
return assets;
Expand All @@ -72,14 +72,18 @@ export class DataDogStatsReporter implements StatsReporter {
return {
metric: `${this.metricName}.bytes${path.extname(asset.name)}`,
points: [[now, size]],
tags: [...this.tags, `chunk:${asset.chunkNames[0]}`],
tags: [
...this.tags,
`chunk:${asset.chunkNames[0]}`,
`type:${path.extname(asset.name).substring(1)}`
],
type: METRIC_TYPE_GAUGE
};
});
return Promise.all(promises);
}

private validateOptions() {
private validateOptions(): void {
const errors = [];
if (!this.apiKey) {
errors.push('apiKey is required.');
Expand Down

0 comments on commit 0b85b69

Please sign in to comment.