elastic / elastic/apm-agent-nodejs

Instrument JSON functions

Open
#3,228 1 comment 0 reactions 0 assignees View on GitHub
agent-nodejs community
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

**Is your feature request related to a problem? Please describe.**
I would like to instrument JSON functions like `JSON.stringify()` in my project, which is not natively supported by apm. Many projects like our manage large JSON object and we think it could be beneficial to be able to monitor them.

**Describe the solution you'd like**
Save original JSON functions when APM Agent start, and use them within the apm agent. The goal of not using the original JSON functions is to prevent instrumenting the JSON functions of apm itself and have recursive issues (we tested to change JSON.stringify() function and it caused `max call stack exceeded` error). It will allow projects to have instrument JSON natively

This project will have to use the copy of the original JSON functions everywhere to prevent mixing the instrumented one with the original one.
In the apm-agent code it will look something like this:
```
const originalJSON = {
parse: JSON.parse,
stringify: JSON.stringify
};
originalJSON.stringify(k)
```

**Describe alternatives you've considered**
For now, we are using an instrumentedJSON function and using it everywhere, we also have an eslint rule preventing the use of the original JSON function

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.