-
Notifications
You must be signed in to change notification settings - Fork 161
feat(metrics): logMetrics middleware #338
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
8fbe2dd
feat(metric): add logic, unit tests for the middy middleware
saragerion 79e5aae
chore(metrics): lint changes
saragerion 9c1644d
docs(metrics): logMetric middleware and examples
saragerion f430195
test(metrics): add array input for middleware
saragerion 69100ce
Update packages/metrics/package.json
saragerion d3d13ea
Update docs/core/metrics.md
saragerion ef6a58e
Update docs/core/metrics.md
saragerion f52e198
Update docs/core/metrics.md
saragerion d503075
Update docs/core/metrics.md
saragerion 419c8d2
improv(metrics): improve docs, examples, naming
saragerion f29fc49
chore(metrics): merge conflict
saragerion ac08ffe
Update packages/metrics/examples/decorator/default-dimensions.ts
saragerion a42b050
Update packages/metrics/examples/decorator/empty-metrics.ts
saragerion af2ec16
Update docs/core/metrics.md
saragerion 3a9cd0d
Update docs/core/metrics.md
saragerion 7ea58a8
Update docs/core/metrics.md
saragerion 625b79d
Update docs/core/metrics.md
saragerion 0d5c161
Update docs/core/metrics.md
saragerion d75c40f
Update packages/metrics/examples/decorator/manual-flushing.ts
saragerion 3d423e5
improv(metrics): logMetricsAfterOrError middleware, examples update
saragerion 2b23c86
improv(metrics): logMetricsAfterOrError middleware, examples update
saragerion 9b295ed
improv(metrics): logMetricsAfterOrError middleware, examples update
saragerion 8269677
Merge branch 'feat/metrics-middleware' of github.com:awslabs/aws-lamb…
saragerion 29d1c05
tests(metrics): fix handlers type
saragerion d23bbc5
fix(metrics): examples file path
saragerion 7941119
revert(metrics): jest groups
saragerion 3b6b053
chore(metrics): rename examples script, prepending 'decorator'
saragerion fe6bad1
chore(all): merge
saragerion 0ab77da
fix(metrics): removed empty lint file
saragerion c909154
ci(all): exclude examples CDK for linting
saragerion a95f08c
chore(all): lint fix for CDK examples
saragerion 28b9df1
test(metrics): added metrics middleware jest group
saragerion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import * as dummyEvent from '../../../tests/resources/events/custom/hello-world.json'; | ||
import { context as dummyContext } from '../../../tests/resources/contexts/hello-world'; | ||
import { populateEnvironmentVariables } from '../tests/helpers'; | ||
import { Metrics, MetricUnits } from '../src'; | ||
import { LambdaInterface } from "./utils/lambda"; | ||
import { Callback, Context } from "aws-lambda/handler"; | ||
import middy from '@middy/core'; | ||
import { logMetrics } from '../src/middleware/middy'; | ||
|
||
// Populate runtime | ||
populateEnvironmentVariables(); | ||
// Additional runtime variables | ||
process.env.POWERTOOLS_METRICS_NAMESPACE = 'hello-world'; | ||
|
||
const metrics = new Metrics({ | ||
namespace: 'hello-world-constructor', | ||
service: 'hello-world-service-constructor' | ||
}); | ||
|
||
class Lambda implements LambdaInterface { | ||
|
||
@metrics.logMetrics() | ||
public handler<TEvent, TResult>(_event: TEvent, _context: Context, _callback: Callback<TResult>): void | Promise<TResult> { | ||
metrics.addMetric('test-metric', MetricUnits.Count, 10); | ||
const lambdaHandler = async (): Promise<void> => { | ||
metrics.addMetric('test-metric', MetricUnits.Count, 10); | ||
}; | ||
|
||
} | ||
const handlerWithMiddleware = middy(lambdaHandler) | ||
.use(logMetrics(metrics)); | ||
|
||
} | ||
new Lambda().handler(dummyEvent, dummyContext, () => console.log('Lambda invoked!')); | ||
handlerWithMiddleware(dummyEvent, dummyContext, () => console.log('Lambda invoked!')); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as dummyEvent from '../../../../tests/resources/events/custom/hello-world.json'; | ||
import { context as dummyContext } from '../../../../tests/resources/contexts/hello-world'; | ||
import { LambdaInterface } from './../utils/lambda/LambdaInterface'; | ||
import { populateEnvironmentVariables } from '../../tests/helpers'; | ||
import { Callback, Context } from 'aws-lambda/handler'; | ||
import { Metrics, MetricUnits } from '../../src'; | ||
|
||
// Populate runtime | ||
populateEnvironmentVariables(); | ||
// Additional runtime variables | ||
process.env.POWERTOOLS_METRICS_NAMESPACE = 'hello-world'; | ||
|
||
const metrics = new Metrics(); | ||
|
||
class Lambda implements LambdaInterface { | ||
|
||
@metrics.logMetrics({ captureColdStartMetric: true }) | ||
public handler<TEvent, TResult>(_event: TEvent, _context: Context, _callback: Callback<TResult>): void | Promise<TResult> { | ||
metrics.addDimension('OuterDimension', 'true'); | ||
metrics.addMetric('test-metric', MetricUnits.Count, 10); | ||
} | ||
|
||
} | ||
|
||
new Lambda().handler(dummyEvent, dummyContext, () => console.log('Lambda invoked!')); | ||
new Lambda().handler(dummyEvent, dummyContext, () => console.log('Lambda invoked again!')); |
21 changes: 21 additions & 0 deletions
21
packages/metrics/examples/decorator/constructor-options.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as dummyEvent from '../../../../tests/resources/events/custom/hello-world.json'; | ||
import { context as dummyContext } from '../../../../tests/resources/contexts/hello-world'; | ||
import { Metrics, MetricUnits } from '../../src'; | ||
import { LambdaInterface } from './../utils/lambda'; | ||
import { Callback, Context } from 'aws-lambda/handler'; | ||
|
||
const metrics = new Metrics({ | ||
namespace: 'hello-world-constructor', | ||
service: 'hello-world-service-constructor' | ||
}); | ||
|
||
class Lambda implements LambdaInterface { | ||
|
||
@metrics.logMetrics() | ||
public handler<TEvent, TResult>(_event: TEvent, _context: Context, _callback: Callback<TResult>): void | Promise<TResult> { | ||
metrics.addMetric('test-metric', MetricUnits.Count, 10); | ||
|
||
} | ||
|
||
} | ||
new Lambda().handler(dummyEvent, dummyContext, () => console.log('Lambda invoked!')); |
27 changes: 27 additions & 0 deletions
27
packages/metrics/examples/decorator/default-dimensions-constructor.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { populateEnvironmentVariables } from '../../tests/helpers'; | ||
|
||
// Populate runtime | ||
populateEnvironmentVariables(); | ||
// Additional runtime variables | ||
process.env.POWERTOOLS_METRICS_NAMESPACE = 'hello-world-constructor'; | ||
process.env.POWERTOOLS_SERVICE_NAME = 'hello-world-service-constructor'; | ||
|
||
import * as dummyEvent from '../../../tests/resources/events/custom/hello-world.json'; | ||
import { context as dummyContext } from '../../../tests/resources/contexts/hello-world'; | ||
import { LambdaInterface } from './utils/lambda/LambdaInterface'; | ||
import { Callback, Context } from 'aws-lambda/handler'; | ||
import { Metrics, MetricUnits } from '../src'; | ||
|
||
const metrics = new Metrics({ defaultDimensions:{ 'application': 'hello-world' } }); | ||
|
||
class Lambda implements LambdaInterface { | ||
|
||
@metrics.logMetrics() | ||
public handler<TEvent, TResult>(_event: TEvent, _context: Context, _callback: Callback<TResult>): void | Promise<TResult> { | ||
metrics.addMetric('test-metric', MetricUnits.Count, 10); | ||
|
||
} | ||
|
||
} | ||
|
||
new Lambda().handler(dummyEvent, dummyContext, () => console.log('Lambda invoked!')); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.