Skip to content

Commit f59d758

Browse files
fix: this readds soft detection (kind only) for spans (#280)
1 parent 22665e1 commit f59d758

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

clients/web/src/lib/span/format-span.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Span } from "../connection/monitor";
44
import type { SpanEvent_Span } from "../proto/spans";
55
import { convertTimestampToNanoseconds } from "../formatters";
66
import { IpcData } from "../connection/monitor";
7+
import { detectKind } from "./update/kinds/detectKind";
78

89
export function formatSpan(
910
spanEvent: SpanEvent_Span,
@@ -48,5 +49,6 @@ export function formatSpan(
4849
hasError: null,
4950
};
5051

52+
span.kind = detectKind(span);
5153
return span;
5254
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Span } from "~/lib/connection/monitor";
2+
import { detectEventKind } from "./event/detect-event-kind";
3+
import { detectIpcKind } from "./ipc/detect-ipc-kind";
4+
5+
export function detectKind(span: Span) {
6+
if (detectEventKind(span)) return "event";
7+
if (detectIpcKind(span)) return "ipc";
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { Span } from "~/lib/connection/monitor";
2+
import { IpcKinds } from "./ipc-spans";
3+
4+
export function detectIpcKind(span: Span) {
5+
if (!span.metadata?.name) return;
6+
7+
for (const ipcKind of IpcKinds) {
8+
if (ipcKind.names.has(span.metadata.name)) {
9+
return ipcKind.type;
10+
}
11+
}
12+
}

clients/web/src/lib/span/update/kinds/ipc/detect-ipc-trace.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import type { Span, IpcData } from "~/lib/connection/monitor";
22
import { findNamedSpan } from "~/lib/span/find-named-span";
33
import { processFieldValue } from "~/lib/span/process-field-value";
44
import { getIpcResponse } from "./get-ipc-response";
5+
import { detectIpcKind } from "./detect-ipc-kind";
56

67
// TODO: Revisit this function to see if we can improve on the logic and the eslint disable comments.
78
export function detectIpcTrace(root: Span): IpcData | undefined {
8-
const ipcNames = ["wry::ipc::handle", "wry::custom_protocol::handle"];
9-
109
// First we'd like to be sure the root has a specific name.
11-
if (!root.metadata?.name || !ipcNames.includes(root.metadata?.name)) return;
10+
if (!detectIpcKind(root)) return;
1211

1312
// Then we try to parse a child span with request data.
1413
const requestSpan = findNamedSpan(root, "tauri::", "ipc::request");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type IpcKind = "ipc";
2+
3+
export const IpcKinds = [
4+
{
5+
type: "ipc",
6+
names: new Set(["wry::ipc::handle", "wry::custom_protocol::handle"]),
7+
},
8+
] as const satisfies {
9+
type: IpcKind;
10+
names: Set<string>;
11+
}[];

0 commit comments

Comments
 (0)