Skip to content

Commit dd0580a

Browse files
committed
parse vercel id
1 parent aaa4d39 commit dd0580a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
* parse vercel id
11+
812
## [0.1.5] - 2024-02-13
913

1014
* fix request id header support for vercel

src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ export function withOpenTelemetry(fn: Handle, opts?: TraceOptions): Handle {
3030
const name = `${args.event.request.method} ${args.event.route.id}`;
3131
let requestId: string | undefined = undefined;
3232

33-
if(opts.requestIdHeader) {
33+
if (opts.requestIdHeader) {
3434
possibleRequestIdHeaders.push(opts.requestIdHeader.toLowerCase());
3535
}
3636

37-
for(let header of possibleRequestIdHeaders) {
37+
for (let header of possibleRequestIdHeaders) {
3838
const val = args.event.request.headers.get(header);
39-
if(val) {
39+
if (header === "x-vercel-id" && val) {
40+
// Only match the last part of the id because otherwise it can differ from the logs as it appends the edge location region to it.
41+
const requestIdParts = val.split("::");
42+
const id = requestIdParts[requestIdParts.length - 1];
43+
requestId = id;
44+
}
45+
if (val) {
4046
requestId = val;
4147
break;
4248
}
@@ -57,7 +63,7 @@ export function withOpenTelemetry(fn: Handle, opts?: TraceOptions): Handle {
5763
body: args.event.request.body,
5864
}
5965
},
60-
66+
6167
},
6268
svelte: {
6369
route: args.event.route,
@@ -81,7 +87,7 @@ export function withOpenTelemetry(fn: Handle, opts?: TraceOptions): Handle {
8187
}
8288
}
8389
}));
84-
90+
8591
span.end();
8692

8793
return res;

0 commit comments

Comments
 (0)