Skip to content

Commit 3f9865a

Browse files
committed
Merge branch 'develop' into pydantic
* develop: (26 commits) docs: move tenets; remove extra space docs: use table for clarity docs: add blog post, and quick example docs: subtle rewording for better clarity docs: fix typos, log_event & sampling wording docs: make sensitive info more explicit with an example docs: create Patching modules section; cleanup response wording docs: move concurrent asynchronous under escape hatch chore: update internal docstrings for consistency fix: remove actual response from debug logs docs: grammar docs: bring new feature upfront when returning sensitive info chore: update changelog to reflect new feature chore: clarify changelog bugfix vs breaking change chore: remove/correct unnecessary debug logs chore: fix debug log adding unused obj fix: naming and staticmethod consistency improv: naming consistency fix: correct in_subsegment assertion feat: capture_response as metadata option #127 ...
2 parents 913e310 + d0aaad5 commit 3f9865a

File tree

11 files changed

+311
-122
lines changed

11 files changed

+311
-122
lines changed

CHANGELOG.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
- **Metrics**: Cold start metric is now completely separate from application metrics dimensions, making it easier and cheaper to visualize.
11+
- This is a breaking change if you were graphing/alerting on both application metrics with the same name to compensate this previous malfunctioning
12+
- Marked as bugfix as this is the intended behaviour since the beginning, as you shouldn't have the same application metric with different dimensions
13+
14+
### Added
15+
- **Tracer**: capture_lambda_handler and capture_method decorators now support `capture_response` parameter to not include function's response as part of tracing metadata
16+
917
## [1.3.1] - 2020-08-22
1018
### Fixed
1119
- **Tracer**: capture_method decorator did not properly handle nested context managers
@@ -44,7 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4452

4553
## [1.0.1] - 2020-07-06
4654
### Fixed
47-
- **Logger**: Fix a bug with `inject_lambda_context` causing existing an Logger keys to be overriden if `structure_logs` was called before
55+
- **Logger**: Fix a bug with `inject_lambda_context` causing existing Logger keys to be overridden if `structure_logs` was called before
4856

4957
## [1.0.0] - 2020-06-18
5058
### Added
@@ -114,7 +122,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
114122

115123
## [0.8.0] - 2020-04-24
116124
### Added
117-
- **Logger**: Introduced `Logger` class for stuctured logging as a replacement for `logger_setup`
125+
- **Logger**: Introduced `Logger` class for structured logging as a replacement for `logger_setup`
118126
- **Logger**: Introduced `Logger.inject_lambda_context` decorator as a replacement for `logger_inject_lambda_context`
119127

120128
### Removed

aws_lambda_powertools/metrics/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def serialize_metric_set(self, metrics: Dict = None, dimensions: Dict = None, me
177177
if self.service and not self.dimension_set.get("service"):
178178
self.dimension_set["service"] = self.service
179179

180-
logger.debug("Serializing...", {"metrics": metrics, "dimensions": dimensions})
180+
logger.debug({"details": "Serializing metrics", "metrics": metrics, "dimensions": dimensions})
181181

182182
metric_names_and_units: List[Dict[str, str]] = [] # [ { "Name": "metric_name", "Unit": "Count" } ]
183183
metric_names_and_values: Dict[str, str] = {} # { "metric_name": 1.0 }
@@ -207,7 +207,7 @@ def serialize_metric_set(self, metrics: Dict = None, dimensions: Dict = None, me
207207
}
208208

209209
try:
210-
logger.debug("Validating serialized metrics against CloudWatch EMF schema", embedded_metrics_object)
210+
logger.debug("Validating serialized metrics against CloudWatch EMF schema")
211211
fastjsonschema.validate(definition=CLOUDWATCH_EMF_SCHEMA, data=embedded_metrics_object)
212212
except fastjsonschema.JsonSchemaException as e:
213213
message = f"Invalid format. Error: {e.message}, Invalid item: {e.name}" # noqa: B306, E501

aws_lambda_powertools/metrics/metric.py

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ def single_metric(name: str, unit: MetricUnit, value: float, namespace: str = No
110110
metric: SingleMetric = SingleMetric(namespace=namespace)
111111
metric.add_metric(name=name, unit=unit, value=value)
112112
yield metric
113-
logger.debug("Serializing single metric")
114113
metric_set: Dict = metric.serialize_metric_set()
115114
finally:
116-
logger.debug("Publishing single metric", {"metric": metric})
117115
print(json.dumps(metric_set))

aws_lambda_powertools/metrics/metrics.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import warnings
55
from typing import Any, Callable
66

7-
from .base import MetricManager
7+
from .base import MetricManager, MetricUnit
8+
from .metric import single_metric
89

910
logger = logging.getLogger(__name__)
1011

@@ -149,7 +150,6 @@ def decorate(event, context):
149150
else:
150151
metrics = self.serialize_metric_set()
151152
self.clear_metrics()
152-
logger.debug("Publishing metrics", {"metrics": metrics})
153153
print(json.dumps(metrics))
154154

155155
return response
@@ -167,6 +167,7 @@ def __add_cold_start_metric(self, context: Any):
167167
global is_cold_start
168168
if is_cold_start:
169169
logger.debug("Adding cold start metric and function_name dimension")
170-
self.add_metric(name="ColdStart", value=1, unit="Count")
171-
self.add_dimension(name="function_name", value=context.function_name)
172-
is_cold_start = False
170+
with single_metric(name="ColdStart", unit=MetricUnit.Count, value=1, namespace=self.namespace) as metric:
171+
metric.add_dimension(name="function_name", value=context.function_name)
172+
metric.add_dimension(name="service", value=self.service)
173+
is_cold_start = False

0 commit comments

Comments
 (0)