@punks/cli 2.6.0 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/README.md +45 -23
- package/dist/BASELINE_CHANGELOG.md +66 -0
- package/dist/CHANGELOG.md +102 -0
- package/dist/data/scripts/harness-projection/adapters/claude.d.mts +3 -0
- package/dist/data/scripts/harness-projection/adapters/claude.mjs +124 -0
- package/dist/data/scripts/harness-projection/adapters/codex.d.mts +3 -0
- package/dist/data/scripts/harness-projection/adapters/codex.mjs +137 -0
- package/dist/data/scripts/harness-projection/adapters/cursor.d.mts +5 -0
- package/dist/data/scripts/harness-projection/adapters/cursor.mjs +106 -0
- package/dist/data/scripts/harness-projection/adapters/opencode.d.mts +5 -0
- package/dist/data/scripts/harness-projection/adapters/opencode.mjs +100 -0
- package/dist/data/scripts/harness-projection/apply.d.mts +12 -0
- package/dist/data/scripts/harness-projection/apply.mjs +96 -0
- package/dist/data/scripts/harness-projection/core.d.mts +8 -0
- package/dist/data/scripts/harness-projection/core.mjs +239 -0
- package/dist/data/scripts/harness-projection/test-fixtures/application-context-plan.json +27 -0
- package/dist/data/scripts/harness-projection/test-fixtures/claude/actions.json +109 -0
- package/dist/data/scripts/harness-projection/test-fixtures/claude/context-plan.json +150 -0
- package/dist/data/scripts/harness-projection/test-fixtures/claude/matrix.json +23 -0
- package/dist/data/scripts/harness-projection/test-fixtures/claude/traces.json +15 -0
- package/dist/data/scripts/harness-projection/test-fixtures/codex/actions.json +124 -0
- package/dist/data/scripts/harness-projection/test-fixtures/codex/context-plan.json +150 -0
- package/dist/data/scripts/harness-projection/test-fixtures/codex/matrix.json +23 -0
- package/dist/data/scripts/harness-projection/test-fixtures/codex/traces.json +15 -0
- package/dist/data/scripts/harness-projection/test-fixtures/cursor/compiler-input.json +93 -0
- package/dist/data/scripts/harness-projection/test-fixtures/cursor/context-plan.json +108 -0
- package/dist/data/scripts/harness-projection/test-fixtures/cursor/matrix.json +19 -0
- package/dist/data/scripts/harness-projection/test-fixtures/cursor/projection.json +54 -0
- package/dist/data/scripts/harness-projection/test-fixtures/mixed-context-plan.json +35 -0
- package/dist/data/scripts/harness-projection/test-fixtures/opencode/compiler-input.json +93 -0
- package/dist/data/scripts/harness-projection/test-fixtures/opencode/context-plan.json +108 -0
- package/dist/data/scripts/harness-projection/test-fixtures/opencode/matrix.json +19 -0
- package/dist/data/scripts/harness-projection/test-fixtures/opencode/projection.json +51 -0
- package/dist/data/scripts/sync-subagents.mjs +1113 -33
- package/dist/data/subagents/manifest.mjs +5 -6
- package/dist/index.js +1375 -62557
- package/dist/skills/agnostic/cli/hi-cli/SKILL.md +22 -15
- package/dist/skills/agnostic/cli/hi-cli/references/commands.md +21 -5
- package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +87 -55
- package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +1 -1
- package/dist/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +2 -2
- package/dist/skills/agnostic/planning/create-plan/SKILL.md +12 -11
- package/dist/skills/agnostic/planning/create-plan/references/grill-ambiguity.md +10 -31
- package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +20 -2
- package/dist/skills/agnostic/planning/create-spec/SKILL.md +3 -5
- package/dist/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +1 -0
- package/dist/skills/agnostic/planning/create-spec/references/backlog-sync.md +2 -2
- package/dist/skills/agnostic/planning/create-spec/references/grill-phase.md +4 -9
- package/dist/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +1 -0
- package/dist/skills/agnostic/planning/implement-spec/SKILL.md +3 -1
- package/dist/skills/agnostic/planning/implement-spec/assets/IMPLEMENTATION-NOTES-TEMPLATE.md +6 -0
- package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +12 -1
- package/dist/skills/agnostic/planning/implement-spec/references/parallel-orchestration.md +5 -0
- package/dist/skills/agnostic/planning/implement-spec/references/parallel-worker-brief.md +7 -0
- package/dist/skills/agnostic/planning/implement-spec/references/runtime-product-validation.md +50 -0
- package/dist/skills/agnostic/planning/implement-spec/references/sequential.md +7 -5
- package/dist/skills/agnostic/requirements/grilling/LICENSE +21 -0
- package/dist/skills/agnostic/requirements/grilling/SKILL.md +6 -30
- package/dist/skills/agnostic/requirements/grilling/UPSTREAM.md +16 -0
- package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +3 -5
- package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +40 -16
- package/dist/skills/agnostic/requirements/requirements-grill/references/grilling-flow.md +3 -16
- package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +21 -15
- package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +14 -14
- package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +28 -9
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +45 -5
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +48 -28
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +22 -6
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +47 -22
- package/dist/skills/frameworks/effect/effect/LICENSE +21 -0
- package/dist/skills/frameworks/effect/effect/SKILL.md +100 -0
- package/dist/skills/frameworks/effect/effect/UPSTREAM.md +11 -0
- package/dist/skills/frameworks/effect/effect/references/CACHING.md +76 -0
- package/dist/skills/frameworks/effect/effect/references/CONFIG.md +67 -0
- package/dist/skills/frameworks/effect/effect/references/HTTP_CLIENTS.md +101 -0
- package/dist/skills/frameworks/effect/{effect-authoring/references/otel-patterns.md → effect/references/OBSERVABILITY.md} +4 -29
- package/dist/skills/frameworks/effect/effect/references/SCHEDULING.md +135 -0
- package/dist/skills/frameworks/effect/effect/references/SCHEMA.md +130 -0
- package/dist/skills/frameworks/effect/effect/references/SERVICES_LAYERS.md +168 -0
- package/dist/skills/frameworks/effect/effect/references/STREAMS.md +135 -0
- package/dist/skills/frameworks/effect/effect/references/TESTING.md +118 -0
- package/dist/skills/frameworks/effect/effect-backend-structure/SKILL.md +7 -8
- package/dist/skills/frameworks/effect/effect-recoverable-actions/SKILL.md +1 -1
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/.gitignore +29 -0
- package/dist/skills/misc/secrets-cli/SKILL.md +54 -0
- package/dist/skills/misc/secrets-cli/references/command-reference.md +107 -0
- package/dist/skills/misc/secrets-cli/references/safety-and-errors.md +54 -0
- package/dist/skills/misc/secrets-cli/references/workflows.md +106 -0
- package/dist/skills/phases/design-phase/phases/grill.md +1 -1
- package/dist/skills/phases/requirements-phase/SKILL.md +2 -4
- package/dist/skills/phases/review-phase/REFERENCE.md +13 -5
- package/dist/skills/phases/review-phase/SKILL.md +3 -2
- package/package.json +1 -1
- package/dist/skills/agnostic/planning/create-spec/references/handoff.md +0 -47
- package/dist/skills/frameworks/effect/effect-authoring/SKILL.md +0 -116
- package/dist/skills/frameworks/effect/effect-authoring/references/branded-types.md +0 -98
- package/dist/skills/frameworks/effect/effect-authoring/references/effect-primitives.md +0 -144
- package/dist/skills/frameworks/effect/effect-authoring/references/error-patterns.md +0 -156
- package/dist/skills/frameworks/effect/effect-authoring/references/test-patterns.md +0 -146
- package/dist/skills/frameworks/effect/effect-best-practices/SKILL.md +0 -517
- package/dist/skills/frameworks/effect/effect-best-practices/references/anti-patterns.md +0 -392
- package/dist/skills/frameworks/effect/effect-best-practices/references/effect-atom-patterns.md +0 -653
- package/dist/skills/frameworks/effect/effect-best-practices/references/error-patterns.md +0 -464
- package/dist/skills/frameworks/effect/effect-best-practices/references/language-server.md +0 -287
- package/dist/skills/frameworks/effect/effect-best-practices/references/layer-patterns.md +0 -495
- package/dist/skills/frameworks/effect/effect-best-practices/references/observability-patterns.md +0 -342
- package/dist/skills/frameworks/effect/effect-best-practices/references/rpc-cluster-patterns.md +0 -418
- package/dist/skills/frameworks/effect/effect-best-practices/references/schema-patterns.md +0 -353
- package/dist/skills/frameworks/effect/effect-best-practices/references/service-patterns.md +0 -299
- /package/dist/skills/frameworks/effect/{effect-authoring/references/effect-atom-patterns.md → effect/references/EFFECT_ATOM.md} +0 -0
package/dist/skills/frameworks/effect/effect-best-practices/references/observability-patterns.md
DELETED
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
# Observability Patterns
|
|
2
|
-
|
|
3
|
-
## Structured Logging with Effect.log
|
|
4
|
-
|
|
5
|
-
**Always use Effect.log** instead of console.log. Effect.log provides:
|
|
6
|
-
- Structured data
|
|
7
|
-
- Log levels
|
|
8
|
-
- Integration with telemetry systems
|
|
9
|
-
- Testability
|
|
10
|
-
|
|
11
|
-
### Basic Logging
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
// Simple message
|
|
15
|
-
yield* Effect.log("Processing started")
|
|
16
|
-
|
|
17
|
-
// With structured data
|
|
18
|
-
yield* Effect.log("Processing order", {
|
|
19
|
-
orderId,
|
|
20
|
-
userId,
|
|
21
|
-
amount,
|
|
22
|
-
currency,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
// Different log levels
|
|
26
|
-
yield* Effect.logDebug("Cache lookup", { key, hit: true })
|
|
27
|
-
yield* Effect.logInfo("User logged in", { userId })
|
|
28
|
-
yield* Effect.logWarning("Rate limit approaching", { current: 95, limit: 100 })
|
|
29
|
-
yield* Effect.logError("Payment failed", { orderId, reason: error.message })
|
|
30
|
-
yield* Effect.logFatal("Database connection lost")
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### Logging in Services
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
const processOrder = Effect.fn("OrderService.processOrder")(function* (input: OrderInput) {
|
|
37
|
-
yield* Effect.log("Starting order processing", { orderId: input.orderId })
|
|
38
|
-
|
|
39
|
-
const result = yield* validateAndProcess(input).pipe(
|
|
40
|
-
Effect.tap(() => Effect.log("Order processed successfully")),
|
|
41
|
-
Effect.tapError((err) =>
|
|
42
|
-
Effect.logError("Order processing failed", {
|
|
43
|
-
orderId: input.orderId,
|
|
44
|
-
error: err._tag,
|
|
45
|
-
message: err.message,
|
|
46
|
-
})
|
|
47
|
-
),
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
return result
|
|
51
|
-
})
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Effect.fn for Automatic Tracing
|
|
55
|
-
|
|
56
|
-
**Always use Effect.fn** for service methods. This automatically creates spans with proper names:
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
// Creates span: "UserService.findById"
|
|
60
|
-
const findById = Effect.fn("UserService.findById")(function* (id: UserId) {
|
|
61
|
-
// Automatic span creation with:
|
|
62
|
-
// - Start/end timing
|
|
63
|
-
// - Error capture
|
|
64
|
-
// - Parameter tracking (if annotated)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
// Creates span: "PaymentService.processPayment"
|
|
68
|
-
const processPayment = Effect.fn("PaymentService.processPayment")(
|
|
69
|
-
function* (orderId: OrderId, amount: number) {
|
|
70
|
-
// ...
|
|
71
|
-
}
|
|
72
|
-
)
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### Naming Convention
|
|
76
|
-
|
|
77
|
-
Use `ServiceName.methodName` format consistently:
|
|
78
|
-
- `UserService.findById`
|
|
79
|
-
- `OrderService.create`
|
|
80
|
-
- `PaymentService.refund`
|
|
81
|
-
- `NotificationService.sendEmail`
|
|
82
|
-
|
|
83
|
-
## Span Annotations
|
|
84
|
-
|
|
85
|
-
Add important context to spans, but don't overdo it:
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
const processOrder = Effect.fn("OrderService.process")(function* (orderId: OrderId) {
|
|
89
|
-
// GOOD - Important business identifiers
|
|
90
|
-
yield* Effect.annotateCurrentSpan("orderId", orderId)
|
|
91
|
-
yield* Effect.annotateCurrentSpan("userId", order.userId)
|
|
92
|
-
yield* Effect.annotateCurrentSpan("totalAmount", order.total)
|
|
93
|
-
|
|
94
|
-
// BAD - Too much detail, creates noise
|
|
95
|
-
// yield* Effect.annotateCurrentSpan("step", "validating")
|
|
96
|
-
// yield* Effect.annotateCurrentSpan("itemCount", order.items.length)
|
|
97
|
-
// yield* Effect.annotateCurrentSpan("item0Name", order.items[0].name)
|
|
98
|
-
})
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### What to Annotate
|
|
102
|
-
|
|
103
|
-
**Do annotate:**
|
|
104
|
-
- Entity IDs (orderId, userId, etc.)
|
|
105
|
-
- Important business values (amounts, statuses)
|
|
106
|
-
- Error context when failing
|
|
107
|
-
|
|
108
|
-
**Don't annotate:**
|
|
109
|
-
- Step-by-step progress
|
|
110
|
-
- Individual item details
|
|
111
|
-
- Internal implementation state
|
|
112
|
-
- Sensitive data (PII, secrets)
|
|
113
|
-
|
|
114
|
-
## Metrics
|
|
115
|
-
|
|
116
|
-
### Counter
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
import { Metric } from "effect"
|
|
120
|
-
|
|
121
|
-
// Define metrics at module level
|
|
122
|
-
const ordersProcessed = Metric.counter("orders_processed", {
|
|
123
|
-
description: "Total orders processed",
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const ordersFailed = Metric.counter("orders_failed", {
|
|
127
|
-
description: "Total orders that failed processing",
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
// Use in service
|
|
131
|
-
const processOrder = Effect.fn("OrderService.process")(function* (input: OrderInput) {
|
|
132
|
-
return yield* process(input).pipe(
|
|
133
|
-
Effect.tap(() => Metric.increment(ordersProcessed)),
|
|
134
|
-
Effect.tapError(() => Metric.increment(ordersFailed)),
|
|
135
|
-
)
|
|
136
|
-
})
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### Counter with Tags
|
|
140
|
-
|
|
141
|
-
```typescript
|
|
142
|
-
const httpRequests = Metric.counter("http_requests_total", {
|
|
143
|
-
description: "Total HTTP requests",
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
// Tag with method and status
|
|
147
|
-
yield* Metric.increment(httpRequests).pipe(
|
|
148
|
-
Metric.tagged("method", request.method),
|
|
149
|
-
Metric.tagged("status", String(response.status)),
|
|
150
|
-
Metric.tagged("path", request.path),
|
|
151
|
-
)
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Gauge
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
const activeConnections = Metric.gauge("active_connections", {
|
|
158
|
-
description: "Number of active connections",
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
// Update gauge
|
|
162
|
-
yield* Metric.set(activeConnections, connectionCount)
|
|
163
|
-
|
|
164
|
-
// Or increment/decrement
|
|
165
|
-
yield* Metric.increment(activeConnections)
|
|
166
|
-
yield* Metric.decrement(activeConnections)
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### Histogram
|
|
170
|
-
|
|
171
|
-
```typescript
|
|
172
|
-
const requestDuration = Metric.histogram("request_duration_ms", {
|
|
173
|
-
description: "Request duration in milliseconds",
|
|
174
|
-
boundaries: [10, 50, 100, 250, 500, 1000, 2500, 5000],
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
// Record value
|
|
178
|
-
yield* Metric.update(requestDuration, durationMs)
|
|
179
|
-
|
|
180
|
-
// Or use timer helper
|
|
181
|
-
const timedEffect = effect.pipe(
|
|
182
|
-
Metric.timerWithHistogram(requestDuration),
|
|
183
|
-
)
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
## Configuration with Config
|
|
187
|
-
|
|
188
|
-
**Always use Config** instead of process.env:
|
|
189
|
-
|
|
190
|
-
### Basic Config
|
|
191
|
-
|
|
192
|
-
```typescript
|
|
193
|
-
import { Config, Effect } from "effect"
|
|
194
|
-
|
|
195
|
-
const config = Config.all({
|
|
196
|
-
port: Config.integer("PORT").pipe(Config.withDefault(3000)),
|
|
197
|
-
host: Config.string("HOST").pipe(Config.withDefault("localhost")),
|
|
198
|
-
env: Config.literal("development", "staging", "production")("NODE_ENV"),
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
// Use in layer
|
|
202
|
-
const ServerLive = Layer.unwrapEffect(
|
|
203
|
-
Effect.gen(function* () {
|
|
204
|
-
const { port, host, env } = yield* config
|
|
205
|
-
return Layer.succeed(ServerConfig, { port, host, env })
|
|
206
|
-
})
|
|
207
|
-
)
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
### Config with Validation
|
|
211
|
-
|
|
212
|
-
```typescript
|
|
213
|
-
const dbConfig = Config.all({
|
|
214
|
-
host: Config.string("DB_HOST"),
|
|
215
|
-
port: Config.integer("DB_PORT").pipe(
|
|
216
|
-
Config.validate({
|
|
217
|
-
message: "Port must be between 1 and 65535",
|
|
218
|
-
validation: (p) => p >= 1 && p <= 65535,
|
|
219
|
-
})
|
|
220
|
-
),
|
|
221
|
-
database: Config.string("DB_NAME"),
|
|
222
|
-
maxConnections: Config.integer("DB_MAX_CONNECTIONS").pipe(
|
|
223
|
-
Config.withDefault(10),
|
|
224
|
-
Config.validate({
|
|
225
|
-
message: "Max connections must be positive",
|
|
226
|
-
validation: (n) => n > 0,
|
|
227
|
-
})
|
|
228
|
-
),
|
|
229
|
-
})
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
### Redacted Config
|
|
233
|
-
|
|
234
|
-
```typescript
|
|
235
|
-
// For sensitive values that shouldn't be logged
|
|
236
|
-
const secretConfig = Config.all({
|
|
237
|
-
apiKey: Config.redacted("API_KEY"), // Returns Redacted<string>
|
|
238
|
-
dbPassword: Config.redacted("DB_PASSWORD"),
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
// Using redacted values
|
|
242
|
-
const program = Effect.gen(function* () {
|
|
243
|
-
const { apiKey, dbPassword } = yield* secretConfig
|
|
244
|
-
|
|
245
|
-
// Redacted values are wrapped - use Redacted.value to unwrap
|
|
246
|
-
const key = Redacted.value(apiKey)
|
|
247
|
-
|
|
248
|
-
// Logging a Redacted shows "<redacted>"
|
|
249
|
-
yield* Effect.log("Config loaded", { apiKey }) // Safe - shows <redacted>
|
|
250
|
-
})
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
### Config with Nested Structure
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
const appConfig = Config.all({
|
|
257
|
-
server: Config.all({
|
|
258
|
-
port: Config.integer("SERVER_PORT"),
|
|
259
|
-
host: Config.string("SERVER_HOST"),
|
|
260
|
-
}),
|
|
261
|
-
database: Config.all({
|
|
262
|
-
url: Config.string("DATABASE_URL"),
|
|
263
|
-
pool: Config.integer("DATABASE_POOL_SIZE").pipe(Config.withDefault(10)),
|
|
264
|
-
}),
|
|
265
|
-
features: Config.all({
|
|
266
|
-
enableBeta: Config.boolean("ENABLE_BETA").pipe(Config.withDefault(false)),
|
|
267
|
-
maxUploadSize: Config.integer("MAX_UPLOAD_SIZE").pipe(Config.withDefault(10485760)),
|
|
268
|
-
}),
|
|
269
|
-
})
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
## Log Level Configuration
|
|
273
|
-
|
|
274
|
-
```typescript
|
|
275
|
-
import { Logger, LogLevel } from "effect"
|
|
276
|
-
|
|
277
|
-
// Set log level via config
|
|
278
|
-
const LoggerLive = Layer.unwrapEffect(
|
|
279
|
-
Effect.gen(function* () {
|
|
280
|
-
const level = yield* Config.literal(
|
|
281
|
-
"debug", "info", "warning", "error"
|
|
282
|
-
)("LOG_LEVEL").pipe(Config.withDefault("info"))
|
|
283
|
-
|
|
284
|
-
const logLevel = {
|
|
285
|
-
debug: LogLevel.Debug,
|
|
286
|
-
info: LogLevel.Info,
|
|
287
|
-
warning: LogLevel.Warning,
|
|
288
|
-
error: LogLevel.Error,
|
|
289
|
-
}[level]
|
|
290
|
-
|
|
291
|
-
return Logger.minimumLogLevel(logLevel)
|
|
292
|
-
})
|
|
293
|
-
)
|
|
294
|
-
|
|
295
|
-
// Production: structured JSON logging
|
|
296
|
-
const JsonLoggerLive = Logger.json
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
## Combining Observability
|
|
300
|
-
|
|
301
|
-
```typescript
|
|
302
|
-
const processOrder = Effect.fn("OrderService.process")(function* (input: OrderInput) {
|
|
303
|
-
const startTime = yield* Effect.clockWith((clock) => clock.currentTimeMillis)
|
|
304
|
-
|
|
305
|
-
// Annotate span
|
|
306
|
-
yield* Effect.annotateCurrentSpan("orderId", input.orderId)
|
|
307
|
-
yield* Effect.annotateCurrentSpan("userId", input.userId)
|
|
308
|
-
|
|
309
|
-
// Log start
|
|
310
|
-
yield* Effect.log("Processing order", { orderId: input.orderId })
|
|
311
|
-
|
|
312
|
-
const result = yield* process(input).pipe(
|
|
313
|
-
Effect.tap((order) =>
|
|
314
|
-
Effect.gen(function* () {
|
|
315
|
-
const endTime = yield* Effect.clockWith((c) => c.currentTimeMillis)
|
|
316
|
-
const duration = endTime - startTime
|
|
317
|
-
|
|
318
|
-
// Record metric
|
|
319
|
-
yield* Metric.update(orderProcessingDuration, duration)
|
|
320
|
-
yield* Metric.increment(ordersProcessed)
|
|
321
|
-
|
|
322
|
-
// Log completion
|
|
323
|
-
yield* Effect.log("Order processed", {
|
|
324
|
-
orderId: input.orderId,
|
|
325
|
-
durationMs: duration,
|
|
326
|
-
})
|
|
327
|
-
})
|
|
328
|
-
),
|
|
329
|
-
Effect.tapError((err) =>
|
|
330
|
-
Effect.gen(function* () {
|
|
331
|
-
yield* Metric.increment(ordersFailed)
|
|
332
|
-
yield* Effect.logError("Order processing failed", {
|
|
333
|
-
orderId: input.orderId,
|
|
334
|
-
error: err._tag,
|
|
335
|
-
})
|
|
336
|
-
})
|
|
337
|
-
),
|
|
338
|
-
)
|
|
339
|
-
|
|
340
|
-
return result
|
|
341
|
-
})
|
|
342
|
-
```
|