Skip to content

Commit aacc64a

Browse files
committed
improve proxy server
1 parent 9d3bbad commit aacc64a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

payload-files/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ the generated files go.
1010
### Next.js
1111

1212
- v7: "transaction" is " " in sent event (when error happens)
13+
- v8: 'route' is added to the name of the transaction. Eg. /test becomes /test/route

utils/event-proxy-server/src/event-proxy-server.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ function extractTransactionRoute(transactionName: string): string {
4242
return transactionName.replace('GET ', '');
4343
}
4444

45+
/** With v8, Next.js attaches /route which pollutes the filename */
46+
function deleteRouteFromName(transactionName: string): string {
47+
return transactionName.replace('/route', '');
48+
}
49+
4550
function extractRelevantFileName(str: string): string {
46-
return extractPathFromUrl(extractTransactionRoute(str));
51+
return extractPathFromUrl(extractTransactionRoute(deleteRouteFromName(str)));
4752
}
4853

4954
function addCommaAfterEachLine(data: string): string {
@@ -174,15 +179,22 @@ async function transformSavedJSON(
174179

175180
const objData = transformedJSON[2] as unknown as {
176181
request?: { url?: string };
182+
tags?: { transaction?: string };
177183
transaction?: string;
178184
contexts?: { trace?: { data?: { url?: string } } };
179185
};
180186

181187
if ('request' in objData || 'contexts' in objData) {
182188
const transactionName = objData?.transaction;
189+
const transactionNameFromTags = objData?.tags?.transaction;
183190
const url = objData?.request?.url || objData.contexts?.trace?.data?.url;
184191

185-
const filename = filenameOrigin === 'transactionName' ? transactionName : url;
192+
const filename =
193+
filenameOrigin === 'transactionName'
194+
? transactionName !== ' ' // In v7 "transaction" is a space in error events in Next.js
195+
? transactionName
196+
: transactionNameFromTags
197+
: url;
186198

187199
if (filename) {
188200
const replaceForwardSlashes = (str: string) => str.split('/').join('_');

0 commit comments

Comments
 (0)