Update optics agent to 1.1 (#14935)

This commit is contained in:
Bjørn 2017-03-10 07:46:14 +01:00 committed by Mohamed Hegazy
parent 1177bba215
commit 68f87621d2
2 changed files with 17 additions and 2 deletions

View File

@ -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 <https://github.com/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<any>) => 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<any>) => 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,

View File

@ -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);