Skip to content

Commit dee7995

Browse files
Rename instruments to instrumentation (#3865)
* Rename instruments to instrumentation * Bump * FIx * chore(dependencies): updated changesets for modified dependencies --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 4bfc81d commit dee7995

22 files changed

+255
-197
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@graphql-yoga/nestjs-federation": patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`@envelop/apollo-federation@^6.1.3` ↗︎](https://www.npmjs.com/package/@envelop/apollo-federation/v/6.1.3) (from `^6.1.1`, in `dependencies`)
6+
- Updated dependency [`@envelop/core@^5.2.3` ↗︎](https://www.npmjs.com/package/@envelop/core/v/5.2.3) (from `^5.2.1`, in `dependencies`)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphql-yoga/plugin-apollo-inline-trace": patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`@envelop/on-resolve@^5.1.3` ↗︎](https://www.npmjs.com/package/@envelop/on-resolve/v/5.1.3) (from `^5.1.1`, in `dependencies`)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphql-yoga/plugin-prometheus": patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`@envelop/prometheus@^12.1.3` ↗︎](https://www.npmjs.com/package/@envelop/prometheus/v/12.1.3) (from `^12.1.1`, in `dependencies`)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@graphql-yoga/plugin-response-cache": patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`@envelop/core@^5.2.3` ↗︎](https://www.npmjs.com/package/@envelop/core/v/5.2.3) (from `^5.2.1`, in `dependencies`)
6+
- Updated dependency [`@envelop/response-cache@^7.1.3` ↗︎](https://www.npmjs.com/package/@envelop/response-cache/v/7.1.3) (from `^7.1.1`, in `dependencies`)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"graphql-yoga": patch
3+
---
4+
dependencies updates:
5+
- Updated dependency [`@envelop/core@^5.2.3` ↗︎](https://www.npmjs.com/package/@envelop/core/v/5.2.3) (from `^5.2.1`, in `dependencies`)
6+
- Updated dependency [`@whatwg-node/server@^0.10.1` ↗︎](https://www.npmjs.com/package/@whatwg-node/server/v/0.10.1) (from `^0.10.0`, in `dependencies`)
7+
- Added dependency [`@envelop/instrumentation@^1.0.0` ↗︎](https://www.npmjs.com/package/@envelop/instrumentation/v/1.0.0) (to `dependencies`)
8+
- Removed dependency [`@envelop/instruments@^1.0.0` ↗︎](https://www.npmjs.com/package/@envelop/instruments/v/1.0.0) (from `dependencies`)

import-map.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@graphql-tools/executor": "npm:@graphql-tools/executor",
1010
"graphql": "npm:graphql",
1111
"dset": "npm:dset",
12-
"@envelop/core": "npm:@envelop/core@3",
12+
"@envelop/core": "npm:@envelop/core@5",
1313
"@envelop/parser-cache": "npm:@envelop/parser-cache",
1414
"@whatwg-node/fetch": "npm:@whatwg-node/fetch",
1515
"@whatwg-node/events": "npm:@whatwg-node/[email protected]",

packages/graphql-yoga/CHANGELOG.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
- [#3793](https://github.com/dotansimha/graphql-yoga/pull/3793)
88
[`63b78d5`](https://github.com/dotansimha/graphql-yoga/commit/63b78d5a7f6f7fd1d5939e92ede2574fda9d08dd)
9-
Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - Add new Instruments API
9+
Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - Add new Instrumentation API
1010

1111
Introduction of a new API allowing to instrument the graphql pipeline.
1212

1313
This new API differs from already existing Hooks by not having access to input/output of phases.
14-
The goal of `Instruments` is to run allow running code before, after or around the **whole process
15-
of a phase**, including plugins hooks executions.
14+
The goal of `Instrumentation` is to run allow running code before, after or around the **whole
15+
process of a phase**, including plugins hooks executions.
1616

1717
The main use case of this new API is observability (monitoring, tracing, etc...).
1818

@@ -27,7 +27,7 @@
2727
schema,
2828
plugins: [
2929
{
30-
instruments: {
30+
instrumentation: {
3131
request: ({ request }, wrapped) =>
3232
Sentry.startSpan({ name: 'Graphql Operation' }, async () => {
3333
try {
@@ -42,11 +42,11 @@
4242
})
4343
```
4444

45-
### Multiple instruments plugins
45+
### Multiple instrumentation plugins
4646

47-
It is possible to have multiple instruments plugins (Prometheus and Sentry for example), they will
48-
be automatically composed by envelop in the same order than the plugin array (first is outermost,
49-
last is inner most).
47+
It is possible to have multiple instrumentation plugins (Prometheus and Sentry for example), they
48+
will be automatically composed by envelop in the same order than the plugin array (first is
49+
outermost, last is inner most).
5050

5151
```ts
5252
import { createYoga } from 'graphql-yoga'
@@ -58,22 +58,22 @@
5858
})
5959
```
6060

61-
### Custom instruments ordering
61+
### Custom instrumentation ordering
6262

63-
If the default composition ordering doesn't suite your need, you can manually compose instruments.
64-
This allows to have a different execution order of hooks and instruments.
63+
If the default composition ordering doesn't suite your need, you can manually compose
64+
instrumentation. This allows to have a different execution order of hooks and instrumentation.
6565

6666
```ts
67-
import { composeInstruments, createYoga } from 'graphql-yoga'
67+
import { composeInstrumentation, createYoga } from 'graphql-yoga'
6868
import schema from './schema'
6969

70-
const { instruments: sentryInstruments, ...sentryPlugin } = useSentry()
71-
const { instruments: otelInstruments, ...otelPlugin } = useOpentelemetry()
72-
const instruments = composeInstruments([otelInstruments, sentryInstruments])
70+
const { instrumentation: sentryInstrumentation, ...sentryPlugin } = useSentry()
71+
const { instrumentation: otelInstrumentation, ...otelPlugin } = useOpentelemetry()
72+
const instrumentation = composeInstrumentation([otelInstrumentation, sentryInstrumentation])
7373

7474
const server = createYoga({
7575
schema,
76-
plugins: [{ instruments }, useSentry(), useOpentelemetry()]
76+
plugins: [{ instrumentation }, useSentry(), useOpentelemetry()]
7777
})
7878
```
7979

@@ -87,7 +87,7 @@
8787
[`@envelop/core@^5.2.1` ↗︎](https://www.npmjs.com/package/@envelop/core/v/5.2.1) (from
8888
`^5.0.2`, in `dependencies`)
8989
- Added dependency
90-
[`@envelop/instruments@^1.0.0` ↗︎](https://www.npmjs.com/package/@envelop/instruments/v/1.0.0)
90+
[`@envelop/instrumentation@^1.0.0` ↗︎](https://www.npmjs.com/package/@envelop/instrumentation/v/1.0.0)
9191
(to `dependencies`)
9292
- Added dependency
9393
[`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4)

packages/graphql-yoga/__tests__/instruments.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createSchema, createYoga, Plugin } from '../src';
22

3-
describe('instruments', () => {
3+
describe('instrumentation', () => {
44
const schema = createSchema({
55
typeDefs: /* GraphQL */ `
66
type Query {
@@ -27,7 +27,7 @@ describe('instruments', () => {
2727
it('should wrap all the phases with the default composition order', async () => {
2828
const result: string[] = [];
2929
const make = (name: string): Plugin => ({
30-
instruments: {
30+
instrumentation: {
3131
context: (_, w) => {
3232
result.push(`pre-context-${name}`);
3333
w();

packages/graphql-yoga/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@
4949
"graphql": "^15.2.0 || ^16.0.0"
5050
},
5151
"dependencies": {
52-
"@envelop/core": "^5.2.1",
53-
"@envelop/instruments": "^1.0.0",
52+
"@envelop/core": "^5.2.3",
53+
"@envelop/instrumentation": "^1.0.0",
5454
"@graphql-tools/executor": "^1.4.0",
5555
"@graphql-tools/schema": "^10.0.11",
5656
"@graphql-tools/utils": "^10.6.2",
5757
"@graphql-yoga/logger": "workspace:^",
5858
"@graphql-yoga/subscription": "workspace:^",
5959
"@whatwg-node/fetch": "^0.10.5",
6060
"@whatwg-node/promise-helpers": "^1.2.4",
61-
"@whatwg-node/server": "^0.10.0",
61+
"@whatwg-node/server": "^0.10.1",
6262
"dset": "^3.1.4",
6363
"lru-cache": "^10.0.0",
6464
"tslib": "^2.8.1"
6565
},
6666
"devDependencies": {
67-
"@envelop/disable-introspection": "7.1.2",
67+
"@envelop/disable-introspection": "7.1.3",
6868
"@envelop/graphql-jit": "9.1.2",
69-
"@envelop/live-query": "8.1.2",
69+
"@envelop/live-query": "8.1.3",
7070
"@graphql-yoga/render-graphiql": "workspace:*",
7171
"@jest/globals": "^29.2.1",
7272
"@n1ru4l/in-memory-live-query-store": "0.10.0",

packages/graphql-yoga/src/index.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export * from './server.js';
88
export * from './subscription.js';
99
export * from './types.js';
1010
export { maskError } from './utils/mask-error.js';
11-
export { type OnParamsEventPayload, type Plugin, type Instruments } from './plugins/types.js';
11+
export { type OnParamsEventPayload, type Plugin, type Instrumentation } from './plugins/types.js';
1212
export { _createLRUCache, createLRUCache } from './utils/create-lru-cache.js';
1313
export { mergeSchemas } from '@graphql-tools/schema';
1414
export {
@@ -35,7 +35,11 @@ export {
3535
useLogger,
3636
usePayloadFormatter,
3737
} from '@envelop/core';
38-
export { getInstrumentsAndPlugins, chain, composeInstruments } from '@envelop/instruments';
38+
export {
39+
getInstrumentationAndPlugin,
40+
chain,
41+
composeInstrumentation,
42+
} from '@envelop/instrumentation';
3943
export { createGraphQLError, isPromise, mapMaybePromise } from '@graphql-tools/utils';
4044
export { getSSEProcessor } from './plugins/result-processor/sse.js';
4145
export { processRegularResult } from './plugins/result-processor/regular.js';
@@ -45,4 +49,4 @@ export {
4549
type LandingPageRendererOpts,
4650
} from './plugins/use-unhandled-route.js';
4751
export { DisposableSymbols } from '@whatwg-node/server';
48-
export * from '@envelop/instruments';
52+
export * from '@envelop/instrumentation';

packages/graphql-yoga/src/plugins/types.ts

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import {
3-
Instruments as EnvelopInstruments,
3+
Instrumentation as EnvelopInstrumentation,
44
Plugin as EnvelopPlugin,
55
OnExecuteHook,
66
OnSubscribeHook,
@@ -13,7 +13,7 @@ import { MaybePromise } from '@whatwg-node/promise-helpers';
1313
import {
1414
ServerAdapterPlugin,
1515
type ServerAdapterInitialContext,
16-
type Instruments as ServerAdapterInstruments,
16+
type Instrumentation as ServerAdapterInstrumentation,
1717
} from '@whatwg-node/server';
1818
import { YogaServer } from '../server.js';
1919
import {
@@ -51,7 +51,7 @@ export type Plugin<
5151
* A Tracer instance that will wrap each phases of the request pipeline.
5252
* This should be used primarly as an observability tool (for monitoring, tracing, etc...).
5353
*/
54-
instruments?: Instruments<YogaInitialContext & PluginContext & TUserContext>;
54+
instrumentation?: Instrumentation<YogaInitialContext & PluginContext & TUserContext>;
5555
/**
5656
* This hook is invoked at Yoga Server initialization, before it starts.
5757
* Here you can setup long running resources (like monitoring or caching clients)
@@ -92,21 +92,22 @@ export type Plugin<
9292
onResultProcess?: OnResultProcess<TServerContext>;
9393
};
9494

95-
export type Instruments<TContext extends Record<string, any>> = EnvelopInstruments<TContext> &
96-
ServerAdapterInstruments & {
97-
operation?: (
98-
payload: { context: TContext },
99-
wrapped: () => PromiseOrValue<void>,
100-
) => PromiseOrValue<void>;
101-
requestParse?: (
102-
payload: { request: Request },
103-
wrapped: () => MaybePromise<void>,
104-
) => MaybePromise<void>;
105-
resultProcess?: (
106-
payload: { request: Request },
107-
wrapped: () => MaybePromise<void>,
108-
) => MaybePromise<void>;
109-
};
95+
export type Instrumentation<TContext extends Record<string, any>> =
96+
EnvelopInstrumentation<TContext> &
97+
ServerAdapterInstrumentation & {
98+
operation?: (
99+
payload: { context: TContext },
100+
wrapped: () => PromiseOrValue<void>,
101+
) => PromiseOrValue<void>;
102+
requestParse?: (
103+
payload: { request: Request },
104+
wrapped: () => MaybePromise<void>,
105+
) => MaybePromise<void>;
106+
resultProcess?: (
107+
payload: { request: Request },
108+
wrapped: () => MaybePromise<void>,
109+
) => MaybePromise<void>;
110+
};
110111

111112
export type OnYogaInitHook<TServerContext extends Record<string, any>> = (
112113
payload: OnYogaInitEventPayload<TServerContext>,

packages/graphql-yoga/src/server.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
useExtendContext,
1010
useMaskedErrors,
1111
} from '@envelop/core';
12-
import { chain, getInstrumented } from '@envelop/instruments';
12+
import { chain, getInstrumented } from '@envelop/instrumentation';
1313
import { normalizedExecutor } from '@graphql-tools/executor';
1414
import { mapAsyncIterator } from '@graphql-tools/utils';
1515
import { createLogger, LogLevel, YogaLogger } from '@graphql-yoga/logger';
@@ -51,7 +51,7 @@ import { useHTTPValidationError } from './plugins/request-validation/use-http-va
5151
import { useLimitBatching } from './plugins/request-validation/use-limit-batching.js';
5252
import { usePreventMutationViaGET } from './plugins/request-validation/use-prevent-mutation-via-get.js';
5353
import {
54-
Instruments,
54+
Instrumentation,
5555
OnExecutionResultHook,
5656
OnParamsHook,
5757
OnRequestParseDoneHook,
@@ -224,7 +224,9 @@ export class YogaServer<
224224
protected plugins: Array<
225225
Plugin<TUserContext & TServerContext & YogaInitialContext, TServerContext, TUserContext>
226226
>;
227-
private instruments: Instruments<TUserContext & TServerContext & YogaInitialContext> | undefined;
227+
private instrumentation:
228+
| Instrumentation<TUserContext & TServerContext & YogaInitialContext>
229+
| undefined;
228230
private onRequestParseHooks: OnRequestParseHook<TServerContext>[];
229231
private onParamsHooks: OnParamsHook<TServerContext>[];
230232
private onExecutionResultHooks: OnExecutionResultHook<TServerContext>[];
@@ -468,10 +470,10 @@ export class YogaServer<
468470
if (plugin.onResultProcess) {
469471
this.onResultProcessHooks.push(plugin.onResultProcess);
470472
}
471-
if (plugin.instruments) {
472-
this.instruments = this.instruments
473-
? chain(this.instruments, plugin.instruments)
474-
: plugin.instruments;
473+
if (plugin.instrumentation) {
474+
this.instrumentation = this.instrumentation
475+
? chain(this.instrumentation, plugin.instrumentation)
476+
: plugin.instrumentation;
475477
}
476478
}
477479
}
@@ -674,10 +676,10 @@ export class YogaServer<
674676
request: Request,
675677
serverContext: TServerContext & ServerAdapterInitialContext,
676678
) => {
677-
const instrumented = this.instruments && getInstrumented({ request });
679+
const instrumented = this.instrumentation && getInstrumented({ request });
678680

679-
const parseRequest = this.instruments?.requestParse
680-
? instrumented!.asyncFn(this.instruments?.requestParse, this.parseRequest)
681+
const parseRequest = this.instrumentation?.requestParse
682+
? instrumented!.asyncFn(this.instrumentation?.requestParse, this.parseRequest)
681683
: this.parseRequest;
682684

683685
return handleMaybePromise(
@@ -686,11 +688,11 @@ export class YogaServer<
686688
if (response) {
687689
return response;
688690
}
689-
const getResultForParams = this.instruments?.operation
691+
const getResultForParams = this.instrumentation?.operation
690692
? (payload: { request: Request; params: GraphQLParams }, context: any) => {
691693
const instrumented = getInstrumented({ context });
692694
const tracedHandler = instrumented.asyncFn(
693-
this.instruments?.operation,
695+
this.instrumentation?.operation,
694696
this.getResultForParams,
695697
);
696698
return tracedHandler(payload, context);
@@ -718,8 +720,11 @@ export class YogaServer<
718720
serverContext,
719721
)) as ResultProcessorInput,
720722
result => {
721-
const tracedProcessResult = this.instruments?.resultProcess
722-
? instrumented!.asyncFn(this.instruments.resultProcess, processResult<TServerContext>)
723+
const tracedProcessResult = this.instrumentation?.resultProcess
724+
? instrumented!.asyncFn(
725+
this.instrumentation.resultProcess,
726+
processResult<TServerContext>,
727+
)
723728
: processResult<TServerContext>;
724729

725730
return tracedProcessResult({

packages/nestjs-federation/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
"dependencies": {
5656
"@apollo/gateway": "^2.4.0",
5757
"@apollo/subgraph": "^2.4.0",
58-
"@envelop/apollo-federation": "^6.1.1",
59-
"@envelop/core": "^5.2.1",
58+
"@envelop/apollo-federation": "^6.1.3",
59+
"@envelop/core": "^5.2.3",
6060
"@graphql-yoga/nestjs": "workspace:*",
6161
"@graphql-yoga/plugin-apollo-inline-trace": "workspace:*"
6262
},

packages/plugins/apollo-inline-trace/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@
4242
},
4343
"dependencies": {
4444
"@apollo/usage-reporting-protobuf": "^4.1.1",
45-
"@envelop/on-resolve": "^5.1.1",
45+
"@envelop/on-resolve": "^5.1.3",
4646
"tslib": "^2.8.1"
4747
},
4848
"devDependencies": {
4949
"@apollo/gateway": "^2.9.3",
5050
"@apollo/subgraph": "^2.9.3",
51-
"@envelop/core": "^5.2.1",
51+
"@envelop/core": "^5.2.3",
5252
"@graphql-tools/delegate": "^10.1.1",
5353
"@graphql-tools/federation": "^3.0.0",
5454
"@whatwg-node/fetch": "^0.10.1",
55-
"@whatwg-node/server": "^0.10.0",
55+
"@whatwg-node/server": "^0.10.1",
5656
"graphql": "16.10.0",
5757
"graphql-yoga": "workspace:*"
5858
},

packages/plugins/apollo-managed-federation/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
},
5757
"devDependencies": {
5858
"@whatwg-node/fetch": "^0.10.1",
59-
"@whatwg-node/server": "^0.10.0",
59+
"@whatwg-node/server": "^0.10.1",
6060
"graphql": "16.10.0",
6161
"graphql-yoga": "workspace:^",
6262
"typescript": "5.8.2"

0 commit comments

Comments
 (0)