Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/plugin-hooks",
"version": "0.3.1",
"version": "0.3.2-beta",
"publishConfig": {
"access": "public"
},
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/telemetry/agents/log.js
Original file line number Diff line number Diff line change
@@ -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<void>}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,
}
16 changes: 16 additions & 0 deletions src/telemetry/register.js
Original file line number Diff line number Diff line change
@@ -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;
Loading