@qnsp/storage-sdk 0.3.0 → 0.3.2
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/LICENSE +21 -7
- package/README.md +22 -72
- package/dist/index.d.ts +133 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +273 -4
- package/dist/index.js.map +1 -1
- package/dist/sdk-package-version.d.ts +2 -0
- package/dist/sdk-package-version.d.ts.map +1 -0
- package/dist/sdk-package-version.js +6 -0
- package/dist/sdk-package-version.js.map +1 -0
- package/dist/types.d.ts +474 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -39
- package/src/event-envelope.ts +0 -58
- package/src/events.ts +0 -190
- package/src/index.test.ts +0 -473
- package/src/index.ts +0 -874
- package/src/observability.ts +0 -172
- package/src/validation.ts +0 -21
- package/tsconfig.build.json +0 -10
- package/tsconfig.json +0 -10
- package/tsconfig.tsbuildinfo +0 -1
package/src/observability.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import type { Attributes } from "@opentelemetry/api";
|
|
2
|
-
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
3
|
-
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
4
|
-
import type { MetricReader } from "@opentelemetry/sdk-metrics";
|
|
5
|
-
import {
|
|
6
|
-
ConsoleMetricExporter,
|
|
7
|
-
MeterProvider,
|
|
8
|
-
PeriodicExportingMetricReader,
|
|
9
|
-
} from "@opentelemetry/sdk-metrics";
|
|
10
|
-
|
|
11
|
-
type TelemetryResourceOptions = {
|
|
12
|
-
readonly serviceName: string;
|
|
13
|
-
readonly serviceVersion?: string;
|
|
14
|
-
readonly environment?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function createMeterProvider(
|
|
18
|
-
options: TelemetryResourceOptions,
|
|
19
|
-
readers: readonly MetricReader[] = [],
|
|
20
|
-
): MeterProvider {
|
|
21
|
-
const attributes: Record<string, string | number | boolean> = {
|
|
22
|
-
"service.name": options.serviceName,
|
|
23
|
-
...(options.serviceVersion ? { "service.version": options.serviceVersion } : {}),
|
|
24
|
-
"deployment.environment": options.environment ?? "development",
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return new MeterProvider({
|
|
28
|
-
resource: resourceFromAttributes(attributes),
|
|
29
|
-
readers: [...readers],
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function createCounter(
|
|
34
|
-
provider: MeterProvider,
|
|
35
|
-
name: string,
|
|
36
|
-
options?: Parameters<ReturnType<MeterProvider["getMeter"]>["createCounter"]>[1],
|
|
37
|
-
) {
|
|
38
|
-
return provider.getMeter("qnsp").createCounter(name, options);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function createHistogram(
|
|
42
|
-
provider: MeterProvider,
|
|
43
|
-
name: string,
|
|
44
|
-
options?: Parameters<ReturnType<MeterProvider["getMeter"]>["createHistogram"]>[1],
|
|
45
|
-
) {
|
|
46
|
-
return provider.getMeter("qnsp").createHistogram(name, options);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface StorageClientTelemetryConfig {
|
|
50
|
-
readonly serviceName: string;
|
|
51
|
-
readonly serviceVersion?: string;
|
|
52
|
-
readonly environment?: string;
|
|
53
|
-
readonly otlpEndpoint?: string;
|
|
54
|
-
readonly metricsIntervalMs?: number;
|
|
55
|
-
readonly metricsTimeoutMs?: number;
|
|
56
|
-
readonly exporterFactory?: () => MetricReader;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface StorageClientTelemetryEvent {
|
|
60
|
-
readonly operation: string;
|
|
61
|
-
readonly method: string;
|
|
62
|
-
readonly route: string;
|
|
63
|
-
readonly status: "ok" | "error";
|
|
64
|
-
readonly durationMs: number;
|
|
65
|
-
readonly httpStatus?: number;
|
|
66
|
-
readonly target?: string;
|
|
67
|
-
readonly error?: string;
|
|
68
|
-
readonly bytesSent?: number;
|
|
69
|
-
readonly bytesReceived?: number;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface StorageClientTelemetry {
|
|
73
|
-
record(event: StorageClientTelemetryEvent): void;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function createStorageClientTelemetry(
|
|
77
|
-
config: StorageClientTelemetryConfig,
|
|
78
|
-
): StorageClientTelemetry {
|
|
79
|
-
const interval = config.metricsIntervalMs ?? 60_000;
|
|
80
|
-
const timeout = config.metricsTimeoutMs ?? 15_000;
|
|
81
|
-
const readers: MetricReader[] = [];
|
|
82
|
-
|
|
83
|
-
if (typeof config.exporterFactory === "function") {
|
|
84
|
-
readers.push(config.exporterFactory());
|
|
85
|
-
} else if (config.otlpEndpoint) {
|
|
86
|
-
readers.push(
|
|
87
|
-
new PeriodicExportingMetricReader({
|
|
88
|
-
exporter: new OTLPMetricExporter({
|
|
89
|
-
url: config.otlpEndpoint,
|
|
90
|
-
}),
|
|
91
|
-
exportIntervalMillis: interval,
|
|
92
|
-
exportTimeoutMillis: timeout,
|
|
93
|
-
}),
|
|
94
|
-
);
|
|
95
|
-
} else if (process.env["NODE_ENV"] !== "test") {
|
|
96
|
-
readers.push(
|
|
97
|
-
new PeriodicExportingMetricReader({
|
|
98
|
-
exporter: new ConsoleMetricExporter(),
|
|
99
|
-
exportIntervalMillis: interval,
|
|
100
|
-
exportTimeoutMillis: timeout,
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const provider = createMeterProvider(
|
|
106
|
-
{
|
|
107
|
-
serviceName: config.serviceName,
|
|
108
|
-
serviceVersion: config.serviceVersion ?? "0.0.0",
|
|
109
|
-
environment: config.environment ?? process.env["NODE_ENV"] ?? "development",
|
|
110
|
-
},
|
|
111
|
-
readers,
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
const requestCounter = createCounter(provider, "storage_sdk_requests_total", {
|
|
115
|
-
description: "Count of Storage SDK HTTP requests",
|
|
116
|
-
});
|
|
117
|
-
const failureCounter = createCounter(provider, "storage_sdk_request_failures_total", {
|
|
118
|
-
description: "Count of failed Storage SDK HTTP requests",
|
|
119
|
-
});
|
|
120
|
-
const durationHistogram = createHistogram(provider, "storage_sdk_request_duration_ms", {
|
|
121
|
-
description: "Latency of Storage SDK HTTP requests",
|
|
122
|
-
unit: "ms",
|
|
123
|
-
});
|
|
124
|
-
const bytesCounter = createCounter(provider, "storage_sdk_bytes_total", {
|
|
125
|
-
description: "Bytes sent or received by the Storage SDK",
|
|
126
|
-
unit: "By",
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
record(event) {
|
|
131
|
-
const baseAttributes: Attributes = {
|
|
132
|
-
service: config.serviceName,
|
|
133
|
-
operation: event.operation,
|
|
134
|
-
method: event.method,
|
|
135
|
-
route: event.route,
|
|
136
|
-
target: event.target ?? event.route,
|
|
137
|
-
status: event.status,
|
|
138
|
-
...(event.httpStatus ? { http_status: event.httpStatus } : {}),
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
requestCounter.add(1, baseAttributes);
|
|
142
|
-
durationHistogram.record(event.durationMs, baseAttributes);
|
|
143
|
-
|
|
144
|
-
if (event.status === "error") {
|
|
145
|
-
failureCounter.add(1, {
|
|
146
|
-
...baseAttributes,
|
|
147
|
-
error: event.error ?? "unknown",
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (typeof event.bytesSent === "number") {
|
|
152
|
-
bytesCounter.add(event.bytesSent, {
|
|
153
|
-
...baseAttributes,
|
|
154
|
-
direction: "sent",
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (typeof event.bytesReceived === "number") {
|
|
159
|
-
bytesCounter.add(event.bytesReceived, {
|
|
160
|
-
...baseAttributes,
|
|
161
|
-
direction: "received",
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function isStorageClientTelemetry(
|
|
169
|
-
value: StorageClientTelemetry | StorageClientTelemetryConfig,
|
|
170
|
-
): value is StorageClientTelemetry {
|
|
171
|
-
return typeof (value as StorageClientTelemetry)?.record === "function";
|
|
172
|
-
}
|
package/src/validation.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Validation schemas for storage-sdk inputs
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export const uuidSchema = z.string().uuid("Invalid UUID format");
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Validates a UUID string
|
|
11
|
-
*/
|
|
12
|
-
export function validateUUID(value: string, fieldName: string): void {
|
|
13
|
-
try {
|
|
14
|
-
uuidSchema.parse(value);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
if (error instanceof z.ZodError) {
|
|
17
|
-
throw new Error(`Invalid ${fieldName}: ${error.issues[0]?.message ?? "Invalid format"}`);
|
|
18
|
-
}
|
|
19
|
-
throw error;
|
|
20
|
-
}
|
|
21
|
-
}
|
package/tsconfig.build.json
DELETED