Skip to content

Commit e603858

Browse files
committed
fix: ignore tracer spans
1 parent 26f15ba commit e603858

File tree

7 files changed

+56
-27
lines changed

7 files changed

+56
-27
lines changed

packages/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@includable/serverless-middleware": "^2.2.0",
2121
"@thi.ng/ksuid": "^3.2.83",
2222
"bcryptjs": "^2.4.3",
23-
"date-fns": "^3.6.0",
23+
"date-fns": "^4.1.0",
2424
"dynamodb-toolbox": "^1.3.8",
2525
"hono": "^4.5.10",
2626
"jest": "^29.7.0",

packages/api/src/lib/storage.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { eachDayOfInterval, parseISO, format } from "date-fns";
12
import {
23
GetObjectCommand,
34
ListObjectsV2Command,
@@ -46,14 +47,11 @@ export const listByPrefix = async (prefix) => {
4647

4748
export const list = async (startDate, endDate, prefix) => {
4849
// Get a list of all days between startDate and endDate
49-
const start = new Date(startDate);
50-
const end = new Date(endDate);
51-
const dateList = [];
52-
const currentDate = new Date(start);
53-
while (currentDate <= end) {
54-
dateList.push(currentDate.toISOString().split("T")[0]);
55-
currentDate.setDate(currentDate.getDate() + 1);
56-
}
50+
const start = typeof startDate === "string" ? parseISO(startDate) : startDate;
51+
const end = typeof endDate === "string" ? parseISO(endDate) : endDate;
52+
const dateList = eachDayOfInterval({ start, end }).map((date) =>
53+
format(date, "yyyy-MM-dd"),
54+
);
5755

5856
// Get all keys for each date, and flatten the array
5957
const allKeys = await Promise.all(

packages/dashboard/src/components/stats/transaction-graph.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
getTransactionService,
1919
useTransaction,
2020
} from "@/lib/transaction";
21+
import { isTracerSendSpan } from "@/lib/utils";
2122

2223
const GraphNode = ({ data, isConnectable }) => {
2324
return (
@@ -103,7 +104,8 @@ const buildTransactionGraph = (transaction) => {
103104
if (
104105
item.id?.endsWith("_started") ||
105106
item.type === "enrichment" ||
106-
item.type === "log"
107+
item.type === "log" ||
108+
isTracerSendSpan(item)
107109
)
108110
continue;
109111

packages/dashboard/src/lib/transaction.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { API_URL, authenticatedFetch } from "@/lib/api";
2+
import { isTracerSendSpan } from "@/lib/utils";
23
import useSWR from "swr";
34

45
export const getGroupingKey = (transaction: any, extended = false) => {
@@ -46,16 +47,19 @@ export const getTransactionService = (transaction: any) => {
4647
) {
4748
return "eventBridge";
4849
}
49-
if (transaction.info?.httpInfo?.host === "hooks.slack.com" || transaction.info?.httpInfo?.host === "slack.com") {
50+
if (
51+
transaction.info?.httpInfo?.host === "hooks.slack.com" ||
52+
transaction.info?.httpInfo?.host === "slack.com"
53+
) {
5054
return "slack";
5155
}
52-
if (transaction.info?.httpInfo?.host?.endsWith('.chargebee.com')) {
56+
if (transaction.info?.httpInfo?.host?.endsWith(".chargebee.com")) {
5357
return "chargebee";
5458
}
55-
if (transaction.info?.httpInfo?.host?.endsWith('.myshopify.com')) {
59+
if (transaction.info?.httpInfo?.host?.endsWith(".myshopify.com")) {
5660
return "shopify";
5761
}
58-
if (transaction.info?.httpInfo?.host === 'api.todoist.com') {
62+
if (transaction.info?.httpInfo?.host === "api.todoist.com") {
5963
return "todoist";
6064
}
6165

@@ -87,16 +91,19 @@ export const getTransactionLabel = (transaction: any) => {
8791
return "CloudFront";
8892
}
8993

90-
if (transaction.info?.httpInfo?.host === "hooks.slack.com" || transaction.info?.httpInfo?.host === "slack.com") {
94+
if (
95+
transaction.info?.httpInfo?.host === "hooks.slack.com" ||
96+
transaction.info?.httpInfo?.host === "slack.com"
97+
) {
9198
return "Slack";
9299
}
93-
if (transaction.info?.httpInfo?.host?.endsWith('.chargebee.com')) {
100+
if (transaction.info?.httpInfo?.host?.endsWith(".chargebee.com")) {
94101
return "Chargebee";
95102
}
96-
if (transaction.info?.httpInfo?.host?.endsWith('.myshopify.com')) {
103+
if (transaction.info?.httpInfo?.host?.endsWith(".myshopify.com")) {
97104
return "Shopify";
98105
}
99-
if (transaction.info?.httpInfo?.host === 'api.todoist.com') {
106+
if (transaction.info?.httpInfo?.host === "api.todoist.com") {
100107
return "Todoist";
101108
}
102109

@@ -127,7 +134,11 @@ export const getTransactionLabel = (transaction: any) => {
127134
export const groupSpans = (spans?: any[]) => {
128135
const grouped: { groupingKey: any; spans: any[] }[] = [];
129136
for (const span of spans || []) {
130-
if (span.id?.endsWith("_started") || span.spanType === "enrichment")
137+
if (
138+
span.id?.endsWith("_started") ||
139+
span.spanType === "enrichment" ||
140+
isTracerSendSpan(span)
141+
)
131142
continue;
132143

133144
span.groupingKey = getGroupingKey(span, true);
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import { clsx, type ClassValue } from "clsx"
2-
import { twMerge } from "tailwind-merge"
1+
import { clsx, type ClassValue } from "clsx";
2+
import { twMerge } from "tailwind-merge";
33

44
export function cn(...inputs: ClassValue[]) {
5-
return twMerge(clsx(inputs))
5+
return twMerge(clsx(inputs));
66
}
7+
8+
export const isTracerSendSpan = (span: any) => {
9+
return (
10+
span.service === "sqs" &&
11+
span.info?.httpInfo?.request?.body.includes("__TRACE_TOKEN__")
12+
);
13+
};

packages/lambda-layer/lib/utils/httpSpansAgent.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ exports.HttpSpansAgent = (() => {
2727
}
2828

2929
try {
30-
const params = {
30+
const command = new SendMessageCommand({
3131
QueueUrl: process.env.AUTO_TRACE_QUEUE_URL,
32+
MessageAttributes: {
33+
__TRACE_TOKEN__: {
34+
DataType: "String",
35+
StringValue: process.env.TRACER_TOKEN || "",
36+
},
37+
},
3238
MessageBody: JSON.stringify(requestBody),
33-
};
34-
35-
const command = new SendMessageCommand(params);
39+
});
3640
await sqsClient.send(command);
3741
} catch (error) {
3842
console.warn("Error sending trace spans:", error);

yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9438,7 +9438,7 @@ __metadata:
94389438
"@thi.ng/ksuid": "npm:^3.2.83"
94399439
"@types/jest": "npm:^29.5.13"
94409440
bcryptjs: "npm:^2.4.3"
9441-
date-fns: "npm:^3.6.0"
9441+
date-fns: "npm:^4.1.0"
94429442
dynamodb-toolbox: "npm:^1.3.8"
94439443
esbuild: "npm:^0.20.1"
94449444
hono: "npm:^4.5.10"
@@ -11799,6 +11799,13 @@ __metadata:
1179911799
languageName: node
1180011800
linkType: hard
1180111801

11802+
"date-fns@npm:^4.1.0":
11803+
version: 4.1.0
11804+
resolution: "date-fns@npm:4.1.0"
11805+
checksum: 10c0/b79ff32830e6b7faa009590af6ae0fb8c3fd9ffad46d930548fbb5acf473773b4712ae887e156ba91a7b3dc30591ce0f517d69fd83bd9c38650fdc03b4e0bac8
11806+
languageName: node
11807+
linkType: hard
11808+
1180211809
"dayjs@npm:^1.11.8":
1180311810
version: 1.11.13
1180411811
resolution: "dayjs@npm:1.11.13"

0 commit comments

Comments
 (0)