@tracepanel/js 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +265 -14
- package/dist/agent.d.ts +5 -1
- package/dist/agent.js +12 -3
- package/dist/agent.js.map +1 -1
- package/dist/aws.d.ts +27 -0
- package/dist/aws.js +368 -0
- package/dist/aws.js.map +1 -0
- package/dist/browser.d.ts +4 -1
- package/dist/browser.js +33 -3
- package/dist/browser.js.map +1 -1
- package/dist/bun.js +6 -82
- package/dist/bun.js.map +1 -1
- package/dist/calls.d.ts +5 -0
- package/dist/calls.js +7 -0
- package/dist/calls.js.map +1 -1
- package/dist/config.d.ts +7 -0
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/explain.d.ts +5 -0
- package/dist/explain.js +56 -7
- package/dist/explain.js.map +1 -1
- package/dist/express.js +43 -3
- package/dist/express.js.map +1 -1
- package/dist/fastify.d.ts +2 -0
- package/dist/fastify.js +100 -0
- package/dist/fastify.js.map +1 -0
- package/dist/frameworks.js +3 -0
- package/dist/frameworks.js.map +1 -1
- package/dist/graphql.d.ts +39 -0
- package/dist/graphql.js +337 -0
- package/dist/graphql.js.map +1 -0
- package/dist/hono.d.ts +2 -0
- package/dist/hono.js +63 -0
- package/dist/hono.js.map +1 -0
- package/dist/koa.d.ts +2 -0
- package/dist/koa.js +119 -0
- package/dist/koa.js.map +1 -0
- package/dist/llm.d.ts +20 -0
- package/dist/llm.js +632 -0
- package/dist/llm.js.map +1 -0
- package/dist/memory.d.ts +69 -0
- package/dist/memory.js +203 -0
- package/dist/memory.js.map +1 -0
- package/dist/model.d.ts +22 -1
- package/dist/model.js.map +1 -1
- package/dist/next.js +4 -4
- package/dist/next.js.map +1 -1
- package/dist/processor.d.ts +50 -5
- package/dist/processor.js +193 -30
- package/dist/processor.js.map +1 -1
- package/dist/profile.d.ts +34 -8
- package/dist/profile.js +98 -13
- package/dist/profile.js.map +1 -1
- package/dist/propagation.d.ts +12 -0
- package/dist/propagation.js +48 -0
- package/dist/propagation.js.map +1 -0
- package/dist/queries.d.ts +20 -0
- package/dist/queries.js +75 -0
- package/dist/queries.js.map +1 -0
- package/dist/respond.d.ts +12 -0
- package/dist/respond.js +85 -0
- package/dist/respond.js.map +1 -0
- package/dist/setup.js +27 -6
- package/dist/setup.js.map +1 -1
- package/dist/sql.d.ts +1 -0
- package/dist/sql.js +11 -2
- package/dist/sql.js.map +1 -1
- package/dist/sqlite.d.ts +13 -0
- package/dist/sqlite.js +291 -0
- package/dist/sqlite.js.map +1 -0
- package/dist/stack.d.ts +3 -1
- package/dist/stack.js +30 -6
- package/dist/stack.js.map +1 -1
- package/dist/testing.d.ts +128 -0
- package/dist/testing.js +362 -0
- package/dist/testing.js.map +1 -0
- package/dist/transactions.d.ts +11 -1
- package/dist/transactions.js +70 -34
- package/dist/transactions.js.map +1 -1
- package/dist/view.d.ts +17 -0
- package/dist/view.js +71 -0
- package/dist/view.js.map +1 -0
- package/dist/vitest-setup.d.ts +1 -0
- package/dist/vitest-setup.js +63 -0
- package/dist/vitest-setup.js.map +1 -0
- package/dist/vitest.d.ts +57 -0
- package/dist/vitest.js +130 -0
- package/dist/vitest.js.map +1 -0
- package/dist/widget.d.ts +16 -0
- package/dist/widget.js +42 -1
- package/dist/widget.js.map +1 -1
- package/package.json +81 -4
package/dist/fastify.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// `await app.register(tracepanel())`, before the routes: a Fastify plugin. Each route's handler is a span of its own,
|
|
2
|
+
// named by its route (`/books/:id`) and the app's line that added it; the request's trace is named by the route too.
|
|
3
|
+
// Every response gets what the badge reads (Tracepanel-Id, Server-Timing), and an HTML page the widget's script: one
|
|
4
|
+
// sent whole has it put into its body, a stream as it passes. What the request carried goes into its trace as the
|
|
5
|
+
// response goes out: its headers, query, cookies, the body Fastify parsed, the session (`request.session`), and the
|
|
6
|
+
// response's headers. An error the handler throws is the request's unless Fastify answers it below 500.
|
|
7
|
+
//
|
|
8
|
+
// Fastify's own OpenTelemetry instrumentation is deprecated, and @fastify/otel is a plugin to register too, with a span
|
|
9
|
+
// for every hook: this plugin needs nothing but Fastify's hooks.
|
|
10
|
+
import { hasBody, parsedBody, requestAttrs, responseHeaders, searchOf } from "./request.js";
|
|
11
|
+
import { runtime } from "./runtime.js";
|
|
12
|
+
import { expressSession } from "./session.js";
|
|
13
|
+
import { madeAt } from "./stack.js";
|
|
14
|
+
import { inView, statusOf, wasRecorded } from "./view.js";
|
|
15
|
+
import { inject, responseMarks, streamablePage, streamWith } from "./widget.js";
|
|
16
|
+
const TRACED = Symbol.for("tracepanel.fastify.handler");
|
|
17
|
+
const FRAMEWORK = "Fastify";
|
|
18
|
+
function isStream(payload) {
|
|
19
|
+
return payload !== null && typeof payload === "object" && typeof payload.pipe === "function";
|
|
20
|
+
}
|
|
21
|
+
/** What the request carried, the body Fastify parsed, the session as the handler left it, the response's headers. */
|
|
22
|
+
function carried(request, reply) {
|
|
23
|
+
const { headers } = request;
|
|
24
|
+
const body = hasBody(headers) ? parsedBody({ contentType: headers["content-type"] ?? "", body: request.body }) : {};
|
|
25
|
+
return {
|
|
26
|
+
...requestAttrs(headers, searchOf(request.url)),
|
|
27
|
+
...body,
|
|
28
|
+
...expressSession(request.session),
|
|
29
|
+
...responseHeaders(Object.entries(reply.getHeaders())),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function tracepanel() {
|
|
33
|
+
const plugin = async (app) => {
|
|
34
|
+
const tp = runtime();
|
|
35
|
+
if (!tp)
|
|
36
|
+
return;
|
|
37
|
+
const started = new WeakMap();
|
|
38
|
+
app.addHook("onRoute", (route) => {
|
|
39
|
+
const handler = route.handler;
|
|
40
|
+
if (handler[TRACED])
|
|
41
|
+
return;
|
|
42
|
+
// The app's line that added the route: where its handler is, most often.
|
|
43
|
+
const origin = madeAt(tp.config.root).origin;
|
|
44
|
+
const name = route.url;
|
|
45
|
+
const traced = function (request, reply) {
|
|
46
|
+
return inView(name, origin, () => handler.call(this, request, reply));
|
|
47
|
+
};
|
|
48
|
+
traced[TRACED] = true;
|
|
49
|
+
route.handler = traced;
|
|
50
|
+
});
|
|
51
|
+
app.addHook("onRequest", async (request) => {
|
|
52
|
+
started.set(request, performance.now());
|
|
53
|
+
tp.processor.setFramework(FRAMEWORK);
|
|
54
|
+
const route = request.routeOptions.url;
|
|
55
|
+
if (route)
|
|
56
|
+
tp.processor.setRoute(route);
|
|
57
|
+
});
|
|
58
|
+
// One a hook threw, or one the handler's span didn't see (a validation error is below 500, and not one).
|
|
59
|
+
app.addHook("onError", async (_request, _reply, error) => {
|
|
60
|
+
if (statusOf(error) >= 500 && !wasRecorded(error))
|
|
61
|
+
tp.processor.addError(error);
|
|
62
|
+
});
|
|
63
|
+
app.addHook("onSend", async (request, reply, payload) => {
|
|
64
|
+
if (tp.config.captureRequest)
|
|
65
|
+
tp.processor.setTraceAttrs(carried(request, reply));
|
|
66
|
+
const header = (name) => reply.getHeader(name);
|
|
67
|
+
const html = String(header("content-type") ?? "").includes("text/html") && header("content-encoding") == null;
|
|
68
|
+
const whole = typeof payload === "string" || Buffer.isBuffer(payload);
|
|
69
|
+
const page = html && (whole || (isStream(payload) && streamablePage(header)));
|
|
70
|
+
const marks = responseMarks(tp, {
|
|
71
|
+
method: request.method,
|
|
72
|
+
status: reply.statusCode,
|
|
73
|
+
startedMs: started.get(request) ?? performance.now(),
|
|
74
|
+
page,
|
|
75
|
+
framework: tp.processor.framework() ?? FRAMEWORK,
|
|
76
|
+
}, request.headers, header);
|
|
77
|
+
if (!marks)
|
|
78
|
+
return payload;
|
|
79
|
+
reply.headers(marks.headers);
|
|
80
|
+
// Fastify keeps each Set-Cookie it is given.
|
|
81
|
+
if (marks.cookie)
|
|
82
|
+
reply.header("set-cookie", marks.cookie);
|
|
83
|
+
if (!page || !marks.script)
|
|
84
|
+
return payload;
|
|
85
|
+
if (isStream(payload))
|
|
86
|
+
return streamWith(payload, marks.script);
|
|
87
|
+
const body = inject(Buffer.isBuffer(payload) ? payload.toString("utf8") : payload, marks.script);
|
|
88
|
+
if (header("content-length") !== undefined)
|
|
89
|
+
reply.header("content-length", Buffer.byteLength(body));
|
|
90
|
+
return body;
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
// Not encapsulated, as fastify-plugin would leave it: its hooks are the app's, for the routes added after it.
|
|
94
|
+
Object.assign(plugin, {
|
|
95
|
+
[Symbol.for("skip-override")]: true,
|
|
96
|
+
[Symbol.for("fastify.display-name")]: "tracepanel",
|
|
97
|
+
});
|
|
98
|
+
return plugin;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=fastify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,qHAAqH;AACrH,qHAAqH;AACrH,kHAAkH;AAClH,oHAAoH;AACpH,wGAAwG;AACxG,EAAE;AACF,wHAAwH;AACxH,iEAAiE;AAYjE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhF,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AACxD,MAAM,SAAS,GAAG,SAAS,CAAC;AAI5B,SAAS,QAAQ,CAAC,OAAgB;IAChC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,OAA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AC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,OAAkB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YAC7G,IAAI,MAAM,CAAC,gBAAgB,CAAC,KAAK,SAAS;gBAAE,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;YACpG,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,8GAA8G;IAC9G,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QACpB,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,EAAE,IAAI;QACnC,CAAC,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,EAAE,YAAY;KACnD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/frameworks.js
CHANGED
package/dist/frameworks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frameworks.js","sourceRoot":"","sources":["../src/frameworks.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,yCAAyC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,QAAQ,GAA2B;IACvC,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,cAAc;IACtB,SAAS,EAAE,MAAM;IACjB,IAAI,EAAE,MAAM;CACb,CAAC;AAEF,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;AAElD,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC3B,SAAS,CAAC;QACR,IAAI,CAAC;YACH,MAAM,OAAO,GAAY,IAAI,CAAC,KAAK,C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C;IACnC,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,OAAO,GAAG,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** What tells the processor a span is GraphQL's: an operation (it has graphql.library), `parse` or `validate`. */
|
|
2
|
+
export declare const GRAPHQL = "graphql";
|
|
3
|
+
/** What tells the processor a span is a resolver of the app's. */
|
|
4
|
+
export declare const RESOLVER = "graphql.resolver";
|
|
5
|
+
/** A Yoga plugin's hooks this one has: Yoga's own types are the app's, not a dependency of the SDK. */
|
|
6
|
+
type Hook = (payload: any) => any;
|
|
7
|
+
export interface YogaPlugin {
|
|
8
|
+
instrumentation: {
|
|
9
|
+
operation: (payload: unknown, wrapped: () => unknown) => unknown;
|
|
10
|
+
};
|
|
11
|
+
onSchemaChange: Hook;
|
|
12
|
+
onParams: Hook;
|
|
13
|
+
onParse: Hook;
|
|
14
|
+
onValidate: Hook;
|
|
15
|
+
onExecute: Hook;
|
|
16
|
+
onExecutionResult: Hook;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* GraphQL Yoga's plugin: `createYoga({ schema, plugins: [tracepanelYogaPlugin()] })`. Each operation is a span named after
|
|
20
|
+
* it, and so is the request's trace; its parse and validate phases and the app's resolvers are spans under it.
|
|
21
|
+
*/
|
|
22
|
+
export declare function tracepanelYogaPlugin(): YogaPlugin;
|
|
23
|
+
export interface ApolloPlugin {
|
|
24
|
+
serverWillStart: (service: {
|
|
25
|
+
schema: unknown;
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
schemaDidLoadOrUpdate: (schemaContext: {
|
|
28
|
+
apiSchema: unknown;
|
|
29
|
+
}) => void;
|
|
30
|
+
}>;
|
|
31
|
+
requestDidStart: (requestContext: any) => Promise<object | undefined>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Apollo Server's plugin: `new ApolloServer({ typeDefs, resolvers, plugins: [tracepanelApolloPlugin()] })`. Each
|
|
35
|
+
* operation is a span named after it, and so is the request's trace; its parse and validate phases and the app's
|
|
36
|
+
* resolvers are spans under it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function tracepanelApolloPlugin(): ApolloPlugin;
|
|
39
|
+
export {};
|
package/dist/graphql.js
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
// GraphQL servers: GraphQL Yoga (`plugins: [tracepanelYogaPlugin()]`) and Apollo Server (`plugins: [tracepanelApolloPlugin()]`).
|
|
2
|
+
// Their traces look like the Python SDK's of Strawberry and Graphene, so the console shows every server's the same
|
|
3
|
+
// way: the request is named after its operation (`GraphQL query Books`, `GraphQL query { books, authors }` when
|
|
4
|
+
// unnamed), so traffic groups by operation instead of `POST /graphql`; the operation is a span holding `parse` and
|
|
5
|
+
// `validate`; each of the app's own resolvers is a `function` span (`Book.author`, its path `books.3.author`), and
|
|
6
|
+
// what it does (a fetch(), a query) is under it. Fields without a resolver of the app's, which only read a property,
|
|
7
|
+
// are left out: a list of 500 objects would otherwise add thousands of spans. An exception a resolver throws comes
|
|
8
|
+
// back to the client in `errors` with a 200: it is the trace's error all the same. A document that didn't parse is no
|
|
9
|
+
// operation (`syntax error`); one that failed validation keeps its operation's name. The variables are in the
|
|
10
|
+
// request's body, as the app read it, their secrets masked like the rest of a body.
|
|
11
|
+
import { context, createContextKey, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
12
|
+
import { runtime } from "./runtime.js";
|
|
13
|
+
/** What tells the processor a span is GraphQL's: an operation (it has graphql.library), `parse` or `validate`. */
|
|
14
|
+
export const GRAPHQL = "graphql";
|
|
15
|
+
/** What tells the processor a span is a resolver of the app's. */
|
|
16
|
+
export const RESOLVER = "graphql.resolver";
|
|
17
|
+
const MAX_DOCUMENT = 2000;
|
|
18
|
+
const MAX_ROOT_FIELDS = 3;
|
|
19
|
+
/** What a document that didn't parse is named: it has no operation, so it groups apart from the anonymous queries. */
|
|
20
|
+
const SYNTAX_ERROR = "syntax error";
|
|
21
|
+
const tracer = trace.getTracer("tracepanel-graphql");
|
|
22
|
+
/** The operation running in this context: Yoga runs its phases and resolvers in it. */
|
|
23
|
+
const OPERATION = createContextKey("tracepanel.graphql.operation");
|
|
24
|
+
/** Apollo's operations by their context value: it runs the resolvers outside the operation's context. */
|
|
25
|
+
const byContextValue = new WeakMap();
|
|
26
|
+
/** Errors a resolver's span recorded already: the operation leaves them be. */
|
|
27
|
+
const recorded = new WeakSet();
|
|
28
|
+
const WRAPPED = Symbol.for("tracepanel.graphql.resolver");
|
|
29
|
+
function begin(library) {
|
|
30
|
+
const span = tracer.startSpan("graphql operation", { attributes: { "tracepanel.span_kind": GRAPHQL } });
|
|
31
|
+
return {
|
|
32
|
+
span,
|
|
33
|
+
context: trace.setSpan(context.active(), span),
|
|
34
|
+
library,
|
|
35
|
+
query: undefined,
|
|
36
|
+
operationName: undefined,
|
|
37
|
+
document: undefined,
|
|
38
|
+
errors: [],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** `parse` or `validate`, a span under the operation. */
|
|
42
|
+
function phase(operation, name) {
|
|
43
|
+
return tracer.startSpan(name, { attributes: { "tracepanel.span_kind": GRAPHQL } }, operation.context);
|
|
44
|
+
}
|
|
45
|
+
function documentText(query) {
|
|
46
|
+
if (!query)
|
|
47
|
+
return null;
|
|
48
|
+
const text = query.replace(/\s+/g, " ").trim();
|
|
49
|
+
return text.length <= MAX_DOCUMENT ? text : `${text.slice(0, MAX_DOCUMENT)}…`;
|
|
50
|
+
}
|
|
51
|
+
/** `{ books, authors }`: what an unnamed operation asks for, so `{ books { id } }` isn't only "anonymous". */
|
|
52
|
+
function rootFields(document) {
|
|
53
|
+
const operation = document.definitions.find((node) => node.kind === "OperationDefinition" && !node.name);
|
|
54
|
+
const fields = (operation?.selectionSet?.selections ?? [])
|
|
55
|
+
.filter((node) => node.kind === "Field")
|
|
56
|
+
.map((node) => node.name?.value ?? "");
|
|
57
|
+
if (fields.length === 0)
|
|
58
|
+
return null;
|
|
59
|
+
const more = fields.length - MAX_ROOT_FIELDS;
|
|
60
|
+
return `{ ${fields.slice(0, MAX_ROOT_FIELDS).join(", ")}${more > 0 ? `, +${more}` : ""} }`;
|
|
61
|
+
}
|
|
62
|
+
/** The operation the document runs: the one named, else its only one. */
|
|
63
|
+
function operationOf(document, name) {
|
|
64
|
+
const operations = document.definitions.filter((node) => node.kind === "OperationDefinition");
|
|
65
|
+
if (name)
|
|
66
|
+
return operations.find((node) => node.name?.value === name);
|
|
67
|
+
return operations.length === 1 ? operations[0] : undefined;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A GraphQL error made on purpose: one the server made of the client's mistake (a syntax or validation error), or
|
|
71
|
+
* one a resolver threw as its answer (`throw new GraphQLError("not found")`). Not the app's failure.
|
|
72
|
+
*/
|
|
73
|
+
function answer(error) {
|
|
74
|
+
for (let proto = Object.getPrototypeOf(error ?? {}); proto; proto = Object.getPrototypeOf(proto)) {
|
|
75
|
+
if (proto.constructor?.name === "GraphQLError")
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/** What a resolver threw, under the GraphQLError (or two: a masked one) the server wrapped it in; else undefined. */
|
|
81
|
+
function thrown(error) {
|
|
82
|
+
let at = error;
|
|
83
|
+
for (let depth = 0; depth < 4 && at instanceof Error; depth++) {
|
|
84
|
+
if (!answer(at))
|
|
85
|
+
return recorded.has(at) ? undefined : at;
|
|
86
|
+
at = at.originalError;
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
/** Names the operation's span and the request after it; the exceptions resolvers threw are the trace's errors. */
|
|
91
|
+
function finish(operation) {
|
|
92
|
+
const { span, document } = operation;
|
|
93
|
+
let kind = null;
|
|
94
|
+
let name = null;
|
|
95
|
+
let label = SYNTAX_ERROR;
|
|
96
|
+
if (document) {
|
|
97
|
+
// Not an operation of any type until it parses: the operationName the client sent names none either.
|
|
98
|
+
const node = operationOf(document, operation.operationName);
|
|
99
|
+
kind = node?.operation ?? "query";
|
|
100
|
+
name = operation.operationName ?? node?.name?.value ?? null;
|
|
101
|
+
label = `${kind} ${name ?? rootFields(document) ?? "anonymous"}`;
|
|
102
|
+
}
|
|
103
|
+
const attrs = {
|
|
104
|
+
"graphql.operation.type": kind,
|
|
105
|
+
"graphql.operation.name": name,
|
|
106
|
+
"graphql.document": documentText(operation.query),
|
|
107
|
+
"graphql.errors": operation.errors.length,
|
|
108
|
+
"graphql.library": operation.library,
|
|
109
|
+
};
|
|
110
|
+
span.updateName(label);
|
|
111
|
+
for (const [key, value] of Object.entries(attrs))
|
|
112
|
+
if (value !== null)
|
|
113
|
+
span.setAttribute(key, value);
|
|
114
|
+
for (const error of operation.errors) {
|
|
115
|
+
// A syntax or validation error wraps nothing: the client's mistake, not the app's.
|
|
116
|
+
const original = thrown(error);
|
|
117
|
+
if (!original)
|
|
118
|
+
continue;
|
|
119
|
+
recorded.add(original);
|
|
120
|
+
span.recordException(original);
|
|
121
|
+
}
|
|
122
|
+
// The request is this operation: named and grouped after it.
|
|
123
|
+
runtime()?.processor.setTraceAttrs({ ...attrs, "graphql.operation": label });
|
|
124
|
+
span.end();
|
|
125
|
+
}
|
|
126
|
+
function pathOf(info) {
|
|
127
|
+
const keys = [];
|
|
128
|
+
for (let at = info.path; at; at = at.prev)
|
|
129
|
+
keys.push(String(at.key));
|
|
130
|
+
return keys.reverse().join(".");
|
|
131
|
+
}
|
|
132
|
+
function failed(span, error) {
|
|
133
|
+
if (error instanceof Error && !answer(error)) {
|
|
134
|
+
recorded.add(error);
|
|
135
|
+
span.recordException(error);
|
|
136
|
+
}
|
|
137
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
138
|
+
}
|
|
139
|
+
/** A resolver of the app's, run in a span of its own: what it calls (fetch(), a query) goes under it. */
|
|
140
|
+
function traced(field, resolve) {
|
|
141
|
+
const wrapped = function (source, args, contextValue, info) {
|
|
142
|
+
const operation = (contextValue !== null && typeof contextValue === "object" ? byContextValue.get(contextValue) : undefined) ??
|
|
143
|
+
context.active().getValue(OPERATION);
|
|
144
|
+
if (!operation)
|
|
145
|
+
return resolve.call(this, source, args, contextValue, info);
|
|
146
|
+
const name = `${info.parentType.name}.${info.fieldName}`;
|
|
147
|
+
const attributes = {
|
|
148
|
+
"tracepanel.span_kind": RESOLVER,
|
|
149
|
+
"graphql.field": name,
|
|
150
|
+
"graphql.path": pathOf(info),
|
|
151
|
+
"code.function": name,
|
|
152
|
+
};
|
|
153
|
+
const span = tracer.startSpan(name, { attributes }, operation.context);
|
|
154
|
+
let result;
|
|
155
|
+
try {
|
|
156
|
+
result = context.with(trace.setSpan(operation.context, span), () => resolve.call(this, source, args, contextValue, info));
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
failed(span, error);
|
|
160
|
+
span.end();
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
if (result !== null && typeof result?.then === "function") {
|
|
164
|
+
return Promise.resolve(result).then((value) => {
|
|
165
|
+
span.end();
|
|
166
|
+
return value;
|
|
167
|
+
}, (error) => {
|
|
168
|
+
failed(span, error);
|
|
169
|
+
span.end();
|
|
170
|
+
throw error;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
span.end();
|
|
174
|
+
return result;
|
|
175
|
+
};
|
|
176
|
+
wrapped[WRAPPED] = true;
|
|
177
|
+
Object.defineProperty(wrapped, "name", { value: field });
|
|
178
|
+
return wrapped;
|
|
179
|
+
}
|
|
180
|
+
const instrumented = new WeakSet();
|
|
181
|
+
/** The app's resolvers in the schema, each in a span; once per schema. */
|
|
182
|
+
function instrument(schema) {
|
|
183
|
+
if (schema === null || typeof schema !== "object" || instrumented.has(schema))
|
|
184
|
+
return;
|
|
185
|
+
instrumented.add(schema);
|
|
186
|
+
for (const type of Object.values(schema.getTypeMap())) {
|
|
187
|
+
if (type.name.startsWith("__") || typeof type.getFields !== "function")
|
|
188
|
+
continue;
|
|
189
|
+
for (const [name, field] of Object.entries(type.getFields())) {
|
|
190
|
+
// A field without a resolver of the app's reads a property: left out.
|
|
191
|
+
if (typeof field.resolve !== "function" || field.resolve[WRAPPED])
|
|
192
|
+
continue;
|
|
193
|
+
field.resolve = traced(`${type.name}.${name}`, field.resolve);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/** Runs `wrapped` in the operation's context, and finishes the operation when it is done, however it ends. */
|
|
198
|
+
function within(operation, wrapped) {
|
|
199
|
+
const ctx = operation.context.setValue(OPERATION, operation);
|
|
200
|
+
operation.context = ctx;
|
|
201
|
+
let result;
|
|
202
|
+
try {
|
|
203
|
+
result = context.with(ctx, wrapped);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
finish(operation);
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
if (result !== null && typeof result?.then === "function") {
|
|
210
|
+
return Promise.resolve(result).then((value) => {
|
|
211
|
+
finish(operation);
|
|
212
|
+
return value;
|
|
213
|
+
}, (error) => {
|
|
214
|
+
// The server threw what didn't parse or validate: its answer has them as errors.
|
|
215
|
+
if (operation.errors.length === 0)
|
|
216
|
+
operation.errors = [error].flat();
|
|
217
|
+
finish(operation);
|
|
218
|
+
throw error;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
finish(operation);
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
function current() {
|
|
225
|
+
return context.active().getValue(OPERATION);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* GraphQL Yoga's plugin: `createYoga({ schema, plugins: [tracepanelYogaPlugin()] })`. Each operation is a span named after
|
|
229
|
+
* it, and so is the request's trace; its parse and validate phases and the app's resolvers are spans under it.
|
|
230
|
+
*/
|
|
231
|
+
export function tracepanelYogaPlugin() {
|
|
232
|
+
return {
|
|
233
|
+
instrumentation: {
|
|
234
|
+
operation: (_payload, wrapped) => {
|
|
235
|
+
// Outside a request's trace (production, or Tracepanel off): Yoga as it is.
|
|
236
|
+
if (!runtime() || !trace.getActiveSpan())
|
|
237
|
+
return wrapped();
|
|
238
|
+
return within(begin("graphql-yoga"), wrapped);
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
onSchemaChange: ({ schema }) => instrument(schema),
|
|
242
|
+
onParams: ({ params }) => {
|
|
243
|
+
const operation = current();
|
|
244
|
+
if (!operation)
|
|
245
|
+
return;
|
|
246
|
+
operation.query = params.query;
|
|
247
|
+
operation.operationName = params.operationName ?? undefined;
|
|
248
|
+
},
|
|
249
|
+
onParse: () => {
|
|
250
|
+
const operation = current();
|
|
251
|
+
if (!operation)
|
|
252
|
+
return undefined;
|
|
253
|
+
const span = phase(operation, "parse");
|
|
254
|
+
return ({ result }) => {
|
|
255
|
+
if (result instanceof Error)
|
|
256
|
+
operation.errors = [result];
|
|
257
|
+
else
|
|
258
|
+
operation.document = result;
|
|
259
|
+
span.end();
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
onValidate: () => {
|
|
263
|
+
const operation = current();
|
|
264
|
+
if (!operation)
|
|
265
|
+
return undefined;
|
|
266
|
+
const span = phase(operation, "validate");
|
|
267
|
+
return ({ valid, result }) => {
|
|
268
|
+
if (!valid)
|
|
269
|
+
operation.errors = result;
|
|
270
|
+
span.end();
|
|
271
|
+
};
|
|
272
|
+
},
|
|
273
|
+
onExecute: ({ args }) => {
|
|
274
|
+
// A schema set before this plugin was: its resolvers are instrumented as it first runs.
|
|
275
|
+
instrument(args.schema);
|
|
276
|
+
const operation = current();
|
|
277
|
+
if (!operation)
|
|
278
|
+
return;
|
|
279
|
+
operation.document = args.document;
|
|
280
|
+
operation.operationName = args.operationName ?? operation.operationName;
|
|
281
|
+
},
|
|
282
|
+
onExecutionResult: ({ result }) => {
|
|
283
|
+
const operation = current();
|
|
284
|
+
// A stream's result (@defer, a subscription) is its pieces: their errors come with them, not counted here.
|
|
285
|
+
if (!operation || result === null || typeof result !== "object" || Array.isArray(result))
|
|
286
|
+
return;
|
|
287
|
+
const errors = result.errors;
|
|
288
|
+
if (errors)
|
|
289
|
+
operation.errors = errors;
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Apollo Server's plugin: `new ApolloServer({ typeDefs, resolvers, plugins: [tracepanelApolloPlugin()] })`. Each
|
|
295
|
+
* operation is a span named after it, and so is the request's trace; its parse and validate phases and the app's
|
|
296
|
+
* resolvers are spans under it.
|
|
297
|
+
*/
|
|
298
|
+
export function tracepanelApolloPlugin() {
|
|
299
|
+
return {
|
|
300
|
+
serverWillStart: async ({ schema }) => {
|
|
301
|
+
instrument(schema);
|
|
302
|
+
return { schemaDidLoadOrUpdate: ({ apiSchema }) => instrument(apiSchema) };
|
|
303
|
+
},
|
|
304
|
+
requestDidStart: async (requestContext) => {
|
|
305
|
+
if (!runtime() || !trace.getActiveSpan())
|
|
306
|
+
return undefined;
|
|
307
|
+
instrument(requestContext.schema);
|
|
308
|
+
const operation = begin("apollo-server");
|
|
309
|
+
operation.context = operation.context.setValue(OPERATION, operation);
|
|
310
|
+
operation.query = requestContext.request.query;
|
|
311
|
+
operation.operationName = requestContext.request.operationName ?? undefined;
|
|
312
|
+
const { contextValue } = requestContext;
|
|
313
|
+
if (contextValue !== null && typeof contextValue === "object")
|
|
314
|
+
byContextValue.set(contextValue, operation);
|
|
315
|
+
return {
|
|
316
|
+
parsingDidStart: async () => {
|
|
317
|
+
const span = phase(operation, "parse");
|
|
318
|
+
return async () => span.end();
|
|
319
|
+
},
|
|
320
|
+
validationDidStart: async () => {
|
|
321
|
+
const span = phase(operation, "validate");
|
|
322
|
+
return async () => span.end();
|
|
323
|
+
},
|
|
324
|
+
didResolveOperation: async (resolved) => {
|
|
325
|
+
operation.operationName = resolved.operationName ?? operation.operationName;
|
|
326
|
+
},
|
|
327
|
+
willSendResponse: async (done) => {
|
|
328
|
+
operation.document = done.document;
|
|
329
|
+
const body = done.response?.body;
|
|
330
|
+
operation.errors = done.errors ?? (body?.kind === "single" ? body.singleResult?.errors : undefined) ?? [];
|
|
331
|
+
finish(operation);
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
//# sourceMappingURL=graphql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../src/graphql.ts"],"names":[],"mappings":"AAAA,iIAAiI;AACjI,mHAAmH;AACnH,gHAAgH;AAChH,mHAAmH;AACnH,mHAAmH;AACnH,qHAAqH;AACrH,mHAAmH;AACnH,sHAAsH;AACtH,8GAA8G;AAC9G,oFAAoF;AAEpF,OAAO,EAAgB,OAAO,EAAE,gBAAgB,EAAa,cAAc,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC/G,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,kHAAkH;AAClH,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC;AACjC,kEAAkE;AAClE,MAAM,CAAC,MAAM,QAAQ,GAAG,kBAAkB,CAAC;AAE3C,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,sHAAsH;AACtH,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;AACrD,uFAAuF;AACvF,MAAM,SAAS,GAAG,gBAAgB,CAAC,8BAA8B,CAAC,CAAC;AACnE,yGAAyG;AACzG,MAAM,cAAc,GAAG,IAAI,OAAO,EAAqB,CAAC;AACxD,+EAA+E;AAC/E,MAAM,QAAQ,GAAG,IAAI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YAAY,EAAE,SAAS,CAAC,CAAC;YAC3G,OAAO;gBACL,eAAe,EAAE,KAAK,IAAI,EAAE;oBAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;oBACvC,OAAO,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;gBAChC,CAAC;gBACD,kBAAkB,EAAE,KAAK,IAAI,EAAE;oBAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;oBAC1C,OAAO,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;gBAChC,CAAC;gBACD,mBAAmB,EAAE,KAAK,EAAE,QAAuB,EAAE,EAAE;oBACrD,SAAS,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,IAAI,SAAS,CAAC,aAAa,CAAC;gBAC9E,CAAC;gBACD,gBAAgB,EAAE,KAAK,EAAE,IAAmB,EAAE,EAAE;oBAC9C,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;oBACnC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC;oBACjC,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;oBAC1G,MAAM,CAAC,SAAS,CAAC,CAAC;gBACpB,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/hono.d.ts
ADDED
package/dist/hono.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// `app.use(tracepanel())`, first: Hono middleware, for Hono on Node (@hono/node-server) and on Bun. The route's handler
|
|
2
|
+
// is a span of its own, named by its route (`/books/:id`), and so is the request's trace. On Node every response gets
|
|
3
|
+
// what the badge reads (Tracepanel-Id, Server-Timing) and an HTML page the widget's script, put into its body as it
|
|
4
|
+
// streams; what the request carried goes into its trace: its headers, query, cookies, its body as far as the handler
|
|
5
|
+
// read it, and the response's headers. On Bun, `withTracepanel(app.fetch)` does that, and this middleware names the
|
|
6
|
+
// route and its handler under it. An error is the request's unless the app answers it below 500 (an HTTPException, or
|
|
7
|
+
// what app.onError answers).
|
|
8
|
+
//
|
|
9
|
+
// Hono matches a request before its middleware run: the handler is the last of the routes it matched that is not
|
|
10
|
+
// middleware, and its span holds what runs after this middleware (the others the route has, then the handler).
|
|
11
|
+
import { matchedRoutes } from "hono/route";
|
|
12
|
+
import { tapRequest } from "./body.js";
|
|
13
|
+
import { MARKED, marked } from "./respond.js";
|
|
14
|
+
import { runtime } from "./runtime.js";
|
|
15
|
+
import { inView, recordError, wasRecorded } from "./view.js";
|
|
16
|
+
const FRAMEWORK = "Hono";
|
|
17
|
+
/** The route that answers the request: the last one matched that isn't middleware (`app.use()`'s, `next` taken). */
|
|
18
|
+
function handlerRoute(c) {
|
|
19
|
+
const routes = matchedRoutes(c);
|
|
20
|
+
for (let at = routes.length - 1; at > c.req.routeIndex; at--) {
|
|
21
|
+
const route = routes[at];
|
|
22
|
+
if (route && (route.method !== "ALL" || route.handler.length < 2))
|
|
23
|
+
return route.path;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
export function tracepanel() {
|
|
28
|
+
const tp = runtime();
|
|
29
|
+
return async function tracepanelMiddleware(c, next) {
|
|
30
|
+
if (!tp) {
|
|
31
|
+
await next();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
tp.processor.setFramework(FRAMEWORK);
|
|
35
|
+
const startedMs = performance.now();
|
|
36
|
+
const request = c.req.raw;
|
|
37
|
+
const marking = !request[MARKED];
|
|
38
|
+
const body = marking && tp.config.captureRequest ? tapRequest(request) : undefined;
|
|
39
|
+
const route = handlerRoute(c);
|
|
40
|
+
if (route) {
|
|
41
|
+
tp.processor.setRoute(route);
|
|
42
|
+
// Hono catches what the handler throws, for app.onError: the error is the context's then.
|
|
43
|
+
await inView(route, null, async (span) => {
|
|
44
|
+
await next();
|
|
45
|
+
if (c.error)
|
|
46
|
+
recordError(span, c.error, c.res.status);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
await next();
|
|
51
|
+
}
|
|
52
|
+
// Thrown in middleware, before the handler or without one.
|
|
53
|
+
if (c.error && c.res.status >= 500 && !wasRecorded(c.error))
|
|
54
|
+
tp.processor.addError(c.error);
|
|
55
|
+
if (!marking)
|
|
56
|
+
return;
|
|
57
|
+
const answer = await marked(tp, request, c.res, startedMs, FRAMEWORK, body);
|
|
58
|
+
// Set over the response, the new one would get the old one's headers back (its Content-Length among them).
|
|
59
|
+
c.res = undefined;
|
|
60
|
+
c.res = answer.response;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=hono.js.map
|
package/dist/hono.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono.js","sourceRoot":"","sources":["../src/hono.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,sHAAsH;AACtH,oHAAoH;AACpH,qHAAqH;AACrH,oHAAoH;AACpH,sHAAsH;AACtH,6BAA6B;AAC7B,EAAE;AACF,iHAAiH;AACjH,+GAA+G;AAG/G,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7D,MAAM,SAAS,GAAG,MAAM,CAAC;AAEzB,oHAAoH;AACpH,SAAS,YAAY,CAAC,CAAU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