-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export a type for BufferedMetricsLogger (#120)
Even though we started generating TypeScript types from the JSDoc a while back, it turns out `BufferedMetricsLogger` was getting exported as a *value* and not a type. That technically works in TS, but requires some weird syntax and is definitely not what you want. This changes up our imports and exports a bit to get the TypeScript compiler to do the right thing, and adds a basic test of the types to make sure we don't regress. See #119.
- Loading branch information
Showing
5 changed files
with
73 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,3 +76,7 @@ jobs: | |
- name: Build Types | ||
run: | | ||
npm run build-types | ||
- name: Check Types | ||
run: | | ||
npm run check-types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
"check-codestyle": "npx eslint .", | ||
"check-text": "test/lint_text.sh", | ||
"build-types": "tsc --build", | ||
"check-types": "tsc --noEmit --strict test/types_check.ts", | ||
"clean": "tsc --build --clean" | ||
}, | ||
"keywords": [ | ||
|
@@ -27,6 +28,7 @@ | |
"author": "Daniel Bader <[email protected]> (http://dbader.org/)", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "^12.20.55", | ||
"chai": "4.3.6", | ||
"chai-string": "1.5.0", | ||
"eslint": "^8.24.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// This file is used to check the typings! It is not mean to be executed. | ||
import { | ||
BufferedMetricsLogger, | ||
reporters, | ||
init, | ||
flush, | ||
gauge, | ||
increment, | ||
histogram, | ||
distribution | ||
} from '..'; | ||
import type { BufferedMetricsLoggerOptions } from '..'; | ||
|
||
function useLogger(logger: BufferedMetricsLogger) { | ||
logger.gauge('gauge.key', 0); | ||
logger.increment('increment.key'); | ||
logger.histogram('histogram.key', 11); | ||
logger.distribution('distribution.key', 11); | ||
logger.flush(); | ||
} | ||
|
||
useLogger(new BufferedMetricsLogger()); | ||
|
||
init({ | ||
apiKey: 'abc123', | ||
appKey: 'xyz456', | ||
apiHost: 'datadoghq.eu', | ||
site: 'datadoghq.eu', | ||
prefix: 'key.prefix', | ||
host: 'some-name-for-this-machine', | ||
flushIntervalSeconds: 5, | ||
defaultTags: ['tag'], | ||
histogram: { | ||
aggregates: ['sum', 'avg'], | ||
percentiles: [0.99] | ||
}, | ||
onError (error) { console.error(error); }, | ||
aggregator: { | ||
addPoint (type: Function, key: string, value: number, tags: string[], host: string, timestampInMillis: number, options: any) { | ||
console.log("Adding a point!"); | ||
}, | ||
flush () { | ||
return []; | ||
} | ||
}, | ||
reporter: new reporters.NullReporter() | ||
}); | ||
|
||
gauge('gauge.key', 0); | ||
increment('increment.key'); | ||
histogram('histogram.key', 11); | ||
distribution('distribution.key', 11); | ||
flush(); |