Skip to content

Feature request: Allow use of InvokeStore in Metrics #4662

@svozza

Description

@svozza

Use case

The InvokeStore pacakge, allow for the use of Asynchronous contexts in lambda handlers. We should allow users to set metrics in async contexts across lambda executions so that they are isolated.

Solution/User Experience

Lambda handlers in the runtime are automatically wrapped in this context, this can be replicated locally like so:

export const handler = async (event, context) => {
  // This metadata with this userId will be scoped only to this handler execution and will not be available in any other invocations
  metrics.addMetadata("userId", event.userId);

  return {
    requestId: InvokeStore.getRequestId(),
    userId,
  };
};

// ... 

const result = InvokeStore.run(
  {
    [InvokeStore.PROTECTED_KEYS.REQUEST_ID]: "request-123",
    [InvokeStore.PROTECTED_KEYS.X_RAY_TRACE_ID]: "trace-456", // Optional X-Ray trace ID
    customField: "value", // Optional custom fields
  },
  () => {
    return handler(event)
  }
);

Alternative solutions

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

feature-requestThis item refers to a feature request for an existing or new utilitymetricsThis item relates to the Metrics Utility

Type

No type

Projects

Status

Working on it

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions