awslabs / awslabs/aws-embedded-metrics-node
Allow Local environment detection (or have Local be the default environment)
- Dominant language
- TypeScript
- Stars
- 263
- Forks
- 39
- PR merge metrics
- No merged PRs in 30d
Description
We're using this library with our lambda function for creating embedded metrics, and it works fantastically for that use case, but we've been struggling a little bit with getting it all to play smoothly during local development. I'm aware that we can set `AWS_EMF_ENVIRONMENT` to `Local` at runtime to make the library use stdout, and we've added that to a few of our package.json scripts to make it easier for everyone, but there are still a few cases where there's no simple or easy route to setting this, or somebody does something a little different and forgets to add that environment variable (we work in a large monorepo project, so the number of people contributing who know many detail around EMF is fairly low). This leads to confusing error messages about `UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 0.0.0.0:25888` when running in Node 12 - and for anyone who is running in Node 14, it seems to actually just crash the local server.
Looking into the library, it looks like Agent is set up as the default environment, and the Local environment `probe` method is intentionally a no-op, which means that the _only_ way to use the library in local environment mode is via this environment variable.
Is there a historical reason why it is this way? Is there no other way to detect if the environment should be `Agent`, and thus switch the default environment around, or having some other way to auto-detect if the environment should be `Local` (e.g. if `NODE_ENV !== 'production'`)?
Contributor guide
Research direction
Begin by tracing Agent's default setup, Local's no-op probe, and AWS_EMF_ENVIRONMENT handling. Compare the Node 12 and Node 14 failure paths described in the issue, then establish which default or detection behavior is intended for local development and Lambda use. Done should include an agreed behavior and coverage for both environments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100