@@ -11,6 +11,7 @@ import { type PrismaClient } from "~/db.server";
1111import { ClickHouseRunsRepository } from "./clickhouseRunsRepository.server" ;
1212import { PostgresRunsRepository } from "./postgresRunsRepository.server" ;
1313import { FEATURE_FLAG , makeFlags } from "~/v3/featureFlags.server" ;
14+ import { startActiveSpan } from "~/v3/tracer.server" ;
1415
1516export type RunsRepositoryOptions = {
1617 clickhouse : ClickHouse ;
@@ -103,6 +104,7 @@ export type ListedRun = Prisma.TaskRunGetPayload<{
103104export type ListRunsOptions = RunListInputOptions & Pagination ;
104105
105106export interface IRunsRepository {
107+ name : string ;
106108 listRunIds ( options : ListRunsOptions ) : Promise < string [ ] > ;
107109 listRuns ( options : ListRunsOptions ) : Promise < {
108110 runs : ListedRun [ ] ;
@@ -123,25 +125,43 @@ export class RunsRepository implements IRunsRepository {
123125 this . postgresRunsRepository = new PostgresRunsRepository ( options ) ;
124126 }
125127
126- async #getRepository( ) {
127- const getFlag = makeFlags ( this . options . prisma ) ;
128- const runsListRepository = await getFlag ( {
129- key : FEATURE_FLAG . runsListRepository ,
130- defaultValue : "clickhouse" ,
131- } ) ;
128+ get name ( ) {
129+ return "runsRepository" ;
130+ }
132131
133- switch ( runsListRepository ) {
134- case "postgres" :
135- return this . postgresRunsRepository ;
136- case "clickhouse" :
137- default :
138- return this . clickHouseRunsRepository ;
139- }
132+ async #getRepository( ) : Promise < IRunsRepository > {
133+ return startActiveSpan ( "runsRepository.getRepository" , async ( span ) => {
134+ const getFlag = makeFlags ( this . options . prisma ) ;
135+ const runsListRepository = await getFlag ( {
136+ key : FEATURE_FLAG . runsListRepository ,
137+ defaultValue : "clickhouse" ,
138+ } ) ;
139+
140+ span . setAttribute ( "repository.name" , runsListRepository ) ;
141+
142+ switch ( runsListRepository ) {
143+ case "postgres" :
144+ return this . postgresRunsRepository ;
145+ case "clickhouse" :
146+ default :
147+ return this . clickHouseRunsRepository ;
148+ }
149+ } ) ;
140150 }
141151
142152 async listRunIds ( options : ListRunsOptions ) : Promise < string [ ] > {
143153 const repository = await this . #getRepository( ) ;
144- return repository . listRunIds ( options ) ;
154+ return startActiveSpan (
155+ "runsRepository.listRunIds" ,
156+ async ( ) => {
157+ return repository . listRunIds ( options ) ;
158+ } ,
159+ {
160+ attributes : {
161+ "repository.name" : repository . name ,
162+ } ,
163+ }
164+ ) ;
145165 }
146166
147167 async listRuns ( options : ListRunsOptions ) : Promise < {
@@ -152,12 +172,32 @@ export class RunsRepository implements IRunsRepository {
152172 } ;
153173 } > {
154174 const repository = await this . #getRepository( ) ;
155- return repository . listRuns ( options ) ;
175+ return startActiveSpan (
176+ "runsRepository.listRuns" ,
177+ async ( ) => {
178+ return repository . listRuns ( options ) ;
179+ } ,
180+ {
181+ attributes : {
182+ "repository.name" : repository . name ,
183+ } ,
184+ }
185+ ) ;
156186 }
157187
158188 async countRuns ( options : RunListInputOptions ) : Promise < number > {
159189 const repository = await this . #getRepository( ) ;
160- return repository . countRuns ( options ) ;
190+ return startActiveSpan (
191+ "runsRepository.countRuns" ,
192+ async ( ) => {
193+ return repository . countRuns ( options ) ;
194+ } ,
195+ {
196+ attributes : {
197+ "repository.name" : repository . name ,
198+ } ,
199+ }
200+ ) ;
161201 }
162202}
163203
0 commit comments