Socket
Socket
Sign inDemoInstall

apollo-tracing

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-tracing - npm Package Compare versions

Comparing version 0.0.9 to 0.1.0

37

lib/index.d.ts

@@ -1,2 +0,35 @@

export { TraceCollector, instrumentSchemaForTracing } from './instrumentation';
export { formatTraceData } from './tracingFormat';
import { GraphQLResolveInfo } from "graphql";
import { GraphQLExtension } from "graphql-extensions";
export interface TracingFormat {
version: 1;
startTime: string;
endTime: string;
duration: number;
execution: {
resolvers: {
path: (string | number)[];
parentType: string;
fieldName: string;
returnType: string;
startOffset: number;
duration: number;
}[];
};
}
export declare class TracingExtension<TContext = any> implements GraphQLExtension<TContext> {
private startWallTime;
private endWallTime;
private startHrTime;
private duration;
private resolverCalls;
requestDidStart(): void;
executionDidStart(): void;
willResolveField(_source: any, _args: {
[argName: string]: any;
}, _context: TContext, info: GraphQLResolveInfo): () => void;
didResolveField(_source: any, _args: {
[argName: string]: any;
}, _context: TContext, info: GraphQLResolveInfo): void;
requestDidEnd(): void;
format(): [string, TracingFormat];
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var instrumentation_1 = require("./instrumentation");
exports.TraceCollector = instrumentation_1.TraceCollector;
exports.instrumentSchemaForTracing = instrumentation_1.instrumentSchemaForTracing;
var tracingFormat_1 = require("./tracingFormat");
exports.formatTraceData = tracingFormat_1.formatTraceData;
const graphql_1 = require("graphql");
class TracingExtension {
constructor() {
this.resolverCalls = [];
}
requestDidStart() {
this.startWallTime = new Date();
this.startHrTime = process.hrtime();
}
executionDidStart() { }
willResolveField(_source, _args, _context, info) {
const resolverCall = {
path: info.path,
fieldName: info.fieldName,
parentType: info.parentType,
returnType: info.returnType,
startOffset: process.hrtime(this.startHrTime)
};
this.resolverCalls.push(resolverCall);
return () => {
resolverCall.endOffset = process.hrtime(this.startHrTime);
};
}
didResolveField(_source, _args, _context, info) { }
requestDidEnd() {
this.duration = process.hrtime(this.startHrTime);
this.endWallTime = new Date();
}
format() {
return [
"tracing",
{
version: 1,
startTime: this.startWallTime.toISOString(),
endTime: this.endWallTime.toISOString(),
duration: durationHrTimeToNanos(this.duration),
execution: {
resolvers: this.resolverCalls.map(resolverCall => {
const startOffset = durationHrTimeToNanos(resolverCall.startOffset);
const duration = resolverCall.endOffset
? durationHrTimeToNanos(resolverCall.endOffset) - startOffset
: 0;
return {
path: graphql_1.responsePathAsArray(resolverCall.path),
parentType: resolverCall.parentType.toString(),
fieldName: resolverCall.fieldName,
returnType: resolverCall.returnType.toString(),
startOffset,
duration
};
})
}
}
];
}
}
exports.TracingExtension = TracingExtension;
// Converts an hrtime array (as returned from process.hrtime) to nanoseconds.
//
// ONLY CALL THIS ON VALUES REPRESENTING DELTAS, NOT ON THE RAW RETURN VALUE
// FROM process.hrtime() WITH NO ARGUMENTS.
//
// The entire point of the hrtime data structure is that the JavaScript Number
// type can't represent all int64 values without loss of precision:
// Number.MAX_SAFE_INTEGER nanoseconds is about 104 days. Calling this function
// on a duration that represents a value less than 104 days is fine. Calling
// this function on an absolute time (which is generally roughly time since
// system boot) is not a good idea.
function durationHrTimeToNanos(hrtime) {
return hrtime[0] * 1e9 + hrtime[1];
}
//# sourceMappingURL=index.js.map

4

package.json
{
"name": "apollo-tracing",
"version": "0.0.9",
"version": "0.1.0",
"description": "Collect and expose trace data for GraphQL requests",

@@ -29,4 +29,4 @@ "main": "./lib/index.js",

"dependencies": {
"graphql-tools": "^2.2.0"
"graphql-extensions": "^0.0.4"
}
}

@@ -10,2 +10,3 @@ {

"lib": ["es2017", "esnext.asynciterable"],
"types": ["jest", "node"],
"strict": true

@@ -12,0 +13,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc