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

docs(metrics): Corrections to the docstrings code examples #314

Merged
merged 1 commit into from
Mar 7, 2021
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
4 changes: 1 addition & 3 deletions aws_lambda_powertools/metrics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def serialize_metric_set(self, metrics: Dict = None, dimensions: Dict = None, me
metric_names_and_units.append({"Name": metric_name, "Unit": metric_unit})
metric_names_and_values.update({metric_name: metric_value})

embedded_metrics_object = {
return {
"_aws": {
"Timestamp": int(datetime.datetime.now().timestamp() * 1000), # epoch
"CloudWatchMetrics": [
Expand All @@ -213,8 +213,6 @@ def serialize_metric_set(self, metrics: Dict = None, dimensions: Dict = None, me
**metric_names_and_values, # "single_metric": 1.0
}

return embedded_metrics_object

def add_dimension(self, name: str, value: str):
"""Adds given dimension to all metrics

Expand Down
8 changes: 4 additions & 4 deletions aws_lambda_powertools/metrics/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class SingleMetric(MetricManager):
-------
**Creates cold start metric with function_version as dimension**

from aws_lambda_powertools.metrics import SingleMetric, MetricUnit
import json
metric = Single_Metric(namespace="ServerlessAirline")
from aws_lambda_powertools.metrics import single_metric, MetricUnit
metric = single_metric(namespace="ServerlessAirline")

metric.add_metric(name="ColdStart", unit=MetricUnit.Count, value=1)
metric.add_dimension(name="function_version", value=47)
Expand Down Expand Up @@ -72,7 +72,7 @@ def single_metric(name: str, unit: MetricUnit, value: float, namespace: str = No
from aws_lambda_powertools.metrics import MetricUnit

with single_metric(name="ColdStart", unit=MetricUnit.Count, value=1, namespace="ServerlessAirline") as metric:
metric.add_dimension(name="function_version", value=47)
metric.add_dimension(name="function_version", value="47")

**Same as above but set namespace using environment variable**

Expand All @@ -82,7 +82,7 @@ def single_metric(name: str, unit: MetricUnit, value: float, namespace: str = No
from aws_lambda_powertools.metrics import MetricUnit

with single_metric(name="ColdStart", unit=MetricUnit.Count, value=1) as metric:
metric.add_dimension(name="function_version", value=47)
metric.add_dimension(name="function_version", value="47")

Parameters
----------
Expand Down
11 changes: 6 additions & 5 deletions aws_lambda_powertools/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ class Metrics(MetricManager):
metrics.add_dimension(name="function_version", value="$LATEST")
...

@tracer.capture_lambda_handler
@metrics.log_metrics()
def lambda_handler():
do_something()
return True
do_something()
return True

def do_something():
metrics.add_metric(name="Something", unit="Count", value=1)
metrics.add_metric(name="Something", unit="Count", value=1)

Environment variables
---------------------
Expand Down Expand Up @@ -111,12 +110,14 @@ def log_metrics(
-------
**Lambda function using tracer and metrics decorators**

from aws_lambda_powertools import Metrics, Tracer

metrics = Metrics(service="payment")
tracer = Tracer(service="payment")

@tracer.capture_lambda_handler
@metrics.log_metrics
def handler(event, context):
def handler(event, context):
...

Parameters
Expand Down