Skip to content

Commit

Permalink
Prettier and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jun 22, 2023
1 parent d3ecee3 commit ae105be
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion examples/azure-functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execute, parse, subscribe, validate } from 'graphql';
import { getGraphQLParameters, processRequest, Response } from 'graphql-helix';
import { AzureFunction, Context, HttpRequest } from '@azure/functions';
import type { AzureFunction, Context, HttpRequest } from '@azure/functions';
import { envelop, useLogger, useSchema } from '@envelop/core';
import { makeExecutableSchema } from '@graphql-tools/schema';

Expand Down
7 changes: 4 additions & 3 deletions packages/plugins/newrelic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@
"tslib": "^2.5.0"
},
"devDependencies": {
"@types/newrelic": "9.14.0",
"@envelop/core": "^4.0.0",
"@graphql-tools/schema": "^10.0.0",
"@newrelic/test-utilities": "6.5.5",
"@types/newrelic": "9.14.0",
"graphql": "16.6.0",
"newrelic": "9.8.1",
"typescript": "4.8.4",
"@newrelic/test-utilities": "6.5.5"
"typescript": "4.8.4"
},
"publishConfig": {
"directory": "dist",
Expand Down
14 changes: 7 additions & 7 deletions packages/plugins/newrelic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ export const useNewRelic = (rawOptions?: UseNewRelicOptions): Plugin => {
const transaction = instrumentationApi.agent.tracer.getTransaction();
if (!transaction) {
logger.trace('No transaction found. Not recording resolver.');
return () => { };
return () => {};
}
const transactionNameState = transaction.nameState;
if (!transactionNameState) {
logger.trace('No transaction name state found. Not recording resolver.');
return () => { };
return () => {};
}
const delimiter = transactionNameState.delimiter;

Expand All @@ -100,7 +100,7 @@ export const useNewRelic = (rawOptions?: UseNewRelicOptions): Plugin => {
'No active segment found at resolver call. Not recording resolver (%s).',
formattedPath,
);
return () => { };
return () => {};
}

const resolverSegment = instrumentationApi.createSegment(
Expand All @@ -110,7 +110,7 @@ export const useNewRelic = (rawOptions?: UseNewRelicOptions): Plugin => {
);
if (!resolverSegment) {
logger.trace('Resolver segment was not created (%s).', formattedPath);
return () => { };
return () => {};
}
resolverSegment.start();
resolverSegment.addAttribute(AttributeName.RESOLVER_FIELD_PATH, formattedPath);
Expand Down Expand Up @@ -169,9 +169,9 @@ export const useNewRelic = (rawOptions?: UseNewRelicOptions): Plugin => {
transactionNameState.verb,
delimiter,
operationType +
delimiter +
operationName +
(rootFields ? delimiter + rootFields.join('&') : ''),
delimiter +
operationName +
(rootFields ? delimiter + rootFields.join('&') : ''),
);
}

Expand Down
47 changes: 30 additions & 17 deletions packages/plugins/newrelic/tests/newrelic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AttributeName, useNewRelic } from '../src';
import { createTestkit } from '@envelop/testing';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { TestAgent } from '@newrelic/test-utilities';
import { AttributeName, useNewRelic } from '../src';

describe('New Relic', () => {
const schema = makeExecutableSchema({
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('New Relic', () => {
shim: helper.getShim(),
}),
],
schema
schema,
);
// Do some testing logic...

Expand All @@ -60,10 +60,14 @@ describe('New Relic', () => {
AttributeName.EXECUTION_OPERATION_TYPE,
]);
expect(
tx.trace.root._spanContext.customAttributes.attributes.get(AttributeName.EXECUTION_OPERATION_NAME).value
tx.trace.root._spanContext.customAttributes.attributes.get(
AttributeName.EXECUTION_OPERATION_NAME,
).value,
).toBe(`Greetings`);
expect(
tx.trace.root._spanContext.customAttributes.attributes.get(AttributeName.EXECUTION_OPERATION_TYPE).value
tx.trace.root._spanContext.customAttributes.attributes.get(
AttributeName.EXECUTION_OPERATION_TYPE,
).value,
).toBe(`query`);

// Many metrics are not created until the transaction ends, if you're
Expand All @@ -73,7 +77,9 @@ describe('New Relic', () => {
// This will check that the metrics given have been created. Extra metrics
// are allowed.
expect(
helper.agent.metrics.getMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`)
helper.agent.metrics.getMetric(
`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`,
),
).toBeTruthy();
});
});
Expand All @@ -88,13 +94,17 @@ describe('New Relic', () => {
shim: helper.getShim(),
}),
],
schema
schema,
);

await testKit.execute(`query Greetings($name: String!) { hello(name: $name) }`, { name: 'Laurin' });
await testKit.execute(`query Greetings($name: String!) { hello(name: $name) }`, {
name: 'Laurin',
});

expect(
tx.trace.root._spanContext.customAttributes.attributes.get(AttributeName.EXECUTION_VARIABLES).value
tx.trace.root._spanContext.customAttributes.attributes.get(
AttributeName.EXECUTION_VARIABLES,
).value,
).toBe(`{"name":"Laurin"}`);

// Many metrics are not created until the transaction ends, if you're
Expand All @@ -112,7 +122,7 @@ describe('New Relic', () => {
shim: helper.getShim(),
}),
],
schema
schema,
);

await testKit.execute(
Expand All @@ -124,11 +134,13 @@ describe('New Relic', () => {
{
verb: 'Hi',
name: 'Dotan',
}
},
);

expect(
tx.trace.root._spanContext.customAttributes.attributes.get(AttributeName.EXECUTION_VARIABLES).value
tx.trace.root._spanContext.customAttributes.attributes.get(
AttributeName.EXECUTION_VARIABLES,
).value,
).toBe(`{"verb":"Hi"}`);

// Many metrics are not created until the transaction ends, if you're
Expand All @@ -147,14 +159,15 @@ describe('New Relic', () => {
shim: helper.getShim(),
}),
],
schema
schema,
);
// Do some testing logic...
await testKit.execute(`query Greetings { hello }`);

expect(tx.trace.root._spanContext.customAttributes.attributes.get(AttributeName.EXECUTION_RESULT).value).toBe(
`{"data":{"hello":"Hello world!"}}`
);
expect(
tx.trace.root._spanContext.customAttributes.attributes.get(AttributeName.EXECUTION_RESULT)
.value,
).toBe(`{"data":{"hello":"Hello world!"}}`);

// Many metrics are not created until the transaction ends, if you're
// missing metrics in your instrumentation tests, this may help.
Expand All @@ -171,7 +184,7 @@ describe('New Relic', () => {
shim: helper.getShim(),
}),
],
schema
schema,
);
// Do some testing logic...

Expand All @@ -193,7 +206,7 @@ describe('New Relic', () => {
shim: helper.getShim(),
}),
],
schema
schema,
);
// Do some testing logic...

Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/sentry/__tests__/sentry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('sentry', () => {
`);

// run sentry flush
await new Promise(res => setTimeout(res, 10));
await new Promise(res => setTimeout(res, 100));

const reports = sentryTestkit.reports();
expect(reports).toHaveLength(1);
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ae105be

Please sign in to comment.