http.d.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { BasePlugin, Func } from '@opencensus/core';
  2. import * as httpModule from 'http';
  3. import * as url from 'url';
  4. export declare type IgnoreMatcher<T> = string | RegExp | ((url: string, request: T) => boolean);
  5. export declare type HttpPluginConfig = {
  6. ignoreIncomingPaths: Array<IgnoreMatcher<httpModule.IncomingMessage>>;
  7. ignoreOutgoingUrls: Array<IgnoreMatcher<httpModule.ClientRequest>>;
  8. createSpanWithNet: boolean;
  9. };
  10. export declare type HttpModule = typeof httpModule;
  11. export declare type RequestFunction = typeof httpModule.request;
  12. export declare class HttpPlugin extends BasePlugin {
  13. static ATTRIBUTE_HTTP_HOST: string;
  14. static ATTRIBUTE_HTTP_METHOD: string;
  15. static ATTRIBUTE_HTTP_PATH: string;
  16. static ATTRIBUTE_HTTP_ROUTE: string;
  17. static ATTRIBUTE_HTTP_USER_AGENT: string;
  18. static ATTRIBUTE_HTTP_STATUS_CODE: string;
  19. static ATTRIBUTE_HTTP_ERROR_NAME: string;
  20. static ATTRIBUTE_HTTP_ERROR_MESSAGE: string;
  21. protected options: HttpPluginConfig;
  22. constructor(moduleName: string);
  23. protected applyPatch(): any;
  24. protected applyUnpatch(): void;
  25. protected isIgnored<T>(url: string, request: T, list: Array<IgnoreMatcher<T>>): boolean;
  26. protected isSatisfyPattern<T>(url: string, request: T, pattern: IgnoreMatcher<T>): boolean;
  27. protected getPatchIncomingRequestFunction(): (original: (event: string) => boolean) => (event: string, ...args: any[]) => boolean;
  28. protected getPatchOutgoingRequestFunction(): (original: Func<httpModule.ClientRequest>) => Func<httpModule.ClientRequest>;
  29. private getMakeRequestTraceFunction;
  30. private createSpan;
  31. static convertTraceStatus(statusCode: number): number;
  32. hasExpectHeader(options: httpModule.ClientRequestArgs | url.URL): boolean;
  33. }
  34. export declare enum TraceStatusCodes {
  35. UNKNOWN = 2,
  36. OK = 0,
  37. INVALID_ARGUMENT = 3,
  38. DEADLINE_EXCEEDED = 4,
  39. NOT_FOUND = 5,
  40. PERMISSION_DENIED = 7,
  41. UNAUTHENTICATED = 16,
  42. RESOURCE_EXHAUSTED = 8,
  43. UNIMPLEMENTED = 12,
  44. UNAVAILABLE = 14
  45. }
  46. export declare const plugin: HttpPlugin;