Skip to content

Commit

Permalink
run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Aug 15, 2022
1 parent 5c31806 commit dd9474c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 39 deletions.
5 changes: 3 additions & 2 deletions .changeset/usenewrelic-agent-error-msg.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
"@envelop/newrelic": patch
'@envelop/newrelic': patch
---

New Relic: add error for agent not being found
Adds an error message when initializing the new relic plugin
- This error message will occur when the new relic agent is not found when initializing the plugin. Signalling information to a developer that new relic may not be

- This error message will occur when the new relic agent is not found when initializing the plugin. Signalling information to a developer that new relic may not be
- installed correctly or may be disabled where this plugin is being instantiated.
76 changes: 39 additions & 37 deletions packages/plugins/newrelic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export const useNewRelic = (rawOptions?: UseNewRelicOptions): Plugin => {
.then(m => m.default || m)
.then(({ shim }) => {
if (!shim?.agent) {
throw new Error("Agent unavailable. Please check your New Relic Agent configuration and ensure New Relic is enabled.")
throw new Error(
'Agent unavailable. Please check your New Relic Agent configuration and ensure New Relic is enabled.'
);
}
shim.agent.metrics
.getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`)
Expand Down Expand Up @@ -128,50 +130,50 @@ export const useNewRelic = (rawOptions?: UseNewRelicOptions): Plugin => {

const onResolverCalled: OnResolverCalledHook | undefined = options.trackResolvers
? async ({ args: resolversArgs, info }) => {
const logger = await logger$;
const { returnType, path, parentType } = info;
const formattedPath = flattenPath(path, delimiter);
const currentSegment = instrumentationApi.getActiveSegment();

if (!currentSegment) {
logger.trace('No active segment found at resolver call. Not recording resolver (%s).', formattedPath);
return () => { };
}

const resolverSegment = instrumentationApi.createSegment(
`resolver${delimiter}${formattedPath}`,
null,
operationSegment
);
const logger = await logger$;
const { returnType, path, parentType } = info;
const formattedPath = flattenPath(path, delimiter);
const currentSegment = instrumentationApi.getActiveSegment();

if (!currentSegment) {
logger.trace('No active segment found at resolver call. Not recording resolver (%s).', formattedPath);
return () => {};
}

if (!resolverSegment) {
logger.trace('Resolver segment was not created (%s).', formattedPath);
return () => { };
}
const resolverSegment = instrumentationApi.createSegment(
`resolver${delimiter}${formattedPath}`,
null,
operationSegment
);

resolverSegment.start();
if (!resolverSegment) {
logger.trace('Resolver segment was not created (%s).', formattedPath);
return () => {};
}

resolverSegment.addAttribute(AttributeName.RESOLVER_FIELD_PATH, formattedPath);
resolverSegment.addAttribute(AttributeName.RESOLVER_TYPE_NAME, parentType.toString());
resolverSegment.addAttribute(AttributeName.RESOLVER_RESULT_TYPE, returnType.toString());
resolverSegment.start();

if (options.includeResolverArgs) {
const rawArgs = resolversArgs || {};
const resolverArgsToTrack = options.isResolverArgsRegex
? filterPropertiesByRegex(rawArgs, options.includeResolverArgs as RegExp)
: rawArgs;
resolverSegment.addAttribute(AttributeName.RESOLVER_FIELD_PATH, formattedPath);
resolverSegment.addAttribute(AttributeName.RESOLVER_TYPE_NAME, parentType.toString());
resolverSegment.addAttribute(AttributeName.RESOLVER_RESULT_TYPE, returnType.toString());

resolverSegment.addAttribute(AttributeName.RESOLVER_ARGS, JSON.stringify(resolverArgsToTrack));
}
if (options.includeResolverArgs) {
const rawArgs = resolversArgs || {};
const resolverArgsToTrack = options.isResolverArgsRegex
? filterPropertiesByRegex(rawArgs, options.includeResolverArgs as RegExp)
: rawArgs;

return ({ result }) => {
if (options.includeRawResult) {
resolverSegment.addAttribute(AttributeName.RESOLVER_RESULT, JSON.stringify(result));
resolverSegment.addAttribute(AttributeName.RESOLVER_ARGS, JSON.stringify(resolverArgsToTrack));
}

resolverSegment.end();
};
}
return ({ result }) => {
if (options.includeRawResult) {
resolverSegment.addAttribute(AttributeName.RESOLVER_RESULT, JSON.stringify(result));
}

resolverSegment.end();
};
}
: undefined;

return {
Expand Down

0 comments on commit dd9474c

Please sign in to comment.