Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

seek-datadog-custom-metrics

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seek-datadog-custom-metrics - npm Package Compare versions

Comparing version 4.5.0 to 4.6.0

19

lib-commonjs/createTimedSpan.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc