@@ -4,18 +4,31 @@ import { AppRuntime } from "@/effect/app-runtime"
44
55type AppEnv = Parameters < typeof AppRuntime . runPromise > [ 0 ] extends Effect . Effect < any , any , infer R > ? R : never
66
7+ // Build the base span attributes for an HTTP handler: method, path, and every
8+ // matched route param (sessionID, messageID, partID, providerID, ptyID, …)
9+ // prefixed with `opencode.`. This makes each request's root span searchable
10+ // by ID in motel without having to parse the path string.
11+ export interface RequestLike {
12+ readonly req : {
13+ readonly method : string
14+ readonly url : string
15+ param ( ) : Record < string , string >
16+ }
17+ }
18+
19+ export function requestAttributes ( c : RequestLike ) : Record < string , string > {
20+ const attributes : Record < string , string > = {
21+ "http.method" : c . req . method ,
22+ "http.path" : new URL ( c . req . url ) . pathname ,
23+ }
24+ for ( const [ key , value ] of Object . entries ( c . req . param ( ) ) ) {
25+ attributes [ `opencode.${ key } ` ] = value
26+ }
27+ return attributes
28+ }
29+
730export function runRequest < A , E > ( name : string , c : Context , effect : Effect . Effect < A , E , AppEnv > ) {
8- const url = new URL ( c . req . url )
9- return AppRuntime . runPromise (
10- effect . pipe (
11- Effect . withSpan ( name , {
12- attributes : {
13- "http.method" : c . req . method ,
14- "http.path" : url . pathname ,
15- } ,
16- } ) ,
17- ) ,
18- )
31+ return AppRuntime . runPromise ( effect . pipe ( Effect . withSpan ( name , { attributes : requestAttributes ( c ) } ) ) )
1932}
2033
2134export async function jsonRequest < C extends Context , A , E > (
0 commit comments