@uploadista/observability 0.0.18-beta.8 → 0.0.18
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 +1048 -74
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1096 -122
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -4
- package/src/core/exporters.ts +475 -0
- package/src/core/full-observability.ts +313 -0
- package/src/core/index.ts +5 -0
- package/src/core/logs-sdk.ts +441 -0
- package/src/core/metrics-sdk.ts +279 -0
- package/src/core/tracing.ts +417 -1
- package/src/core/types.ts +44 -0
- package/src/flow/layers.ts +9 -1
- package/src/flow/metrics.ts +22 -10
- package/src/flow/tracing.ts +74 -2
- package/src/index.ts +0 -2
- package/tests/core/exporters.test.ts +235 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Full Observability SDK Layers for Uploadista SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides combined Effect Layers that enable all three pillars
|
|
5
|
+
* of observability (Traces, Metrics, Logs) with a single import.
|
|
6
|
+
*
|
|
7
|
+
* Configuration is done via standard OpenTelemetry environment variables:
|
|
8
|
+
* - OTEL_EXPORTER_OTLP_ENDPOINT: Base endpoint URL (default: http://localhost:4318)
|
|
9
|
+
* - OTEL_EXPORTER_OTLP_HEADERS: Headers for authentication
|
|
10
|
+
* - OTEL_SERVICE_NAME: Service name (default: uploadista)
|
|
11
|
+
* - UPLOADISTA_OBSERVABILITY_ENABLED: Set to "false" to disable (default: true)
|
|
12
|
+
*
|
|
13
|
+
* @module core/full-observability
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { Effect, Layer } from "effect";
|
|
17
|
+
import type { MetricsSdkConfig } from "./exporters.js";
|
|
18
|
+
import { getServiceName } from "./exporters.js";
|
|
19
|
+
import {
|
|
20
|
+
createOtlpLogsNodeSdkLayer,
|
|
21
|
+
createOtlpLogsWebSdkLayer,
|
|
22
|
+
createOtlpLogsWorkersSdkLayer,
|
|
23
|
+
type LogsLayerConfig,
|
|
24
|
+
OtlpLogsNodeSdkLive,
|
|
25
|
+
OtlpLogsWebSdkLive,
|
|
26
|
+
OtlpLogsWorkersSdkLive,
|
|
27
|
+
} from "./logs-sdk.js";
|
|
28
|
+
import {
|
|
29
|
+
createOtlpMetricsNodeSdkLayer,
|
|
30
|
+
createOtlpMetricsWebSdkLayer,
|
|
31
|
+
createOtlpMetricsWorkersSdkLayer,
|
|
32
|
+
OtlpMetricsNodeSdkLive,
|
|
33
|
+
OtlpMetricsWebSdkLive,
|
|
34
|
+
OtlpMetricsWorkersSdkLive,
|
|
35
|
+
} from "./metrics-sdk.js";
|
|
36
|
+
import {
|
|
37
|
+
createOtlpNodeSdkLayer,
|
|
38
|
+
createOtlpWebSdkLayer,
|
|
39
|
+
createOtlpWorkersSdkLayer,
|
|
40
|
+
OtlpNodeSdkLive,
|
|
41
|
+
type OtlpSdkConfig,
|
|
42
|
+
OtlpWebSdkLive,
|
|
43
|
+
OtlpWorkersSdkLive,
|
|
44
|
+
} from "./tracing.js";
|
|
45
|
+
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// Combined Configuration
|
|
48
|
+
// ============================================================================
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Configuration for full observability SDK.
|
|
52
|
+
*/
|
|
53
|
+
export interface FullObservabilityConfig {
|
|
54
|
+
/** Service name for all telemetry. Defaults to OTEL_SERVICE_NAME or "uploadista" */
|
|
55
|
+
serviceName?: string;
|
|
56
|
+
/** Additional resource attributes */
|
|
57
|
+
resourceAttributes?: Record<string, string>;
|
|
58
|
+
/** Traces-specific configuration */
|
|
59
|
+
traces?: Omit<OtlpSdkConfig, "serviceName" | "resourceAttributes">;
|
|
60
|
+
/** Metrics-specific configuration */
|
|
61
|
+
metrics?: Omit<MetricsSdkConfig, "serviceName">;
|
|
62
|
+
/** Logs-specific configuration */
|
|
63
|
+
logs?: Omit<LogsLayerConfig, "serviceName">;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ============================================================================
|
|
67
|
+
// Combined SDK Layers
|
|
68
|
+
// ============================================================================
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Node.js Full Observability SDK Layer.
|
|
72
|
+
*
|
|
73
|
+
* Combines traces, metrics, and logs export into a single layer.
|
|
74
|
+
* Use this for easy setup of complete observability.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* import { OtlpFullObservabilityNodeSdkLive } from "@uploadista/observability";
|
|
79
|
+
* import { Effect } from "effect";
|
|
80
|
+
*
|
|
81
|
+
* const program = Effect.gen(function* () {
|
|
82
|
+
* // All three pillars are now active:
|
|
83
|
+
* // - Traces via Effect.withSpan
|
|
84
|
+
* // - Metrics via OtelMeter
|
|
85
|
+
* // - Logs via OtelLogger
|
|
86
|
+
* yield* Effect.log("This goes to OTLP!");
|
|
87
|
+
* }).pipe(Effect.provide(OtlpFullObservabilityNodeSdkLive));
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export const OtlpFullObservabilityNodeSdkLive = Layer.mergeAll(
|
|
91
|
+
OtlpNodeSdkLive,
|
|
92
|
+
OtlpMetricsNodeSdkLive,
|
|
93
|
+
OtlpLogsNodeSdkLive,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Creates a customized Full Observability Node.js SDK Layer.
|
|
98
|
+
*
|
|
99
|
+
* @param config - Configuration for all three pillars
|
|
100
|
+
* @returns Combined Effect Layer
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const customObservability = createOtlpFullObservabilityNodeSdkLayer({
|
|
105
|
+
* serviceName: "my-upload-service",
|
|
106
|
+
* traces: { maxQueueSize: 1024 },
|
|
107
|
+
* metrics: { exportIntervalMillis: 30000 },
|
|
108
|
+
* logs: { minSeverity: SeverityNumber.WARN },
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export function createOtlpFullObservabilityNodeSdkLayer(
|
|
113
|
+
config: FullObservabilityConfig = {},
|
|
114
|
+
) {
|
|
115
|
+
const serviceName = config.serviceName ?? getServiceName("uploadista");
|
|
116
|
+
const resourceAttributes = config.resourceAttributes;
|
|
117
|
+
|
|
118
|
+
return Layer.mergeAll(
|
|
119
|
+
createOtlpNodeSdkLayer({
|
|
120
|
+
serviceName,
|
|
121
|
+
resourceAttributes,
|
|
122
|
+
...config.traces,
|
|
123
|
+
}),
|
|
124
|
+
createOtlpMetricsNodeSdkLayer({
|
|
125
|
+
serviceName,
|
|
126
|
+
...config.metrics,
|
|
127
|
+
}),
|
|
128
|
+
createOtlpLogsNodeSdkLayer({
|
|
129
|
+
serviceName,
|
|
130
|
+
...config.logs,
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Browser Full Observability SDK Layer.
|
|
137
|
+
*
|
|
138
|
+
* Combines traces, metrics, and logs export for browser environments.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* import { OtlpFullObservabilityWebSdkLive } from "@uploadista/observability";
|
|
143
|
+
*
|
|
144
|
+
* const program = myEffect.pipe(Effect.provide(OtlpFullObservabilityWebSdkLive));
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export const OtlpFullObservabilityWebSdkLive = Layer.mergeAll(
|
|
148
|
+
OtlpWebSdkLive,
|
|
149
|
+
OtlpMetricsWebSdkLive,
|
|
150
|
+
OtlpLogsWebSdkLive,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Creates a customized Full Observability Web SDK Layer.
|
|
155
|
+
*
|
|
156
|
+
* @param config - Configuration for all three pillars
|
|
157
|
+
* @returns Combined Effect Layer for browser environments
|
|
158
|
+
*/
|
|
159
|
+
export function createOtlpFullObservabilityWebSdkLayer(
|
|
160
|
+
config: FullObservabilityConfig = {},
|
|
161
|
+
) {
|
|
162
|
+
const serviceName = config.serviceName ?? getServiceName("uploadista");
|
|
163
|
+
const resourceAttributes = config.resourceAttributes;
|
|
164
|
+
|
|
165
|
+
return Layer.mergeAll(
|
|
166
|
+
createOtlpWebSdkLayer({
|
|
167
|
+
serviceName,
|
|
168
|
+
resourceAttributes,
|
|
169
|
+
...config.traces,
|
|
170
|
+
}),
|
|
171
|
+
createOtlpMetricsWebSdkLayer({
|
|
172
|
+
serviceName,
|
|
173
|
+
...config.metrics,
|
|
174
|
+
}),
|
|
175
|
+
createOtlpLogsWebSdkLayer({
|
|
176
|
+
serviceName,
|
|
177
|
+
...config.logs,
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Cloudflare Workers Full Observability SDK Layer.
|
|
184
|
+
*
|
|
185
|
+
* Combines traces, metrics, and logs export for Workers environments.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* import { OtlpFullObservabilityWorkersSdkLive } from "@uploadista/observability";
|
|
190
|
+
*
|
|
191
|
+
* export default {
|
|
192
|
+
* async fetch(request, env) {
|
|
193
|
+
* const program = handleRequest(request).pipe(
|
|
194
|
+
* Effect.provide(OtlpFullObservabilityWorkersSdkLive)
|
|
195
|
+
* );
|
|
196
|
+
* return Effect.runPromise(program);
|
|
197
|
+
* }
|
|
198
|
+
* };
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export const OtlpFullObservabilityWorkersSdkLive = Layer.mergeAll(
|
|
202
|
+
OtlpWorkersSdkLive,
|
|
203
|
+
OtlpMetricsWorkersSdkLive,
|
|
204
|
+
OtlpLogsWorkersSdkLive,
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Creates a customized Full Observability Workers SDK Layer.
|
|
209
|
+
*
|
|
210
|
+
* @param config - Configuration for all three pillars
|
|
211
|
+
* @returns Combined Effect Layer for Cloudflare Workers
|
|
212
|
+
*/
|
|
213
|
+
export function createOtlpFullObservabilityWorkersSdkLayer(
|
|
214
|
+
config: FullObservabilityConfig = {},
|
|
215
|
+
) {
|
|
216
|
+
const serviceName =
|
|
217
|
+
config.serviceName ?? getServiceName("uploadista-workers");
|
|
218
|
+
const resourceAttributes = config.resourceAttributes;
|
|
219
|
+
|
|
220
|
+
return Layer.mergeAll(
|
|
221
|
+
createOtlpWorkersSdkLayer({
|
|
222
|
+
serviceName,
|
|
223
|
+
resourceAttributes,
|
|
224
|
+
...config.traces,
|
|
225
|
+
}),
|
|
226
|
+
createOtlpMetricsWorkersSdkLayer({
|
|
227
|
+
serviceName,
|
|
228
|
+
...config.metrics,
|
|
229
|
+
}),
|
|
230
|
+
createOtlpLogsWorkersSdkLayer({
|
|
231
|
+
serviceName,
|
|
232
|
+
...config.logs,
|
|
233
|
+
}),
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ============================================================================
|
|
238
|
+
// Auto-Detection Layer
|
|
239
|
+
// ============================================================================
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Runtime environment types.
|
|
243
|
+
*/
|
|
244
|
+
export type Environment = "node" | "web" | "workers";
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Detects the current runtime environment.
|
|
248
|
+
*
|
|
249
|
+
* @returns The detected environment
|
|
250
|
+
*/
|
|
251
|
+
export function detectEnvironment(): Environment {
|
|
252
|
+
// Check for Node.js
|
|
253
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
254
|
+
return "node";
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Check for browser (has navigator and window)
|
|
258
|
+
if (typeof navigator !== "undefined" && typeof window !== "undefined") {
|
|
259
|
+
return "web";
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Default to workers (Cloudflare Workers, Deno Deploy, etc.)
|
|
263
|
+
return "workers";
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Auto-detecting Full Observability SDK Layer.
|
|
268
|
+
*
|
|
269
|
+
* Automatically selects the appropriate layer based on runtime environment.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* import { OtlpAutoSdkLive } from "@uploadista/observability";
|
|
274
|
+
*
|
|
275
|
+
* // Works in Node.js, Browser, or Workers automatically
|
|
276
|
+
* const program = myEffect.pipe(Effect.provide(OtlpAutoSdkLive));
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
export const OtlpAutoSdkLive = Layer.unwrapEffect(
|
|
280
|
+
Effect.sync(() => {
|
|
281
|
+
const env = detectEnvironment();
|
|
282
|
+
switch (env) {
|
|
283
|
+
case "node":
|
|
284
|
+
return OtlpFullObservabilityNodeSdkLive;
|
|
285
|
+
case "web":
|
|
286
|
+
return OtlpFullObservabilityWebSdkLive;
|
|
287
|
+
case "workers":
|
|
288
|
+
return OtlpFullObservabilityWorkersSdkLive;
|
|
289
|
+
}
|
|
290
|
+
}),
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Creates an auto-detecting Full Observability SDK Layer with custom config.
|
|
295
|
+
*
|
|
296
|
+
* @param config - Configuration for all three pillars
|
|
297
|
+
* @returns Auto-detecting combined Effect Layer
|
|
298
|
+
*/
|
|
299
|
+
export function createOtlpAutoSdkLayer(config: FullObservabilityConfig = {}) {
|
|
300
|
+
return Layer.unwrapEffect(
|
|
301
|
+
Effect.sync(() => {
|
|
302
|
+
const env = detectEnvironment();
|
|
303
|
+
switch (env) {
|
|
304
|
+
case "node":
|
|
305
|
+
return createOtlpFullObservabilityNodeSdkLayer(config);
|
|
306
|
+
case "web":
|
|
307
|
+
return createOtlpFullObservabilityWebSdkLayer(config);
|
|
308
|
+
case "workers":
|
|
309
|
+
return createOtlpFullObservabilityWorkersSdkLayer(config);
|
|
310
|
+
}
|
|
311
|
+
}),
|
|
312
|
+
);
|
|
313
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
// Core observability exports
|
|
2
2
|
|
|
3
3
|
export * from "./errors.js";
|
|
4
|
+
export * from "./exporters.js";
|
|
5
|
+
export * from "./full-observability.js";
|
|
4
6
|
export * from "./layers.js";
|
|
5
7
|
export * from "./logging.js";
|
|
8
|
+
export * from "./logs-sdk.js";
|
|
6
9
|
export * from "./metrics.js";
|
|
10
|
+
export * from "./metrics-sdk.js";
|
|
7
11
|
export * from "./testing.js";
|
|
8
12
|
export * from "./tracing.js";
|
|
13
|
+
export * from "./types.js";
|
|
9
14
|
export * from "./utilities.js";
|