@@ -17,6 +17,11 @@ import * as Option from "effect/Option";
1717import * as Result from "effect/Result" ;
1818import * as Schema from "effect/Schema" ;
1919
20+ import {
21+ orchestrationCommandDuration ,
22+ orchestrationCommandsTotal ,
23+ withMetrics ,
24+ } from "../observability/Metrics.ts" ;
2025import * as EventSink from "../orchestration-v2/EventSink.ts" ;
2126import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator" ;
2227import * as LegacyV1ThreadImporter from "../orchestration-v2/legacy/LegacyV1ThreadImporter.ts" ;
@@ -210,7 +215,7 @@ export const make = Effect.gen(function* () {
210215 ) ,
211216 ) ;
212217
213- const commit = Effect . fn ( "ProjectService.commit" ) ( function * ( command : ProjectCommand ) {
218+ const commitEffect = Effect . fn ( "ProjectService.commit" ) ( function * ( command : ProjectCommand ) {
214219 const { projectId } = command ;
215220 const dispatchError = ( cause : unknown ) =>
216221 new ProjectOperationError ( { operation : "dispatch-project-command" , projectId, cause } ) ;
@@ -253,12 +258,18 @@ export const make = Effect.gen(function* () {
253258 error : encodeProjectCommandRejection ( planned . failure ) ,
254259 } ) ;
255260 } ) ;
261+ const timedPlanAndCommit = planAndCommit . pipe (
262+ withMetrics ( {
263+ timer : orchestrationCommandDuration ,
264+ attributes : { commandType : command . type } ,
265+ } ) ,
266+ ) ;
256267 const receipt = yield * projectLocks
257268 . withLock (
258269 projectId ,
259270 workspaceRoot === undefined
260- ? planAndCommit
261- : workspaceLocks . withLock ( workspaceRoot , planAndCommit ) ,
271+ ? timedPlanAndCommit
272+ : workspaceLocks . withLock ( workspaceRoot , timedPlanAndCommit ) ,
262273 )
263274 . pipe ( Effect . mapError ( dispatchError ) ) ;
264275 if ( receipt . projectId !== projectId || receipt . commandType !== command . type ) {
@@ -286,6 +297,14 @@ export const make = Effect.gen(function* () {
286297 }
287298 } ) ;
288299
300+ const commit = ( command : ProjectCommand ) =>
301+ commitEffect ( command ) . pipe (
302+ withMetrics ( {
303+ counter : orchestrationCommandsTotal ,
304+ attributes : { commandType : command . type } ,
305+ } ) ,
306+ ) ;
307+
289308 const readCommitted = Effect . fn ( "ProjectService.readCommitted" ) ( function * ( projectId : ProjectId ) {
290309 const row = yield * readRow ( projectId , { includeDeleted : true } ) ;
291310 if ( Option . isNone ( row ) ) {
0 commit comments