From 4491dbe1a93613c05008ee3b666f1b3f831de749 Mon Sep 17 00:00:00 2001 From: Kristopher Maschi Date: Thu, 31 Oct 2024 10:04:08 -0400 Subject: [PATCH 1/2] feat(support-local-hooks-edge): CEXT-2904 - Updated code to make newrelic agent optional. --- package.json | 2 +- src/index.js | 5 +++-- src/telemetry/agents/log.js | 15 +++++++++++++++ src/telemetry/register.js | 16 ++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/telemetry/agents/log.js create mode 100644 src/telemetry/register.js diff --git a/package.json b/package.json index f61bc26..a5b4fb8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@adobe/plugin-hooks", - "version": "0.3.1", + "version": "0.3.2", "publishConfig": { "access": "public" }, diff --git a/src/index.js b/src/index.js index 1cd8d1f..a5641ef 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,8 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const newrelic = require("newrelic"); +const agent = require('./telemetry/register'); + const handleBeforeAllHooks = require("./handleBeforeAllHooks"); async function hooksPlugin(config) { @@ -34,7 +35,7 @@ async function hooksPlugin(config) { return { async onExecute({ args, setResultAndStopExecution, extendContext }) { - await newrelic.startSegment('handleBeforeAllHooks:onExecute', true, async() => { + await agent.startSegment('handleBeforeAllHooks:onExecute', true, async() => { const query = args.contextValue.params.query; diff --git a/src/telemetry/agents/log.js b/src/telemetry/agents/log.js new file mode 100644 index 0000000..68c3597 --- /dev/null +++ b/src/telemetry/agents/log.js @@ -0,0 +1,15 @@ +/** + * Stub replacement for newrelic.startSegment used by `plugin-hooks`. Does NOT report telemetry back to newrelic. + * @param {string} name The name to give the new segment. This will also be the name of the metric. + * @param {boolean} record Indicates if the segment should be recorded as a metric. Metrics will show up on the transaction breakdown table and server breakdown graph. Segments just show up in transaction traces. + * @param {() => Promise}handler The function to track as a segment. + * @param {Function?} _callback An optional callback for the handler. This will indicate the end of the timing if provided. + */ +const startSegment = async (name, record, handler, _callback) => { + console.log(name); + await handler(); +} + +module.exports = { + startSegment, +} diff --git a/src/telemetry/register.js b/src/telemetry/register.js new file mode 100644 index 0000000..47a6079 --- /dev/null +++ b/src/telemetry/register.js @@ -0,0 +1,16 @@ +let agent; + +// Attempt to register newrelic agent +try { + agent = require("newrelic"); +} catch (err) { + console.warn('newrelic agent not installed...'); +} + +// No other telemetry agents were registered so fall back on logging +if (!agent) { + console.log('Falling back on log agent...'); + agent = require('./agents/log'); +} + +module.exports = agent; From c926000abf18f62fc0cc086605d350c1291eb545 Mon Sep 17 00:00:00 2001 From: Kristopher Maschi Date: Thu, 31 Oct 2024 10:16:02 -0400 Subject: [PATCH 2/2] feat(support-local-hooks-edge): CEXT-2904 - Added beta tag. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a5b4fb8..cd260fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@adobe/plugin-hooks", - "version": "0.3.2", + "version": "0.3.2-beta", "publishConfig": { "access": "public" },