MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / withExecutionAnalytics

Function withExecutionAnalytics

packages/core/analytics/src/engine.ts:30–63  ·  view source on GitHub ↗
(
  engine: ExecutionEngine<E>,
  analytics: AnalyticsService,
  context: ExecutionAnalyticsContext,
)

Source from the content-addressed store, hash-verified

28}
29
30export const withExecutionAnalytics = <E extends Cause.YieldableError>(
31 engine: ExecutionEngine<E>,
32 analytics: AnalyticsService,
33 context: ExecutionAnalyticsContext,
34): ExecutionEngine<E> => {
35 const completed = (ok: boolean): Effect.Effect<void> =>
36 analytics.record("execution_completed", {
37 ok,
38 plane: context.plane,
39 toolkit: context.toolkit,
40 });
41
42 const recordOutcome = (result: ExecutionResult | null): Effect.Effect<void> =>
43 result?.status === "completed" ? completed(!result.result.error) : Effect.void;
44
45 return {
46 ...engine,
47 execute: (code, options) =>
48 engine.execute(code, options).pipe(
49 Effect.tap((result) => completed(!result.error)),
50 Effect.tapError(() => completed(false)),
51 ),
52 executeWithPause: (code, options) =>
53 engine.executeWithPause(code, options).pipe(
54 Effect.tap(recordOutcome),
55 Effect.tapError(() => completed(false)),
56 ),
57 resume: (executionId, response) =>
58 engine.resume(executionId, response).pipe(
59 Effect.tap(recordOutcome),
60 Effect.tapError(() => completed(false)),
61 ),
62 };
63};

Callers 4

engine.test.tsFile · 0.90
createServerHandlersFunction · 0.90
localFixedExecutionLayerFunction · 0.90
analytics.tsFile · 0.90

Calls 2

completedFunction · 0.70
executeMethod · 0.65

Tested by

no test coverage detected