diff --git a/optics-agent/index.d.ts b/optics-agent/index.d.ts index ba1e930739..4d27ac71ae 100644 --- a/optics-agent/index.d.ts +++ b/optics-agent/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for optics-agent 1.0 +// Type definitions for optics-agent 1.1 // Project: https://github.com/apollostack/optics-agent-js#readme // Definitions by: Crevil // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -6,6 +6,7 @@ import { GraphQLSchema } from "graphql"; import { Request, Response } from "express"; import { Server } from "hapi"; +import { Context } from "koa"; export interface Options { /** @@ -57,6 +58,11 @@ export interface Options { * Send the query variables along with traces. Defaults to true. */ reportVariables?: boolean; + + /** + * Send statistics when the process exits. Defaults to true. + */ + shutdownGracefully?: boolean; } export class Agent { @@ -64,6 +70,7 @@ export class Agent { configureAgent(options: Options): Agent; instrumentSchema(schema: GraphQLSchema): void; + koaMiddleware(): (context: Context, next: () => Promise) => void; middleware(): (req: Request, res: Response, next?: any) => void; instrumentHapiServer(server: Server): void; context(req: Request): any; @@ -71,6 +78,7 @@ export class Agent { export function configureAgent(options: Options): Agent; export function instrumentSchema(schema: GraphQLSchema): void; +export function koaMiddleware(): (context: Context, next: () => Promise) => void; export function middleware(): (req: Request, res: Response, next?: any) => void; export function instrumentHapiServer(server: Server): void; export function context(req: Request): any; @@ -78,6 +86,7 @@ export function context(req: Request): any; export default { configureAgent, instrumentSchema, + koaMiddleware, middleware, instrumentHapiServer, context, diff --git a/optics-agent/optics-agent-tests.ts b/optics-agent/optics-agent-tests.ts index 758b374efa..cb4cb60051 100644 --- a/optics-agent/optics-agent-tests.ts +++ b/optics-agent/optics-agent-tests.ts @@ -4,12 +4,14 @@ import OpticsAgent, { middleware, instrumentHapiServer, context, + Options, } from 'optics-agent'; import { GraphQLSchema } from 'graphql'; import * as express from 'express'; import * as hapi from 'hapi'; +import * as KoaServer from 'koa'; -const configOptions = { +const configOptions: Options = { apiKey: "", reportTraces: false, reportVariables: false, @@ -18,6 +20,7 @@ const configOptions = { endpointUrl: "", proxyUrl: "", reportIntervalMs: 1, + shutdownGracefully: false, }; OpticsAgent.configureAgent(configOptions); @@ -27,6 +30,9 @@ expressServer.use(OpticsAgent.middleware()); const hapiServer = new hapi.Server(); OpticsAgent.instrumentHapiServer(hapiServer); +const koaServer = new KoaServer(); +koaServer.use(OpticsAgent.koaMiddleware()); + const req = {} as express.Request; OpticsAgent.context(req);