UNPKG

@graphql-mesh/plugin-opentelemetry

Version:
133 lines (128 loc) 6.03 kB
import { AzureMonitorExporterOptions } from '@azure/monitor-opentelemetry-exporter'; import { ExporterConfig } from '@opentelemetry/exporter-zipkin'; import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; import { OTLPGRPCExporterConfigNode } from '@opentelemetry/otlp-grpc-exporter-base'; import { BufferConfig, SpanProcessor } from '@opentelemetry/sdk-trace-base'; import { MaybePromise } from '@whatwg-node/promise-helpers'; import { OnParseEventPayload, OnValidateEventPayload, OnExecuteEventPayload } from '@envelop/types'; import { GatewayPlugin } from '@graphql-hive/gateway-runtime'; import { ExecutionRequest, Executor, MaybePromise as MaybePromise$1 } from '@graphql-tools/utils'; import { TransportEntry } from '@graphql-mesh/transport-common'; import { Logger, OnFetchHookPayload } from '@graphql-mesh/types'; import { GraphQLSchema } from 'graphql'; import { Tracer, Context } from '@opentelemetry/api'; import { OnRequestEventPayload } from '@whatwg-node/server'; type BatchingConfig = boolean | BufferConfig; declare function createStdoutExporter(batchingConfig?: BatchingConfig): SpanProcessor; declare function createZipkinExporter(config: ExporterConfig, batchingConfig?: BatchingConfig): SpanProcessor; declare function createOtlpHttpExporter(config: OTLPExporterNodeConfigBase, batchingConfig?: BatchingConfig): SpanProcessor; declare function createOtlpGrpcExporter(config: OTLPGRPCExporterConfigNode, batchingConfig?: BatchingConfig): MaybePromise<SpanProcessor>; declare function createAzureMonitorExporter(config: AzureMonitorExporterOptions, batchingConfig?: BatchingConfig): MaybePromise<SpanProcessor>; declare module 'graphql' { interface GraphQLResolveInfo { executionRequest?: ExecutionRequest; } } interface OnSubgraphExecutePayload<TContext> { subgraph: GraphQLSchema; subgraphName: string; transportEntry?: TransportEntry; executionRequest: ExecutionRequest<any, TContext>; setExecutionRequest(executionRequest: ExecutionRequest): void; executor: Executor; setExecutor(executor: Executor): void; requestId?: string; logger?: Logger; } type PrimitiveOrEvaluated<TExpectedResult, TInput = never> = TExpectedResult | ((input: TInput) => TExpectedResult); interface OpenTelemetryGatewayPluginOptionsWithoutInit { /** * Whether to initialize the OpenTelemetry SDK (default: true). */ initializeNodeSDK: false; } interface OpenTelemetryGatewayPluginOptionsWithInit { /** * Whether to initialize the OpenTelemetry SDK (default: true). */ initializeNodeSDK?: true; /** * A list of OpenTelemetry exporters to use for exporting the spans. * You can use exporters from `@opentelemetry/exporter-*` packages, or use the built-in utility functions. * * Does not apply when `initializeNodeSDK` is `false`. */ exporters: MaybePromise$1<SpanProcessor>[]; /** * Service name to use for OpenTelemetry NodeSDK resource option (default: 'Gateway'). * * Does not apply when `initializeNodeSDK` is `false`. */ serviceName?: string; } type OpenTelemetryGatewayPluginOptionsInit = OpenTelemetryGatewayPluginOptionsWithInit | OpenTelemetryGatewayPluginOptionsWithoutInit; type OpenTelemetryGatewayPluginOptions = OpenTelemetryGatewayPluginOptionsInit & { /** * Tracer instance to use for creating spans (default: a tracer with name 'gateway'). */ tracer?: Tracer; /** * Whether to inherit the context from the calling service (default: true). * * 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. * * See https://opentelemetry.io/docs/languages/js/propagation/ */ inheritContext?: boolean; /** * Whether to propagate the context to the outgoing requests (default: true). * * This process is done by injecting the context into the outgoing request headers. If disabled, the context will not be propagated. * * See https://opentelemetry.io/docs/languages/js/propagation/ */ propagateContext?: boolean; /** * Options to control which spans to create. * By default, all spans are enabled. * * You may specify a boolean value to enable/disable all spans, or a function to dynamically enable/disable spans based on the input. */ spans?: { /** * Enable/disable HTTP request spans (default: true). * * Disabling the HTTP span will also disable all other child spans. */ http?: PrimitiveOrEvaluated<boolean, OnRequestEventPayload<any>>; /** * Enable/disable GraphQL parse spans (default: true). */ graphqlParse?: PrimitiveOrEvaluated<boolean, OnParseEventPayload<any>>; /** * Enable/disable GraphQL validate spans (default: true). */ graphqlValidate?: PrimitiveOrEvaluated<boolean, OnValidateEventPayload<any>>; /** * Enable/disable GraphQL execute spans (default: true). */ graphqlExecute?: PrimitiveOrEvaluated<boolean, OnExecuteEventPayload<any>>; /** * Enable/disable subgraph execute spans (default: true). */ subgraphExecute?: PrimitiveOrEvaluated<boolean, OnSubgraphExecutePayload<any>>; /** * Enable/disable upstream HTTP fetch calls spans (default: true). */ upstreamFetch?: PrimitiveOrEvaluated<boolean, OnFetchHookPayload<any>>; }; }; declare function useOpenTelemetry(options: OpenTelemetryGatewayPluginOptions & { logger: Logger; }): GatewayPlugin<{ opentelemetry: { tracer: Tracer; activeContext: () => Context; }; }>; export { type BatchingConfig, type OpenTelemetryGatewayPluginOptions as OpenTelemetryMeshPluginOptions, createAzureMonitorExporter, createOtlpGrpcExporter, createOtlpHttpExporter, createStdoutExporter, createZipkinExporter, useOpenTelemetry };