Skip to content

MetricBuilder

Declares a Metric projected from the Events added to it.

Every selected Event adds one entry to the Metric’s time series, valued by its calculation handler and tagged with the values its Dimension handlers resolve. Projection runs after the publishing Mutation or Listener completes, so a Metric can lag the Events it counts.

A deliveries Metric with two Dimensions

const deliveries = app.addMetric('deliveries');
deliveries.addEvent(sendgrid.templates.delivery.events.delivered);
deliveries.addEvent(slack.templates.delivery.events.delivered);
deliveries.addDimension(deliveryDimension, 1, deliveryDimensionHandler);
deliveries.addDimension(automationDimension, 2, automationDimensionHandler);

readonly dimensions: Record<string, { dimension: MetricDimensionBuilder; handler: MetricDimensionHandler; }>

Attached Dimensions and their handlers, keyed by Dimension key.


readonly prn: string

Platform Resource Name of the declared resource, derived from the App key and resource key.

BaseBuilder.prn

addDimension(dimension, position, handler): this

Attaches a Dimension to this Metric at one of four positions.

MetricDimensionBuilder

Dimension declared with AppBuilder.addMetricDimension.

1 | 2 | 3 | 4

Column position, 1 to 4.

MetricDimensionHandler

Resolver of the Dimension value for each Event.

this

This builder for chaining.

The position selects the projection column that stores the value, so each position holds one Dimension. Attaching a Dimension with the same key again replaces the earlier handler and position.

MetricDimensionHandler


addEvent(event, handler?): this

Selects an Event whose occurrences the Metric counts.

EventBuilder

Event to count.

MetricCalculationHandler

Computes the value each Event contributes.

this

This builder for chaining.

Events from any App in the composition can be selected. Without a handler each Event contributes 1.

MetricCalculationHandler


addGrant(role): MetricGrant

Grants an App Role permission to query this Metric.

AppRoleBuilder

App Role receiving access.

MetricGrant

The Grant builder.

Grant access


setDescription(description): this

Sets the description emitted into the definition and rendered in generated reference and application assets.

string

Human-readable description of the resource.

this

This builder for chaining.

BaseBuilder.setDescription