Skip to content

Commit 27c6f07

Browse files
committed
fix(metrics): ensure metrics are sent
See #4
1 parent f52c621 commit 27c6f07

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

lambda/fetchDeviceShadow.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics'
1+
import {
2+
logMetrics,
3+
Metrics,
4+
MetricUnits,
5+
} from '@aws-lambda-powertools/metrics'
26
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
7+
import middy from '@middy/core'
38
import { fromEnv } from '@nordicsemiconductor/from-env'
49
import { chunk } from 'lodash-es'
510
import pLimit from 'p-limit'
@@ -58,7 +63,7 @@ const deviceShadowPromise = (async () => {
5863
})()
5964
const deviceShadowPublisher = createDeviceShadowPublisher(eventBusName)
6065

61-
export const handler = async (): Promise<void> => {
66+
const h = async (): Promise<void> => {
6267
const deviceShadow = await deviceShadowPromise
6368
const lockAcquired = await lock.acquiredLock(lockName, lockTTL)
6469
if (lockAcquired === false) {
@@ -117,3 +122,5 @@ export const handler = async (): Promise<void> => {
117122
await lock.releaseLock(lockName)
118123
}
119124
}
125+
126+
export const handler = middy(h).use(logMetrics(metrics))

lambda/onConnect.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { MetricUnits, Metrics } from '@aws-lambda-powertools/metrics'
1+
import {
2+
MetricUnits,
3+
Metrics,
4+
logMetrics,
5+
} from '@aws-lambda-powertools/metrics'
26
import {
37
DynamoDBClient,
48
PutItemCommand,
@@ -7,6 +11,7 @@ import {
711
import { EventBridge } from '@aws-sdk/client-eventbridge'
812
import { unmarshall } from '@aws-sdk/util-dynamodb'
913
import { Context, DeviceIdentity } from '@hello.nrfcloud.com/proto/hello'
14+
import middy from '@middy/core'
1015
import { fromEnv } from '@nordicsemiconductor/from-env'
1116
import type { Static } from '@sinclair/typebox'
1217
import type {
@@ -34,7 +39,7 @@ const metrics = new Metrics({
3439
serviceName: 'websocket',
3540
})
3641

37-
export const handler = async (
42+
const h = async (
3843
event: APIGatewayProxyWebsocketEventV2 & {
3944
queryStringParameters?: Record<string, any>
4045
},
@@ -126,3 +131,5 @@ export const handler = async (
126131
body: `Connected. Hello ${event.requestContext.connectionId}@${device.deviceId}!`,
127132
}
128133
}
134+
135+
export const handler = middy(h).use(logMetrics(metrics))

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"dependencies": {
118118
"@aws-lambda-powertools/metrics": "1.9.0",
119119
"@hello.nrfcloud.com/proto": "1.0.0",
120+
"@middy/core": "4.5.2",
120121
"@nordicsemiconductor/from-env": "2.0.0",
121122
"@nordicsemiconductor/timestream-helpers": "5.0.0",
122123
"@sinclair/typebox": "0.28.15",

0 commit comments

Comments
 (0)