@@ -3,13 +3,19 @@ import { describe, expect, it } from "@effect/vitest";
33import * as Effect from "effect/Effect" ;
44import * as Option from "effect/Option" ;
55import * as PlatformError from "effect/PlatformError" ;
6- import { HttpClient } from "effect/unstable/http" ;
6+ import * as Tracer from "effect/Tracer" ;
7+ import { HttpClient , HttpServerRequest } from "effect/unstable/http" ;
78
9+ import { RelayClientTracer } from "@t3tools/shared/relayTracing" ;
810import * as EnvironmentAuth from "../auth/EnvironmentAuth.ts" ;
911import * as ServerSecretStore from "../auth/ServerSecretStore.ts" ;
1012import { ServerEnvironment } from "../environment/Services/ServerEnvironment.ts" ;
1113import * as CliTokenManager from "./CliTokenManager.ts" ;
12- import { consumeCloudReplayGuards , reconcileDesiredCloudLink } from "./http.ts" ;
14+ import {
15+ consumeCloudReplayGuards ,
16+ reconcileDesiredCloudLink ,
17+ traceRelayBrokerHandler ,
18+ } from "./http.ts" ;
1319import {
1420 CloudManagedEndpointRuntime ,
1521 type CloudManagedEndpointRuntimeShape ,
@@ -69,6 +75,38 @@ describe("consumeCloudReplayGuards", () => {
6975 ) ;
7076} ) ;
7177
78+ describe ( "traceRelayBrokerHandler" , ( ) => {
79+ it . effect ( "continues the incoming relay trace with the product tracer" , ( ) =>
80+ Effect . gen ( function * ( ) {
81+ const spans : Array < Tracer . Span > = [ ] ;
82+ const productTracer = Tracer . make ( {
83+ span : ( options ) => {
84+ const span = new Tracer . NativeSpan ( options ) ;
85+ spans . push ( span ) ;
86+ return span ;
87+ } ,
88+ } ) ;
89+ const request = HttpServerRequest . fromWeb (
90+ new Request ( "https://environment.example.test/api/t3-cloud/mint-credential" , {
91+ headers : {
92+ traceparent : "00-0123456789abcdef0123456789abcdef-0123456789abcdef-01" ,
93+ } ,
94+ } ) ,
95+ ) ;
96+
97+ yield * traceRelayBrokerHandler ( Effect . void . pipe ( Effect . withSpan ( "relay.mint.handler" ) ) ) . pipe (
98+ Effect . provideService ( HttpServerRequest . HttpServerRequest , request ) ,
99+ Effect . provideService ( RelayClientTracer , Option . some ( productTracer ) ) ,
100+ ) ;
101+
102+ expect ( spans ) . toHaveLength ( 1 ) ;
103+ const span = spans [ 0 ] ! ;
104+ expect ( span . traceId ) . toBe ( "0123456789abcdef0123456789abcdef" ) ;
105+ expect ( Option . getOrUndefined ( span . parent ) ?. spanId ) . toBe ( "0123456789abcdef" ) ;
106+ } ) ,
107+ ) ;
108+ } ) ;
109+
72110describe ( "reconcileDesiredCloudLink" , ( ) => {
73111 it . effect ( "requires stored CLI authorization without exposing an HTTP endpoint" , ( ) =>
74112 Effect . gen ( function * ( ) {
0 commit comments