Description

MikroMetric is a Lambda-oriented lightweight wrapper for producing AWS CloudWatch Embedded Metric Format-compatible metric logs.

Example

// ES5 format
const { MikroMetric } = require('mikrometric');
// ES6 format
import { MikroMetric } from 'mikrometric';

const mikroMetric = MikroMetric.start({ namespace: 'MyNamespace', serviceName: 'MyServiceName' });

mikroMetric.putDimension('User', 'Sam Person');
mikroMetric.putMetric('Duration', 83, 'Milliseconds');
mikroMetric.setProperty('CorrelationId', '8d5a0ba6-05e0-4c9b-bc7c-9164ea1bdedd');

mikroMetric.flush();

Constructors

Properties

context: any
correlationId: string
event: any
instance: MikroMetric
metadataConfig: StaticMetadataConfigInput | Record<string, any> = {}
namespace: string
serviceName: string

Methods

  • Parameters

    • array: any[]
    • maximumLength: number

    Returns void

    Description

    Validate if the length of an array is within acceptable bounds.

  • Parameters

    • stringToTest: string

    Returns void

    Description

    Check if a string contains any non-ASCII characters.

  • Parameters

    • value: string
    • maximumLength: number

    Returns void

    Description

    Validate if the length of a string is within acceptable bounds.

  • Parameters

    • correlationId: string

    Returns void

    Description

    Set correlation ID manually, for example for use in cross-boundary calls.

    This value will be propagated to all future metrics.

  • Parameters

    • namespace: string

    Returns void

    Description

    Set the namespace for the metric log.

    Example

    mikroMetric.setNamespace('MyNamespace');
    
  • Parameters

    Returns void

    Description

    Set a property onto the metric log.

    These will be shown in CloudWatch Logs (Insights) but not in CloudWatch Metrics.

    Example

    mikroMetric.setProperty('RequestId', '422b1569-16f6-4a03-b8f0-fe3fd9b100f8');
    
  • Parameters

    • input: Record<string, any>

    Returns any

    Description

    Alphabetically sort the fields in the log object.

  • Parameters

    Returns MikroMetric

    Description

    This instantiates MikroMetric. In order to be able to "remember" event and context we use a singleton pattern to reuse the same logical instance.

    Example

    mikroMetric.start({ namespace: 'MyNamespace', serviceName: 'MyService' });
    

Generated using TypeDoc