remove detailed gql from honeycomb traces
This wasn't actually super helpful to read anyway, and I think it was causing us to hit rate limits. We can maybe add back a limited version to like, add path context of _where_ a span happened in the GQL tree, but like, I feel like that's typically been pretty intuitive so far.
This commit is contained in:
parent
dfeeb9fe0d
commit
dc785b063e
2 changed files with 1 additions and 71 deletions
|
@ -1,6 +1,6 @@
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
|
|
||||||
const { addBeelineToSchema, beelinePlugin } = require("./lib/beeline-graphql");
|
const { beelinePlugin } = require("./lib/beeline-graphql");
|
||||||
const { gql, makeExecutableSchema } = require("apollo-server");
|
const { gql, makeExecutableSchema } = require("apollo-server");
|
||||||
const jwtVerify = util.promisify(require("jsonwebtoken").verify);
|
const jwtVerify = util.promisify(require("jsonwebtoken").verify);
|
||||||
const jwksClient = require("jwks-rsa");
|
const jwksClient = require("jwks-rsa");
|
||||||
|
@ -49,7 +49,6 @@ const schema = makeExecutableSchema(
|
||||||
const plugins = [svgLoggingPlugin];
|
const plugins = [svgLoggingPlugin];
|
||||||
|
|
||||||
if (process.env["NODE_ENV"] !== "test") {
|
if (process.env["NODE_ENV"] !== "test") {
|
||||||
addBeelineToSchema(schema);
|
|
||||||
plugins.push(beelinePlugin);
|
plugins.push(beelinePlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,72 +1,4 @@
|
||||||
// Integrates Honeycomb tracing with Apollo Server.
|
|
||||||
// Adapted from https://gist.github.com/numso/504faeca4e946c2c54e8b890c6469d81
|
|
||||||
const beeline = require("honeycomb-beeline");
|
const beeline = require("honeycomb-beeline");
|
||||||
const gql = require("graphql");
|
|
||||||
|
|
||||||
function addBeelineToSchema(schema) {
|
|
||||||
if (!beeline) return;
|
|
||||||
forEachField(schema, (field) => {
|
|
||||||
if (!field.resolve) return;
|
|
||||||
const oldResolve = field.resolve;
|
|
||||||
field.resolve = (source, args, context, info) => {
|
|
||||||
context.spans = context.spans || {};
|
|
||||||
let result;
|
|
||||||
const path = responsePathAsString(info.path);
|
|
||||||
beeline.startAsyncSpan(fieldsFor("resolve", path), async (span) => {
|
|
||||||
context.spans[path] = span.payload["trace.span_id"];
|
|
||||||
try {
|
|
||||||
result = oldResolve(source, args, { ...context, span }, info);
|
|
||||||
if (result.then) await result;
|
|
||||||
} catch (error) {
|
|
||||||
span.addContext({ "error.message": error.message });
|
|
||||||
span.addContext({ "error.stacktrace": error.stack });
|
|
||||||
}
|
|
||||||
const parent = getParentId(context.spans, path);
|
|
||||||
if (parent) span.addContext({ "trace.parent_id": parent });
|
|
||||||
beeline.finishSpan(span);
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function forEachField(schema, fn) {
|
|
||||||
const typeMap = schema.getTypeMap();
|
|
||||||
Object.keys(typeMap).forEach((typeName) => {
|
|
||||||
const type = typeMap[typeName];
|
|
||||||
if (
|
|
||||||
!gql.getNamedType(type).name.startsWith("__") &&
|
|
||||||
type instanceof gql.GraphQLObjectType
|
|
||||||
) {
|
|
||||||
const fields = type.getFields();
|
|
||||||
Object.keys(fields).forEach((fieldName) => {
|
|
||||||
const field = fields[fieldName];
|
|
||||||
fn(field, typeName, fieldName);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const responsePathAsString = (path) => gql.responsePathAsArray(path).join(".");
|
|
||||||
|
|
||||||
function getParentId(spanIds, currentPath) {
|
|
||||||
const path = currentPath.split(".").slice(0, -1).join(".");
|
|
||||||
if (!path) return null;
|
|
||||||
if (!(path in spanIds)) {
|
|
||||||
const span = beeline.startSpan(fieldsFor("field", path));
|
|
||||||
spanIds[path] = span.payload["trace.span_id"];
|
|
||||||
const parent = getParentId(spanIds, path);
|
|
||||||
if (parent) span.addContext({ "trace.parent_id": parent });
|
|
||||||
beeline.finishSpan(span);
|
|
||||||
}
|
|
||||||
return spanIds[path];
|
|
||||||
}
|
|
||||||
|
|
||||||
const fieldsFor = (name, path) => ({
|
|
||||||
name,
|
|
||||||
"graphql.path": path,
|
|
||||||
"graphql.key": path.split(".").pop(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const beelinePlugin = {
|
const beelinePlugin = {
|
||||||
requestDidStart() {
|
requestDidStart() {
|
||||||
|
@ -86,6 +18,5 @@ const beelinePlugin = {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addBeelineToSchema,
|
|
||||||
beelinePlugin,
|
beelinePlugin,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue