@uploadista/observability 0.0.11 → 0.0.13-beta.1
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/dist/index.cjs +1 -1
- package/dist/index.d.cts +233 -233
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +233 -233
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/flow/index.ts +7 -6
- package/src/flow/testing.ts +1 -1
- package/src/storage/index.ts +3 -2
- package/src/test-observability.ts +20 -17
- package/src/upload/index.ts +6 -5
|
@@ -13,12 +13,12 @@ import { Effect, Layer, Metric } from "effect";
|
|
|
13
13
|
import {
|
|
14
14
|
classifyStorageError,
|
|
15
15
|
createStorageMetrics,
|
|
16
|
+
logStorageOperation,
|
|
17
|
+
logUploadCompletion,
|
|
16
18
|
makeStorageObservabilityLayer,
|
|
17
19
|
StorageObservability,
|
|
18
20
|
trackStorageError,
|
|
19
21
|
withStorageSpan,
|
|
20
|
-
logStorageOperation,
|
|
21
|
-
logUploadCompletion,
|
|
22
22
|
} from "./index.js";
|
|
23
23
|
|
|
24
24
|
// ============================================================================
|
|
@@ -50,14 +50,14 @@ const simulateUpload = (fileSize: number, shouldFail: boolean) =>
|
|
|
50
50
|
testStorageType,
|
|
51
51
|
"uploadFile",
|
|
52
52
|
"test-upload-123",
|
|
53
|
-
{ file_size: fileSize }
|
|
53
|
+
{ file_size: fileSize },
|
|
54
54
|
);
|
|
55
55
|
|
|
56
56
|
// Simulate upload with tracing
|
|
57
57
|
const uploadEffect = Effect.gen(function* () {
|
|
58
58
|
// Track upload request
|
|
59
59
|
yield* obs.metrics.uploadRequestsTotal.pipe(
|
|
60
|
-
Metric.tagged("upload_id", "test-upload-123")
|
|
60
|
+
Metric.tagged("upload_id", "test-upload-123"),
|
|
61
61
|
)(Effect.succeed(1));
|
|
62
62
|
|
|
63
63
|
// Track file size
|
|
@@ -67,12 +67,14 @@ const simulateUpload = (fileSize: number, shouldFail: boolean) =>
|
|
|
67
67
|
yield* Effect.sleep("100 millis");
|
|
68
68
|
|
|
69
69
|
if (shouldFail) {
|
|
70
|
-
return yield* Effect.fail(
|
|
70
|
+
return yield* Effect.fail(
|
|
71
|
+
new Error("NetworkError: Connection timeout"),
|
|
72
|
+
);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
// Track success
|
|
74
76
|
yield* obs.metrics.uploadSuccessTotal.pipe(
|
|
75
|
-
Metric.tagged("upload_id", "test-upload-123")
|
|
77
|
+
Metric.tagged("upload_id", "test-upload-123"),
|
|
76
78
|
)(Effect.succeed(1));
|
|
77
79
|
|
|
78
80
|
return { uploadId: "test-upload-123", key: "test-file.jpg" };
|
|
@@ -83,7 +85,7 @@ const simulateUpload = (fileSize: number, shouldFail: boolean) =>
|
|
|
83
85
|
withStorageSpan("uploadFile", testStorageType, {
|
|
84
86
|
"file.size": fileSize,
|
|
85
87
|
"upload.id": "test-upload-123",
|
|
86
|
-
})
|
|
88
|
+
}),
|
|
87
89
|
);
|
|
88
90
|
|
|
89
91
|
// Log completion
|
|
@@ -116,7 +118,9 @@ const testErrorClassification = Effect.gen(function* () {
|
|
|
116
118
|
for (const { error, expected } of testErrors) {
|
|
117
119
|
const category = classifyStorageError(error);
|
|
118
120
|
const status = category === expected ? "✅" : "❌";
|
|
119
|
-
console.log(
|
|
121
|
+
console.log(
|
|
122
|
+
` ${status} ${error.code} -> ${category} (expected: ${expected})`,
|
|
123
|
+
);
|
|
120
124
|
}
|
|
121
125
|
});
|
|
122
126
|
|
|
@@ -132,13 +136,10 @@ const testErrorTracking = Effect.gen(function* () {
|
|
|
132
136
|
const error = new Error("ECONNRESET: Connection reset by peer");
|
|
133
137
|
(error as any).code = "ECONNRESET";
|
|
134
138
|
|
|
135
|
-
yield* trackStorageError(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
error,
|
|
140
|
-
{ upload_id: "test-upload-456", part_number: 1 }
|
|
141
|
-
);
|
|
139
|
+
yield* trackStorageError(testStorageType, obs.metrics, "uploadPart", error, {
|
|
140
|
+
upload_id: "test-upload-456",
|
|
141
|
+
part_number: 1,
|
|
142
|
+
});
|
|
142
143
|
|
|
143
144
|
console.log(" ✅ Error tracked with metrics and logs");
|
|
144
145
|
});
|
|
@@ -177,7 +178,7 @@ const testFailedUpload = Effect.gen(function* () {
|
|
|
177
178
|
obs.metrics,
|
|
178
179
|
"uploadFile",
|
|
179
180
|
error,
|
|
180
|
-
{ upload_id: "test-upload-789" }
|
|
181
|
+
{ upload_id: "test-upload-789" },
|
|
181
182
|
);
|
|
182
183
|
|
|
183
184
|
console.log(" ✅ Error handled and tracked successfully");
|
|
@@ -198,7 +199,9 @@ const testMetricsSnapshot = Effect.gen(function* () {
|
|
|
198
199
|
|
|
199
200
|
// Display some metrics
|
|
200
201
|
for (const metric of snapshot.slice(0, 5)) {
|
|
201
|
-
console.log(
|
|
202
|
+
console.log(
|
|
203
|
+
` - ${metric.metricKey.name}: ${JSON.stringify(metric.metricState)}`,
|
|
204
|
+
);
|
|
202
205
|
}
|
|
203
206
|
});
|
|
204
207
|
|
package/src/upload/index.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Upload observability exports
|
|
2
|
-
|
|
3
|
-
export * from "./
|
|
2
|
+
|
|
3
|
+
export * from "./errors.js";
|
|
4
4
|
export {
|
|
5
|
+
getUploadMetrics,
|
|
5
6
|
makeUploadObservabilityLive,
|
|
6
7
|
UploadObservabilityLive,
|
|
7
|
-
getUploadMetrics,
|
|
8
|
-
withUploadDuration,
|
|
9
8
|
withChunkDuration,
|
|
9
|
+
withUploadDuration,
|
|
10
10
|
} from "./layers.js";
|
|
11
|
-
export * from "./
|
|
11
|
+
export * from "./metrics.js";
|
|
12
12
|
export * from "./testing.js";
|
|
13
|
+
export * from "./tracing.js";
|