Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update metric type to match beaver-logger-paypal #77

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { LOG_LEVEL, PROTOCOL } from "./constants";
import { extendIfDefined } from "./util";
import { type Transport, getHTTPTransport } from "./http";
import type { Metric, Payload } from "./types";
import type { MetricPayload, Payload } from "./types";

type LoggerOptions = {|
url?: string,
Expand All @@ -32,7 +32,7 @@ type LoggerOptions = {|
type ClientPayload = Payload;
type Log = (name: string, payload?: ClientPayload) => LoggerType; // eslint-disable-line no-use-before-define
type Track = (payload: ClientPayload) => LoggerType; // eslint-disable-line no-use-before-define
type LogMetric = (payload: Metric) => LoggerType; // eslint-disable-line no-use-before-define
type LogMetric = (payload: MetricPayload) => LoggerType; // eslint-disable-line no-use-before-define
type LogEvent = {|
level: $Values<typeof LOG_LEVEL>,
event: string,
Expand Down Expand Up @@ -65,7 +65,7 @@ export type LoggerType = {|
__buffer__: {|
get events(): $ReadOnlyArray<LogEvent>,
get tracking(): $ReadOnlyArray<Payload>,
get metrics(): $ReadOnlyArray<Metric>,
get metrics(): $ReadOnlyArray<MetricPayload>,
|},
|};

Expand All @@ -79,7 +79,7 @@ export function Logger({
}: LoggerOptions): LoggerType {
let events: Array<LogEvent> = [];
let tracking: Array<Payload> = [];
let metrics: Array<Metric> = [];
let metrics: Array<MetricPayload> = [];

const payloadBuilders: Array<Builder> = [];
const metaBuilders: Array<Builder> = [];
Expand Down Expand Up @@ -265,14 +265,15 @@ export function Logger({
return logger; // eslint-disable-line no-use-before-define
}

function metric(metricPayload: Metric): LoggerType {
function metric(metricPayload: MetricPayload): LoggerType {
if (!isBrowser()) {
return logger; // eslint-disable-line no-use-before-define
}

print(
LOG_LEVEL.DEBUG,
`metric.${metricPayload.name}`,
`metric.${metricPayload.metricNamespace}`,
// $FlowIssue difference between Payload and metric dimensions
metricPayload.dimensions || {}
);

Expand Down Expand Up @@ -357,7 +358,7 @@ export function Logger({
get tracking(): $ReadOnlyArray<Payload> {
return tracking;
},
get metrics(): $ReadOnlyArray<Metric> {
get metrics(): $ReadOnlyArray<MetricPayload> {
return metrics;
},
},
Expand Down
14 changes: 11 additions & 3 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

export type Payload = { [string]: string | boolean | null | void };

export type Metric = {|
name: string,
dimensions: Payload,
export type MetricPayload = {|
metricNamespace: string, // the name of the metric that's used for charting / finding in signalFx
metricEventName: string, // assigned to event_name dimension in signalFx
metricValue?: number, // in most cases this will be 1 if we want to count 1 instance of an event happening.
metricType?: "counter" | "gauge", // We support these types of metrics. Defaults to counter.
/**
* For proper usage & best practices guidance around dimensions please read: -------------------->
* - https://engineering.paypalcorp.com/confluence/pages/viewpage.action?pageId=981633893
* - https://engineering.paypalcorp.com/confluence/display/Checkout/Checkout+Observability+Overview
*/
dimensions?: { [string]: string },
|};
Loading