@uploadista/observability 0.0.18-beta.9 → 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 +1070 -96
- 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 +8 -3
- 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,235 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
createOtlpMetricExporter,
|
|
4
|
+
createOtlpTraceExporter,
|
|
5
|
+
getOtlpEndpoint,
|
|
6
|
+
getServiceName,
|
|
7
|
+
isOtlpExportEnabled,
|
|
8
|
+
parseOtlpHeaders,
|
|
9
|
+
parseResourceAttributes,
|
|
10
|
+
} from "../../src/core/exporters.js";
|
|
11
|
+
|
|
12
|
+
describe("OTLP Exporter Configuration", () => {
|
|
13
|
+
// Store original env vars to restore after tests
|
|
14
|
+
const originalEnv: Record<string, string | undefined> = {};
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
// Save original values
|
|
18
|
+
originalEnv.OTEL_EXPORTER_OTLP_ENDPOINT =
|
|
19
|
+
process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
20
|
+
originalEnv.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT =
|
|
21
|
+
process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;
|
|
22
|
+
originalEnv.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT =
|
|
23
|
+
process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT;
|
|
24
|
+
originalEnv.OTEL_EXPORTER_OTLP_HEADERS =
|
|
25
|
+
process.env.OTEL_EXPORTER_OTLP_HEADERS;
|
|
26
|
+
originalEnv.OTEL_SERVICE_NAME = process.env.OTEL_SERVICE_NAME;
|
|
27
|
+
originalEnv.OTEL_RESOURCE_ATTRIBUTES = process.env.OTEL_RESOURCE_ATTRIBUTES;
|
|
28
|
+
originalEnv.UPLOADISTA_OBSERVABILITY_ENABLED =
|
|
29
|
+
process.env.UPLOADISTA_OBSERVABILITY_ENABLED;
|
|
30
|
+
|
|
31
|
+
// Clear env vars for clean test state
|
|
32
|
+
delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
33
|
+
delete process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;
|
|
34
|
+
delete process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT;
|
|
35
|
+
delete process.env.OTEL_EXPORTER_OTLP_HEADERS;
|
|
36
|
+
delete process.env.OTEL_SERVICE_NAME;
|
|
37
|
+
delete process.env.OTEL_RESOURCE_ATTRIBUTES;
|
|
38
|
+
delete process.env.UPLOADISTA_OBSERVABILITY_ENABLED;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
// Restore original values
|
|
43
|
+
for (const [key, value] of Object.entries(originalEnv)) {
|
|
44
|
+
if (value === undefined) {
|
|
45
|
+
delete process.env[key];
|
|
46
|
+
} else {
|
|
47
|
+
process.env[key] = value;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("parseOtlpHeaders", () => {
|
|
53
|
+
it("should return undefined when env var is not set", () => {
|
|
54
|
+
expect(parseOtlpHeaders()).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should parse single header", () => {
|
|
58
|
+
process.env.OTEL_EXPORTER_OTLP_HEADERS = "Authorization=Basic abc123";
|
|
59
|
+
expect(parseOtlpHeaders()).toEqual({
|
|
60
|
+
Authorization: "Basic abc123",
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should parse multiple headers", () => {
|
|
65
|
+
process.env.OTEL_EXPORTER_OTLP_HEADERS =
|
|
66
|
+
"Authorization=Bearer token,X-Custom=value";
|
|
67
|
+
expect(parseOtlpHeaders()).toEqual({
|
|
68
|
+
Authorization: "Bearer token",
|
|
69
|
+
"X-Custom": "value",
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should handle headers with = in value", () => {
|
|
74
|
+
process.env.OTEL_EXPORTER_OTLP_HEADERS = "Authorization=Basic a=b=c";
|
|
75
|
+
expect(parseOtlpHeaders()).toEqual({
|
|
76
|
+
Authorization: "Basic a=b=c",
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should trim whitespace", () => {
|
|
81
|
+
process.env.OTEL_EXPORTER_OTLP_HEADERS =
|
|
82
|
+
" Authorization = Bearer token , X-Custom = value ";
|
|
83
|
+
expect(parseOtlpHeaders()).toEqual({
|
|
84
|
+
Authorization: "Bearer token",
|
|
85
|
+
"X-Custom": "value",
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("getOtlpEndpoint", () => {
|
|
91
|
+
it("should return default endpoint when no env vars set", () => {
|
|
92
|
+
expect(getOtlpEndpoint("traces")).toBe("http://localhost:4318");
|
|
93
|
+
expect(getOtlpEndpoint("metrics")).toBe("http://localhost:4318");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should use config endpoint when provided", () => {
|
|
97
|
+
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "http://env-endpoint:4318";
|
|
98
|
+
expect(getOtlpEndpoint("traces", "http://config-endpoint:4318")).toBe(
|
|
99
|
+
"http://config-endpoint:4318",
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("should use signal-specific endpoint over base endpoint", () => {
|
|
104
|
+
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "http://base:4318";
|
|
105
|
+
process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = "http://traces:4318";
|
|
106
|
+
expect(getOtlpEndpoint("traces")).toBe("http://traces:4318");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should use base endpoint when signal-specific not set", () => {
|
|
110
|
+
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "http://base:4318";
|
|
111
|
+
expect(getOtlpEndpoint("traces")).toBe("http://base:4318");
|
|
112
|
+
expect(getOtlpEndpoint("metrics")).toBe("http://base:4318");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("should use metrics-specific endpoint", () => {
|
|
116
|
+
process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = "http://metrics:4318";
|
|
117
|
+
expect(getOtlpEndpoint("metrics")).toBe("http://metrics:4318");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("isOtlpExportEnabled", () => {
|
|
122
|
+
it("should return true by default", () => {
|
|
123
|
+
expect(isOtlpExportEnabled()).toBe(true);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should return true when set to true", () => {
|
|
127
|
+
process.env.UPLOADISTA_OBSERVABILITY_ENABLED = "true";
|
|
128
|
+
expect(isOtlpExportEnabled()).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("should return false when set to false", () => {
|
|
132
|
+
process.env.UPLOADISTA_OBSERVABILITY_ENABLED = "false";
|
|
133
|
+
expect(isOtlpExportEnabled()).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("should return false when set to FALSE (case insensitive)", () => {
|
|
137
|
+
process.env.UPLOADISTA_OBSERVABILITY_ENABLED = "FALSE";
|
|
138
|
+
expect(isOtlpExportEnabled()).toBe(false);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("should return false when set to 0", () => {
|
|
142
|
+
process.env.UPLOADISTA_OBSERVABILITY_ENABLED = "0";
|
|
143
|
+
expect(isOtlpExportEnabled()).toBe(false);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should return true for any other value", () => {
|
|
147
|
+
process.env.UPLOADISTA_OBSERVABILITY_ENABLED = "yes";
|
|
148
|
+
expect(isOtlpExportEnabled()).toBe(true);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe("getServiceName", () => {
|
|
153
|
+
it("should return default when env var not set", () => {
|
|
154
|
+
expect(getServiceName()).toBe("uploadista");
|
|
155
|
+
expect(getServiceName("custom-default")).toBe("custom-default");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("should return env var value when set", () => {
|
|
159
|
+
process.env.OTEL_SERVICE_NAME = "my-service";
|
|
160
|
+
expect(getServiceName()).toBe("my-service");
|
|
161
|
+
expect(getServiceName("custom-default")).toBe("my-service");
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe("parseResourceAttributes", () => {
|
|
166
|
+
it("should return empty object when env var not set", () => {
|
|
167
|
+
expect(parseResourceAttributes()).toEqual({});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("should parse single attribute", () => {
|
|
171
|
+
process.env.OTEL_RESOURCE_ATTRIBUTES = "tenant.id=abc123";
|
|
172
|
+
expect(parseResourceAttributes()).toEqual({
|
|
173
|
+
"tenant.id": "abc123",
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("should parse multiple attributes", () => {
|
|
178
|
+
process.env.OTEL_RESOURCE_ATTRIBUTES =
|
|
179
|
+
"tenant.id=abc123,deployment.environment=production";
|
|
180
|
+
expect(parseResourceAttributes()).toEqual({
|
|
181
|
+
"tenant.id": "abc123",
|
|
182
|
+
"deployment.environment": "production",
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("should handle values with = character", () => {
|
|
187
|
+
process.env.OTEL_RESOURCE_ATTRIBUTES = "config=a=b=c";
|
|
188
|
+
expect(parseResourceAttributes()).toEqual({
|
|
189
|
+
config: "a=b=c",
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("createOtlpTraceExporter", () => {
|
|
195
|
+
it("should create exporter with default config", () => {
|
|
196
|
+
const exporter = createOtlpTraceExporter();
|
|
197
|
+
expect(exporter).toBeDefined();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("should create exporter with custom endpoint", () => {
|
|
201
|
+
const exporter = createOtlpTraceExporter({
|
|
202
|
+
endpoint: "http://custom:4318",
|
|
203
|
+
});
|
|
204
|
+
expect(exporter).toBeDefined();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("should create exporter with custom headers", () => {
|
|
208
|
+
const exporter = createOtlpTraceExporter({
|
|
209
|
+
headers: { Authorization: "Bearer token" },
|
|
210
|
+
});
|
|
211
|
+
expect(exporter).toBeDefined();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("should create exporter with custom timeout", () => {
|
|
215
|
+
const exporter = createOtlpTraceExporter({
|
|
216
|
+
timeoutMillis: 10000,
|
|
217
|
+
});
|
|
218
|
+
expect(exporter).toBeDefined();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe("createOtlpMetricExporter", () => {
|
|
223
|
+
it("should create exporter with default config", () => {
|
|
224
|
+
const exporter = createOtlpMetricExporter();
|
|
225
|
+
expect(exporter).toBeDefined();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("should create exporter with custom endpoint", () => {
|
|
229
|
+
const exporter = createOtlpMetricExporter({
|
|
230
|
+
endpoint: "http://custom:4318",
|
|
231
|
+
});
|
|
232
|
+
expect(exporter).toBeDefined();
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
});
|