@graphql-hive/plugin-opentelemetry 1.0.0-alpha-2cea6e8a62aea3e45963d47c35cb6db588d78c54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +215 -0
- package/dist/api.cjs +43 -0
- package/dist/api.d.cts +32 -0
- package/dist/api.d.ts +32 -0
- package/dist/api.js +36 -0
- package/dist/attributes-mikIPKnv.d.ts +10 -0
- package/dist/index.cjs +78 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +12 -0
- package/dist/plugin-BT_oWPcx.cjs +1050 -0
- package/dist/plugin-Cn24wGGV.d.ts +184 -0
- package/dist/plugin-DUMSBw0j.js +1037 -0
- package/dist/setup.cjs +387 -0
- package/dist/setup.d.cts +128 -0
- package/dist/setup.d.ts +128 -0
- package/dist/setup.js +326 -0
- package/package.json +99 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { GatewayConfigContext, GatewayPlugin } from '@graphql-hive/gateway-runtime';
|
|
2
|
+
import { ExecutionRequest } from '@graphql-tools/utils';
|
|
3
|
+
import { Tracer, Context } from '@opentelemetry/api';
|
|
4
|
+
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
5
|
+
|
|
6
|
+
type OperationHashingFn = (input: {
|
|
7
|
+
document: DocumentNode;
|
|
8
|
+
operationName?: string | null;
|
|
9
|
+
variableValues?: Record<string, unknown> | null;
|
|
10
|
+
schema: GraphQLSchema;
|
|
11
|
+
}) => string | null;
|
|
12
|
+
|
|
13
|
+
type BooleanOrPredicate<TInput = never> = boolean | ((input: TInput) => boolean);
|
|
14
|
+
type OpenTelemetryGatewayPluginOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* Whether to rely on OTEL context api for span correlation.
|
|
17
|
+
* - `true`: the plugin will rely on OTEL context manager for span parenting.
|
|
18
|
+
* - `false`: the plugin will rely on request context for span parenting,
|
|
19
|
+
* which implies that parenting with user defined may be broken.
|
|
20
|
+
*
|
|
21
|
+
* By default, it is enabled if the registered Context Manager is compatible with async calls,
|
|
22
|
+
* or if it is possible to register an `AsyncLocalStorageContextManager`.
|
|
23
|
+
*
|
|
24
|
+
* Note: If `true`, an error is thrown if it fails to obtain an async calls compatible Context Manager.
|
|
25
|
+
*/
|
|
26
|
+
useContextManager?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to inherit the context from the calling service (default: true).
|
|
29
|
+
*
|
|
30
|
+
* This process is done by extracting the context from the incoming request headers. If disabled, a new context and a trace-id will be created.
|
|
31
|
+
*
|
|
32
|
+
* See https://opentelemetry.io/docs/languages/js/propagation/
|
|
33
|
+
*/
|
|
34
|
+
inheritContext?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether to propagate the context to the outgoing requests (default: true).
|
|
37
|
+
*
|
|
38
|
+
* This process is done by injecting the context into the outgoing request headers. If disabled, the context will not be propagated.
|
|
39
|
+
*
|
|
40
|
+
* See https://opentelemetry.io/docs/languages/js/propagation/
|
|
41
|
+
*/
|
|
42
|
+
propagateContext?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Configure Opentelemetry `diag` API to use Gateway's logger.
|
|
45
|
+
*
|
|
46
|
+
* @default true
|
|
47
|
+
*
|
|
48
|
+
* Note: Logger configuration respects OTEL environment variables standard.
|
|
49
|
+
* This means that the logger will be enabled only if `OTEL_LOG_LEVEL` variable is set.
|
|
50
|
+
*/
|
|
51
|
+
configureDiagLogger?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The TraceProvider method to call on Gateway's disposal. By default, it tries to run `forceFlush` method on
|
|
54
|
+
* the registered trace provider if it exists.
|
|
55
|
+
* Set to `false` to disable this behavior.
|
|
56
|
+
* @default 'forceFlush'
|
|
57
|
+
*/
|
|
58
|
+
flushOnDispose?: string | false;
|
|
59
|
+
/**
|
|
60
|
+
* Function to be used to compute the hash of each operation (graphql.operation.hash attribute).
|
|
61
|
+
* Note: pass `null` to disable operation hashing
|
|
62
|
+
*
|
|
63
|
+
* @default `hashOperation` from @graphql-hive/core
|
|
64
|
+
*/
|
|
65
|
+
hashOperation?: OperationHashingFn | null;
|
|
66
|
+
/**
|
|
67
|
+
* Tracing configuration
|
|
68
|
+
*/
|
|
69
|
+
traces?: boolean | {
|
|
70
|
+
/**
|
|
71
|
+
* Tracer instance to use for creating spans (default: a tracer with name 'gateway').
|
|
72
|
+
*/
|
|
73
|
+
tracer?: Tracer;
|
|
74
|
+
/**
|
|
75
|
+
* Options to control which spans to create.
|
|
76
|
+
* By default, all spans are enabled.
|
|
77
|
+
*
|
|
78
|
+
* You may specify a boolean value to enable/disable all spans, or a function to dynamically enable/disable spans based on the input.
|
|
79
|
+
*/
|
|
80
|
+
spans?: {
|
|
81
|
+
/**
|
|
82
|
+
* Enable/disable HTTP request spans (default: true).
|
|
83
|
+
*
|
|
84
|
+
* Disabling the HTTP span will also disable all other child spans.
|
|
85
|
+
*/
|
|
86
|
+
http?: BooleanOrPredicate<{
|
|
87
|
+
request: Request;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Enable/disable GraphQL operation spans (default: true).
|
|
91
|
+
*
|
|
92
|
+
* Disabling the GraphQL operation spa will also disable all other child spans.
|
|
93
|
+
*/
|
|
94
|
+
graphql?: BooleanOrPredicate<{
|
|
95
|
+
context: unknown;
|
|
96
|
+
}>;
|
|
97
|
+
/**
|
|
98
|
+
* Enable/disable GraphQL context building phase (default: true).
|
|
99
|
+
*/
|
|
100
|
+
graphqlContextBuilding?: BooleanOrPredicate<{
|
|
101
|
+
context: unknown;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Enable/disable GraphQL parse spans (default: true).
|
|
105
|
+
*/
|
|
106
|
+
graphqlParse?: BooleanOrPredicate<{
|
|
107
|
+
context: unknown;
|
|
108
|
+
}>;
|
|
109
|
+
/**
|
|
110
|
+
* Enable/disable GraphQL validate spans (default: true).
|
|
111
|
+
*/
|
|
112
|
+
graphqlValidate?: BooleanOrPredicate<{
|
|
113
|
+
context: unknown;
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* Enable/disable GraphQL execute spans (default: true).
|
|
117
|
+
*
|
|
118
|
+
* Disabling the GraphQL execute spans will also disable all other child spans.
|
|
119
|
+
*/
|
|
120
|
+
graphqlExecute?: BooleanOrPredicate<{
|
|
121
|
+
context: unknown;
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Enable/disable subgraph execute spans (default: true).
|
|
125
|
+
*
|
|
126
|
+
* Disabling the subgraph execute spans will also disable all other child spans.
|
|
127
|
+
*/
|
|
128
|
+
subgraphExecute?: BooleanOrPredicate<{
|
|
129
|
+
executionRequest: ExecutionRequest;
|
|
130
|
+
subgraphName: string;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Enable/disable upstream HTTP fetch calls spans (default: true).
|
|
134
|
+
*/
|
|
135
|
+
upstreamFetch?: BooleanOrPredicate<{
|
|
136
|
+
executionRequest: ExecutionRequest | undefined;
|
|
137
|
+
}>;
|
|
138
|
+
/**
|
|
139
|
+
* Enable/disable schema loading spans (default: true if context manager available).
|
|
140
|
+
*
|
|
141
|
+
* Note: This span requires an Async compatible context manager
|
|
142
|
+
*/
|
|
143
|
+
schema?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Enable/disable initialization span (default: true).
|
|
146
|
+
*/
|
|
147
|
+
initialization?: boolean;
|
|
148
|
+
};
|
|
149
|
+
events?: {
|
|
150
|
+
/**
|
|
151
|
+
* Enable/Disable cache related span events (default: true).
|
|
152
|
+
*/
|
|
153
|
+
cache?: BooleanOrPredicate<{
|
|
154
|
+
key: string;
|
|
155
|
+
action: 'read' | 'write';
|
|
156
|
+
}>;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
type ContextMatcher = {
|
|
161
|
+
request?: Request;
|
|
162
|
+
context?: any;
|
|
163
|
+
executionRequest?: ExecutionRequest;
|
|
164
|
+
};
|
|
165
|
+
type OpenTelemetryPluginUtils = {
|
|
166
|
+
tracer: Tracer;
|
|
167
|
+
getActiveContext: (payload: ContextMatcher) => Context;
|
|
168
|
+
getHttpContext: (request: Request) => Context | undefined;
|
|
169
|
+
getOperationContext: (context: any) => Context | undefined;
|
|
170
|
+
getExecutionRequestContext: (ExecutionRequest: ExecutionRequest) => Context | undefined;
|
|
171
|
+
};
|
|
172
|
+
type OpenTelemetryContextExtension = {
|
|
173
|
+
openTelemetry: {
|
|
174
|
+
tracer: Tracer;
|
|
175
|
+
getActiveContext: (payload?: ContextMatcher) => Context;
|
|
176
|
+
getHttpContext: (request?: Request) => Context | undefined;
|
|
177
|
+
getOperationContext: (context?: any) => Context | undefined;
|
|
178
|
+
getExecutionRequestContext: (ExecutionRequest: ExecutionRequest) => Context | undefined;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
type OpenTelemetryPlugin = GatewayPlugin<OpenTelemetryContextExtension> & OpenTelemetryPluginUtils;
|
|
182
|
+
declare function useOpenTelemetry(options: OpenTelemetryGatewayPluginOptions & Partial<GatewayConfigContext>): OpenTelemetryPlugin;
|
|
183
|
+
|
|
184
|
+
export { type OpenTelemetryContextExtension as O, type OpenTelemetryGatewayPluginOptions as a, type OpenTelemetryPlugin as b, type OpenTelemetryPluginUtils as c, useOpenTelemetry as u };
|