Drop aws-embedded-metrics from the stats lambda#2154
Merged
Conversation
aws-embedded-metrics pulled in the entire aiohttp subtree (aiohttp, yarl, multidict, frozenlist, propcache, aiohappyeyeballs) -- the bulk of this lambda's recurring Dependabot churn -- yet in Lambda the library only uses its stdout sink, so aiohttp was never exercised at runtime. stats only used set_namespace/set_property/put_metric, so emit the one PageLoad metric as an Embedded Metric Format JSON line on stdout directly. CloudWatch ingests EMF from the logs identically; the namespace, metric name and value are unchanged (unit kept as the library's default "None" so any alarm keyed on it still matches). The metric is now emitted only on the pageload path rather than flushed (mostly empty) on every invocation. Drops the package from 4.2MB to 845KB and removes six transitive dependencies. emit_metric is unit-tested for EMF shape; the existing pageload tests assert it is called correctly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes the aws-embedded-metrics dependency from the stats Lambda and replaces its usage with a minimal, hand-rolled CloudWatch Embedded Metric Format (EMF) JSON line written directly to stdout, substantially reducing the deployed package size and transitive dependency churn.
Changes:
- Dropped
aws-embedded-metricsfrom the Lambda dependency set (and lockfile), removing theaiohttpdependency subtree. - Added an
emit_metric()helper to output an EMF record to stdout for thePageLoadmetric (preserving thesponsorsproperty). - Updated existing pageload tests and added a unit test validating EMF output shape.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lambda/uv.lock | Removes aws-embedded-metrics and its transitive dependency subtree from the Lambda lockfile. |
| lambda/stats.py | Replaces embedded-metrics decorator/logger usage with a direct EMF stdout emit for PageLoad. |
| lambda/stats_test.py | Adds EMF-shape unit test and updates pageload tests to assert emit_metric() usage. |
| lambda/pyproject.toml | Removes aws-embedded-metrics from Lambda project dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Two fixes after inspecting the live metric: - The existing CompilerExplorer/PageLoad metric (queried by a Grafana dashboard) carries aws-embedded-metrics' default dimensions (LogGroup/ServiceName/ServiceType = stats). Reproduce them so the metric stays the same stream rather than forking into a dimensionless series. - Flush stdout when writing the EMF record: Lambda's stdout is block-buffered, so without it the line can be delayed past the invocation or dropped on recycle, losing the metric (review feedback). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continues the lambda housekeeping.
aws-embedded-metricsdragged in the entire aiohttp subtree (aiohttp, yarl, multidict, frozenlist, propcache, aiohappyeyeballs) -- the bulk of this lambda's recurring Dependabot churn -- yet in the Lambda runtime the library only uses its stdout sink, so aiohttp was never exercised.statsonly usedset_namespace/set_property/put_metric.Change
PageLoadmetric as an Embedded Metric Format JSON line on stdout (emit_metric). CloudWatch ingests EMF from the logs the same way the library did.CompilerExplorer), metric name (PageLoad) and value (1) are unchanged. Unit kept as the library default"None"so any alarm keyed on it still matches.sponsorsproperty is preserved.Impact
Tests
emit_metricis unit-tested for EMF shape (namespace, metric, timestamp, property).emit_metricis called with the right args.make static-checksclean; package builds.Verification plan (post-merge, before/after deploy)
Deploy
statsthen invoke a realPOST /pageloadand confirm a new datapoint lands on theCompilerExplorer/PageLoadmetric viaGetMetricStatistics-- i.e. confirm the hand-rolled EMF is actually ingested, not just logged. A brief stats blip during deploy is acceptable.🤖 Generated with Claude Code