Skip to content

Commit

Permalink
docs: updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi committed Aug 14, 2022
1 parent 56dd309 commit 6eebd7a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,20 @@ You can add default dimensions to your metrics by passing them as parameters in
const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
const DEFAULT_DIMENSIONS = { 'environment': 'prod', 'foo': 'bar' };

export class MyFunction implements LambdaInterface {
export class Lambda implements LambdaInterface {
// Decorate your handler class method
@metrics.logMetrics({ defaultDimensions: DEFAULT_DIMENSIONS })
public async handler(_event: any, _context: any): Promise<void> {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
}
}

export const handlerClass = new Lambda();
export const handler = handlerClass.handler.bind(handlerClass); // (1)
```

1. Binding your handler method allows your handler to access `this` within the class methods.

If you'd like to remove them at some point, you can use the `clearDefaultDimensions` method.

### Flushing metrics
Expand Down Expand Up @@ -362,15 +367,20 @@ The `logMetrics` decorator of the metrics utility can be used when your Lambda h

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

export class MyFunction implements LambdaInterface {
class Lambda implements LambdaInterface {

@metrics.logMetrics()
public async handler(_event: any, _context: any): Promise<void> {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
}
}

export const handlerClass = new Lambda();
export const handler = handlerClass.handler.bind(handlerClass); // (1)
```

1. Binding your handler method allows your handler to access `this` within the class methods.

=== "Example CloudWatch Logs excerpt"

```json hl_lines="2 7 10 15 22"
Expand Down Expand Up @@ -629,6 +639,8 @@ CloudWatch EMF uses the same dimensions across all your metrics. Use `singleMetr
}
}

export const myFunction = new Lambda();
export const handler = myFunction.handler;
export const handlerClass = new Lambda();
export const handler = handlerClass.handler.bind(handlerClass); // (1)
```

1. Binding your handler method allows your handler to access `this` within the class methods.

0 comments on commit 6eebd7a

Please sign in to comment.