Skip to content

Commit

Permalink
Format with rome
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Beutell committed Jul 20, 2023
1 parent 210fe99 commit 02ae887
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
4 changes: 3 additions & 1 deletion packages/lib/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ async function pushToGateway(gateway: string) {
body: serialized,
});
if (!response.ok) {
console.error(`Error pushing metrics to gateway: ${response.statusText}`);
console.error(
`Error pushing metrics to gateway: ${response.statusText}`,
);
// NOTE - Uncomment to log the response body
// console.error(JSON.stringify(await response.text(), null, 2));
}
Expand Down
27 changes: 13 additions & 14 deletions packages/lib/src/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
HISTOGRAM_DESCRIPTION,
HISTOGRAM_NAME,
} from "./constants";
import { getMeter, eagerlyPushMetricsIfConfigured } from "./instrumentation";
import { eagerlyPushMetricsIfConfigured, getMeter } from "./instrumentation";
import type { Objective } from "./objectives";
import {
ALSInstance,
Expand Down Expand Up @@ -100,7 +100,6 @@ export type AutometricsOptions<F extends FunctionSig> = {
* should be considered a success (regardless if it threw an error). This
* may be most useful when you want to ignore certain errors that are thrown
* by the function.
*
*/
recordSuccessIf?: ReportSuccessCondition;
};
Expand All @@ -109,7 +108,7 @@ export type AutometricsOptions<F extends FunctionSig> = {
* @internal
*/
export type ReportErrorCondition<F extends FunctionSig> = (
result: Awaited<ReturnType<F>>
result: Awaited<ReturnType<F>>,
) => boolean;

/**
Expand Down Expand Up @@ -175,7 +174,7 @@ export type ReportSuccessCondition = (result: Error) => boolean;
*/
export function autometrics<F extends FunctionSig>(
functionOrOptions: F | AutometricsOptions<F>,
fnInput?: F
fnInput?: F,
): AutometricsWrapper<F> {
let functionName: string;
let moduleName: string;
Expand Down Expand Up @@ -220,7 +219,7 @@ export function autometrics<F extends FunctionSig>(

if (!functionName) {
console.trace(
"Autometrics decorated function must have a name to successfully create a metric. Function will not be instrumented."
"Autometrics decorated function must have a name to successfully create a metric. Function will not be instrumented.",
);
return fn;
}
Expand Down Expand Up @@ -384,7 +383,7 @@ export function autometrics<F extends FunctionSig>(
if (asyncLocalStorage) {
return asyncLocalStorage.run(
{ caller: functionName },
instrumentedFunction
instrumentedFunction,
);
}

Expand Down Expand Up @@ -466,18 +465,18 @@ type AutometricsDecoratorOptions<F> = F extends FunctionSig
* @group Wrapper and Decorator API
*/
export function Autometrics<T extends Function | Object>(
autometricsOptions?: AutometricsDecoratorOptions<T>
autometricsOptions?: AutometricsDecoratorOptions<T>,
) {
function decorator<T extends Function>(target: T): void;
function decorator<T extends Object>(
target: T,
propertyKey: string,
descriptor: PropertyDescriptor
descriptor: PropertyDescriptor,
): void;
function decorator<T extends Function | Object>(
target: T,
propertyKey?: string,
descriptor?: PropertyDescriptor
descriptor?: PropertyDescriptor,
) {
if (isFunction(target)) {
const classDecorator = getAutometricsClassDecorator(autometricsOptions);
Expand All @@ -502,12 +501,12 @@ export function Autometrics<T extends Function | Object>(
* @internal
*/
export function getAutometricsMethodDecorator(
autometricsOptions?: AutometricsOptions<FunctionSig>
autometricsOptions?: AutometricsOptions<FunctionSig>,
) {
return function (
_target: Object,
_propertyKey: string,
descriptor: PropertyDescriptor
descriptor: PropertyDescriptor,
) {
const originalFunction = descriptor.value;
const functionOrOptions = autometricsOptions ?? originalFunction;
Expand All @@ -527,7 +526,7 @@ export function getAutometricsMethodDecorator(
* @internal
*/
export function getAutometricsClassDecorator(
autometricsOptions?: AutometricsClassDecoratorOptions
autometricsOptions?: AutometricsClassDecoratorOptions,
): ClassDecorator {
return function (classConstructor: Function) {
const prototype = classConstructor.prototype;
Expand All @@ -538,7 +537,7 @@ export function getAutometricsClassDecorator(
const property = prototype[propertyName];
const descriptor = Object.getOwnPropertyDescriptor(
prototype,
propertyName
propertyName,
);

if (
Expand All @@ -552,7 +551,7 @@ export function getAutometricsClassDecorator(
const instrumentedDescriptor = methodDecorator(
{},
propertyName,
descriptor
descriptor,
);

Object.defineProperty(prototype, propertyName, instrumentedDescriptor);
Expand Down

0 comments on commit 02ae887

Please sign in to comment.