seek-datadog-custom-metrics
Advanced tools
Comparing version 4.5.0 to 4.6.0
@@ -17,17 +17,24 @@ "use strict"; | ||
const startTime = process.hrtime.bigint(); | ||
const handleCompletion = (success) => { | ||
const handleCompletion = (success, result) => { | ||
var _a; | ||
const durationNanos = process.hrtime.bigint() - startTime; | ||
const successTag = success ? 'success' : 'failure'; | ||
const durationMilliseconds = Number(durationNanos) / 1e6; | ||
metricsClient.timing(`${name}.latency`, durationMilliseconds, tags); | ||
metricsClient.increment(`${name}.count`, [successTag, ...(tags !== null && tags !== void 0 ? tags : [])]); | ||
afterCompletion === null || afterCompletion === void 0 ? void 0 : afterCompletion(durationMilliseconds, success); | ||
const complete = afterCompletion === null || afterCompletion === void 0 ? void 0 : afterCompletion(durationMilliseconds, success, result); | ||
const tagsToAdd = tags || (complete === null || complete === void 0 ? void 0 : complete.tags) | ||
? [...(tags !== null && tags !== void 0 ? tags : []), ...((_a = complete === null || complete === void 0 ? void 0 : complete.tags) !== null && _a !== void 0 ? _a : [])] | ||
: undefined; | ||
metricsClient.timing(`${name}.latency`, durationMilliseconds, tagsToAdd); | ||
metricsClient.increment(`${name}.count`, [ | ||
successTag, | ||
...(tagsToAdd !== null && tagsToAdd !== void 0 ? tagsToAdd : []), | ||
]); | ||
}; | ||
try { | ||
const result = await block(); | ||
handleCompletion(true); | ||
handleCompletion(true, result); | ||
return result; | ||
} | ||
catch (e) { | ||
handleCompletion(false); | ||
handleCompletion(false, undefined); | ||
throw e; | ||
@@ -34,0 +41,0 @@ } |
@@ -14,17 +14,24 @@ /** | ||
const startTime = process.hrtime.bigint(); | ||
const handleCompletion = (success) => { | ||
const handleCompletion = (success, result) => { | ||
var _a; | ||
const durationNanos = process.hrtime.bigint() - startTime; | ||
const successTag = success ? 'success' : 'failure'; | ||
const durationMilliseconds = Number(durationNanos) / 1e6; | ||
metricsClient.timing(`${name}.latency`, durationMilliseconds, tags); | ||
metricsClient.increment(`${name}.count`, [successTag, ...(tags !== null && tags !== void 0 ? tags : [])]); | ||
afterCompletion === null || afterCompletion === void 0 ? void 0 : afterCompletion(durationMilliseconds, success); | ||
const complete = afterCompletion === null || afterCompletion === void 0 ? void 0 : afterCompletion(durationMilliseconds, success, result); | ||
const tagsToAdd = tags || (complete === null || complete === void 0 ? void 0 : complete.tags) | ||
? [...(tags !== null && tags !== void 0 ? tags : []), ...((_a = complete === null || complete === void 0 ? void 0 : complete.tags) !== null && _a !== void 0 ? _a : [])] | ||
: undefined; | ||
metricsClient.timing(`${name}.latency`, durationMilliseconds, tagsToAdd); | ||
metricsClient.increment(`${name}.count`, [ | ||
successTag, | ||
...(tagsToAdd !== null && tagsToAdd !== void 0 ? tagsToAdd : []), | ||
]); | ||
}; | ||
try { | ||
const result = await block(); | ||
handleCompletion(true); | ||
handleCompletion(true, result); | ||
return result; | ||
} | ||
catch (e) { | ||
handleCompletion(false); | ||
handleCompletion(false, undefined); | ||
throw e; | ||
@@ -31,0 +38,0 @@ } |
import type { MetricsClient } from './MetricsClient'; | ||
type TimingMetricsClient = Pick<MetricsClient, 'increment' | 'timing'>; | ||
interface AfterCompletion { | ||
tags: string[]; | ||
} | ||
/** | ||
@@ -14,3 +17,3 @@ * Sends timing related metrics for an asynchronous operation | ||
*/ | ||
export declare const createTimedSpan: (metricsClient: TimingMetricsClient) => <T>(name: string, block: () => PromiseLike<T>, afterCompletion?: ((duration: number, success: boolean) => void) | undefined, tags?: string[]) => Promise<T>; | ||
export declare const createTimedSpan: (metricsClient: TimingMetricsClient) => <T>(name: string, block: () => PromiseLike<T>, afterCompletion?: ((duration: number, success: boolean, result: T | undefined) => AfterCompletion | void) | undefined, tags?: string[]) => Promise<T>; | ||
export {}; |
{ | ||
"name": "seek-datadog-custom-metrics", | ||
"version": "4.5.0", | ||
"version": "4.6.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Helpers for sending Datadog custom metrics", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58967
867