@superblocksteam/telemetry 2.0.83-next.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/LICENSE.txt +87 -0
- package/README.md +155 -0
- package/dist/browser/index.d.ts +8 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +19 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/init.d.ts +75 -0
- package/dist/browser/init.d.ts.map +1 -0
- package/dist/browser/init.js +169 -0
- package/dist/browser/init.js.map +1 -0
- package/dist/browser/resilient-exporter.d.ts +43 -0
- package/dist/browser/resilient-exporter.d.ts.map +1 -0
- package/dist/browser/resilient-exporter.js +88 -0
- package/dist/browser/resilient-exporter.js.map +1 -0
- package/dist/common/contracts/tier2-traces.d.ts +75 -0
- package/dist/common/contracts/tier2-traces.d.ts.map +1 -0
- package/dist/common/contracts/tier2-traces.js +186 -0
- package/dist/common/contracts/tier2-traces.js.map +1 -0
- package/dist/common/deployment-type.d.ts +18 -0
- package/dist/common/deployment-type.d.ts.map +1 -0
- package/dist/common/deployment-type.js +30 -0
- package/dist/common/deployment-type.js.map +1 -0
- package/dist/common/guardrails.d.ts +116 -0
- package/dist/common/guardrails.d.ts.map +1 -0
- package/dist/common/guardrails.js +189 -0
- package/dist/common/guardrails.js.map +1 -0
- package/dist/common/index.d.ts +16 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +32 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/log-sanitizer.d.ts +78 -0
- package/dist/common/log-sanitizer.d.ts.map +1 -0
- package/dist/common/log-sanitizer.js +340 -0
- package/dist/common/log-sanitizer.js.map +1 -0
- package/dist/common/policy-evaluator.d.ts +103 -0
- package/dist/common/policy-evaluator.d.ts.map +1 -0
- package/dist/common/policy-evaluator.js +200 -0
- package/dist/common/policy-evaluator.js.map +1 -0
- package/dist/common/resource.d.ts +62 -0
- package/dist/common/resource.d.ts.map +1 -0
- package/dist/common/resource.js +106 -0
- package/dist/common/resource.js.map +1 -0
- package/dist/common/tier-hints.d.ts +182 -0
- package/dist/common/tier-hints.d.ts.map +1 -0
- package/dist/common/tier-hints.js +209 -0
- package/dist/common/tier-hints.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/lint/forbidden-attributes.d.ts +149 -0
- package/dist/lint/forbidden-attributes.d.ts.map +1 -0
- package/dist/lint/forbidden-attributes.js +214 -0
- package/dist/lint/forbidden-attributes.js.map +1 -0
- package/dist/lint/index.d.ts +9 -0
- package/dist/lint/index.d.ts.map +1 -0
- package/dist/lint/index.js +16 -0
- package/dist/lint/index.js.map +1 -0
- package/dist/llmobs/index.d.ts +22 -0
- package/dist/llmobs/index.d.ts.map +1 -0
- package/dist/llmobs/index.js +29 -0
- package/dist/llmobs/index.js.map +1 -0
- package/dist/llmobs/tier1-exporter.d.ts +146 -0
- package/dist/llmobs/tier1-exporter.d.ts.map +1 -0
- package/dist/llmobs/tier1-exporter.js +196 -0
- package/dist/llmobs/tier1-exporter.js.map +1 -0
- package/dist/llmobs/tier2-summarizer.d.ts +268 -0
- package/dist/llmobs/tier2-summarizer.d.ts.map +1 -0
- package/dist/llmobs/tier2-summarizer.js +650 -0
- package/dist/llmobs/tier2-summarizer.js.map +1 -0
- package/dist/node/exporters/resilient-exporter.d.ts +77 -0
- package/dist/node/exporters/resilient-exporter.d.ts.map +1 -0
- package/dist/node/exporters/resilient-exporter.js +129 -0
- package/dist/node/exporters/resilient-exporter.js.map +1 -0
- package/dist/node/index.d.ts +11 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +24 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/init.d.ts +75 -0
- package/dist/node/init.d.ts.map +1 -0
- package/dist/node/init.js +245 -0
- package/dist/node/init.js.map +1 -0
- package/dist/node/log-processor.d.ts +83 -0
- package/dist/node/log-processor.d.ts.map +1 -0
- package/dist/node/log-processor.js +266 -0
- package/dist/node/log-processor.js.map +1 -0
- package/dist/node/metrics-client.d.ts +66 -0
- package/dist/node/metrics-client.d.ts.map +1 -0
- package/dist/node/metrics-client.js +193 -0
- package/dist/node/metrics-client.js.map +1 -0
- package/dist/node/traced-socket.d.ts +76 -0
- package/dist/node/traced-socket.d.ts.map +1 -0
- package/dist/node/traced-socket.js +261 -0
- package/dist/node/traced-socket.js.map +1 -0
- package/dist/testing/in-memory-exporter.d.ts +179 -0
- package/dist/testing/in-memory-exporter.d.ts.map +1 -0
- package/dist/testing/in-memory-exporter.js +254 -0
- package/dist/testing/in-memory-exporter.js.map +1 -0
- package/dist/testing/index.d.ts +8 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +19 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/test-init.d.ts +80 -0
- package/dist/testing/test-init.d.ts.map +1 -0
- package/dist/testing/test-init.js +144 -0
- package/dist/testing/test-init.js.map +1 -0
- package/dist/types/index.d.ts +40 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/policy.d.ts +92 -0
- package/dist/types/policy.d.ts.map +1 -0
- package/dist/types/policy.js +125 -0
- package/dist/types/policy.js.map +1 -0
- package/dist-esm/browser/index.d.ts +8 -0
- package/dist-esm/browser/index.d.ts.map +1 -0
- package/dist-esm/browser/index.js +9 -0
- package/dist-esm/browser/index.js.map +1 -0
- package/dist-esm/browser/init.d.ts +75 -0
- package/dist-esm/browser/init.d.ts.map +1 -0
- package/dist-esm/browser/init.js +162 -0
- package/dist-esm/browser/init.js.map +1 -0
- package/dist-esm/browser/resilient-exporter.d.ts +43 -0
- package/dist-esm/browser/resilient-exporter.d.ts.map +1 -0
- package/dist-esm/browser/resilient-exporter.js +84 -0
- package/dist-esm/browser/resilient-exporter.js.map +1 -0
- package/dist-esm/common/contracts/tier2-traces.d.ts +75 -0
- package/dist-esm/common/contracts/tier2-traces.d.ts.map +1 -0
- package/dist-esm/common/contracts/tier2-traces.js +178 -0
- package/dist-esm/common/contracts/tier2-traces.js.map +1 -0
- package/dist-esm/common/deployment-type.d.ts +18 -0
- package/dist-esm/common/deployment-type.d.ts.map +1 -0
- package/dist-esm/common/deployment-type.js +27 -0
- package/dist-esm/common/deployment-type.js.map +1 -0
- package/dist-esm/common/guardrails.d.ts +116 -0
- package/dist-esm/common/guardrails.d.ts.map +1 -0
- package/dist-esm/common/guardrails.js +179 -0
- package/dist-esm/common/guardrails.js.map +1 -0
- package/dist-esm/common/index.d.ts +16 -0
- package/dist-esm/common/index.d.ts.map +1 -0
- package/dist-esm/common/index.js +16 -0
- package/dist-esm/common/index.js.map +1 -0
- package/dist-esm/common/log-sanitizer.d.ts +78 -0
- package/dist-esm/common/log-sanitizer.d.ts.map +1 -0
- package/dist-esm/common/log-sanitizer.js +331 -0
- package/dist-esm/common/log-sanitizer.js.map +1 -0
- package/dist-esm/common/policy-evaluator.d.ts +103 -0
- package/dist-esm/common/policy-evaluator.d.ts.map +1 -0
- package/dist-esm/common/policy-evaluator.js +196 -0
- package/dist-esm/common/policy-evaluator.js.map +1 -0
- package/dist-esm/common/resource.d.ts +62 -0
- package/dist-esm/common/resource.d.ts.map +1 -0
- package/dist-esm/common/resource.js +100 -0
- package/dist-esm/common/resource.js.map +1 -0
- package/dist-esm/common/tier-hints.d.ts +182 -0
- package/dist-esm/common/tier-hints.d.ts.map +1 -0
- package/dist-esm/common/tier-hints.js +199 -0
- package/dist-esm/common/tier-hints.js.map +1 -0
- package/dist-esm/index.d.ts +43 -0
- package/dist-esm/index.d.ts.map +1 -0
- package/dist-esm/index.js +53 -0
- package/dist-esm/index.js.map +1 -0
- package/dist-esm/lint/forbidden-attributes.d.ts +149 -0
- package/dist-esm/lint/forbidden-attributes.d.ts.map +1 -0
- package/dist-esm/lint/forbidden-attributes.js +209 -0
- package/dist-esm/lint/forbidden-attributes.js.map +1 -0
- package/dist-esm/lint/index.d.ts +9 -0
- package/dist-esm/lint/index.d.ts.map +1 -0
- package/dist-esm/lint/index.js +9 -0
- package/dist-esm/lint/index.js.map +1 -0
- package/dist-esm/llmobs/index.d.ts +22 -0
- package/dist-esm/llmobs/index.d.ts.map +1 -0
- package/dist-esm/llmobs/index.js +22 -0
- package/dist-esm/llmobs/index.js.map +1 -0
- package/dist-esm/llmobs/tier1-exporter.d.ts +146 -0
- package/dist-esm/llmobs/tier1-exporter.d.ts.map +1 -0
- package/dist-esm/llmobs/tier1-exporter.js +190 -0
- package/dist-esm/llmobs/tier1-exporter.js.map +1 -0
- package/dist-esm/llmobs/tier2-summarizer.d.ts +268 -0
- package/dist-esm/llmobs/tier2-summarizer.d.ts.map +1 -0
- package/dist-esm/llmobs/tier2-summarizer.js +646 -0
- package/dist-esm/llmobs/tier2-summarizer.js.map +1 -0
- package/dist-esm/node/exporters/resilient-exporter.d.ts +77 -0
- package/dist-esm/node/exporters/resilient-exporter.d.ts.map +1 -0
- package/dist-esm/node/exporters/resilient-exporter.js +125 -0
- package/dist-esm/node/exporters/resilient-exporter.js.map +1 -0
- package/dist-esm/node/index.d.ts +11 -0
- package/dist-esm/node/index.d.ts.map +1 -0
- package/dist-esm/node/index.js +11 -0
- package/dist-esm/node/index.js.map +1 -0
- package/dist-esm/node/init.d.ts +75 -0
- package/dist-esm/node/init.d.ts.map +1 -0
- package/dist-esm/node/init.js +239 -0
- package/dist-esm/node/init.js.map +1 -0
- package/dist-esm/node/log-processor.d.ts +83 -0
- package/dist-esm/node/log-processor.d.ts.map +1 -0
- package/dist-esm/node/log-processor.js +261 -0
- package/dist-esm/node/log-processor.js.map +1 -0
- package/dist-esm/node/metrics-client.d.ts +66 -0
- package/dist-esm/node/metrics-client.d.ts.map +1 -0
- package/dist-esm/node/metrics-client.js +189 -0
- package/dist-esm/node/metrics-client.js.map +1 -0
- package/dist-esm/node/traced-socket.d.ts +76 -0
- package/dist-esm/node/traced-socket.d.ts.map +1 -0
- package/dist-esm/node/traced-socket.js +257 -0
- package/dist-esm/node/traced-socket.js.map +1 -0
- package/dist-esm/testing/in-memory-exporter.d.ts +179 -0
- package/dist-esm/testing/in-memory-exporter.d.ts.map +1 -0
- package/dist-esm/testing/in-memory-exporter.js +248 -0
- package/dist-esm/testing/in-memory-exporter.js.map +1 -0
- package/dist-esm/testing/index.d.ts +8 -0
- package/dist-esm/testing/index.d.ts.map +1 -0
- package/dist-esm/testing/index.js +8 -0
- package/dist-esm/testing/index.js.map +1 -0
- package/dist-esm/testing/test-init.d.ts +80 -0
- package/dist-esm/testing/test-init.d.ts.map +1 -0
- package/dist-esm/testing/test-init.js +137 -0
- package/dist-esm/testing/test-init.js.map +1 -0
- package/dist-esm/types/index.d.ts +40 -0
- package/dist-esm/types/index.d.ts.map +1 -0
- package/dist-esm/types/index.js +7 -0
- package/dist-esm/types/index.js.map +1 -0
- package/dist-esm/types/policy.d.ts +92 -0
- package/dist-esm/types/policy.d.ts.map +1 -0
- package/dist-esm/types/policy.js +122 -0
- package/dist-esm/types/policy.js.map +1 -0
- package/package.json +101 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-Memory Exporters for Testing
|
|
3
|
+
*
|
|
4
|
+
* These exporters capture telemetry data in memory for assertion in tests.
|
|
5
|
+
* No external connections are made.
|
|
6
|
+
*/
|
|
7
|
+
import { ExportResultCode } from '@opentelemetry/core';
|
|
8
|
+
/**
|
|
9
|
+
* In-memory span exporter for testing.
|
|
10
|
+
* Captures all exported spans for assertion.
|
|
11
|
+
*/
|
|
12
|
+
export class InMemorySpanExporter {
|
|
13
|
+
spans = [];
|
|
14
|
+
stopped = false;
|
|
15
|
+
/**
|
|
16
|
+
* Export spans to in-memory storage.
|
|
17
|
+
*/
|
|
18
|
+
export(spans, resultCallback) {
|
|
19
|
+
if (this.stopped) {
|
|
20
|
+
resultCallback({ code: ExportResultCode.FAILED });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
this.spans.push(...spans);
|
|
24
|
+
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Shutdown the exporter.
|
|
28
|
+
*/
|
|
29
|
+
shutdown() {
|
|
30
|
+
this.stopped = true;
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Force flush (no-op for in-memory).
|
|
35
|
+
*/
|
|
36
|
+
forceFlush() {
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get all captured spans.
|
|
41
|
+
*/
|
|
42
|
+
getSpans() {
|
|
43
|
+
return [...this.spans];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the number of captured spans.
|
|
47
|
+
*/
|
|
48
|
+
getSpanCount() {
|
|
49
|
+
return this.spans.length;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Clear captured spans.
|
|
53
|
+
*/
|
|
54
|
+
reset() {
|
|
55
|
+
this.spans = [];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Find spans by name.
|
|
59
|
+
*
|
|
60
|
+
* @param name - Span name to search for
|
|
61
|
+
* @returns Matching spans
|
|
62
|
+
*/
|
|
63
|
+
findSpansByName(name) {
|
|
64
|
+
return this.spans.filter((s) => s.name === name);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Find spans by name pattern (regex).
|
|
68
|
+
*
|
|
69
|
+
* @param pattern - Regex pattern to match span names
|
|
70
|
+
* @returns Matching spans
|
|
71
|
+
*/
|
|
72
|
+
findSpansByPattern(pattern) {
|
|
73
|
+
return this.spans.filter((s) => pattern.test(s.name));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Find spans with a specific attribute value.
|
|
77
|
+
*
|
|
78
|
+
* @param key - Attribute key
|
|
79
|
+
* @param value - Attribute value (or regex for pattern matching)
|
|
80
|
+
* @returns Matching spans
|
|
81
|
+
*/
|
|
82
|
+
findSpansByAttribute(key, value) {
|
|
83
|
+
return this.spans.filter((s) => {
|
|
84
|
+
const attr = s.attributes[key];
|
|
85
|
+
if (attr === undefined)
|
|
86
|
+
return false;
|
|
87
|
+
if (value instanceof RegExp) {
|
|
88
|
+
return value.test(String(attr));
|
|
89
|
+
}
|
|
90
|
+
return attr === value;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Assert no spans have a specific attribute value.
|
|
95
|
+
* Useful for ensuring Tier 1 data doesn't leak.
|
|
96
|
+
*
|
|
97
|
+
* @param key - Attribute key
|
|
98
|
+
* @param value - Forbidden attribute value (or regex pattern)
|
|
99
|
+
* @throws Error if forbidden attribute is found
|
|
100
|
+
*/
|
|
101
|
+
assertNoAttribute(key, value) {
|
|
102
|
+
for (const span of this.spans) {
|
|
103
|
+
const attr = span.attributes[key];
|
|
104
|
+
if (attr === undefined)
|
|
105
|
+
continue;
|
|
106
|
+
const matches = value instanceof RegExp ? value.test(String(attr)) : attr === value;
|
|
107
|
+
if (matches) {
|
|
108
|
+
throw new Error(`Found forbidden attribute ${key}=${String(attr)} on span "${span.name}"`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Assert all spans have a required attribute.
|
|
114
|
+
*
|
|
115
|
+
* @param key - Attribute key
|
|
116
|
+
* @throws Error if any span is missing the attribute
|
|
117
|
+
*/
|
|
118
|
+
assertAllHaveAttribute(key) {
|
|
119
|
+
for (const span of this.spans) {
|
|
120
|
+
if (span.attributes[key] === undefined) {
|
|
121
|
+
throw new Error(`Span "${span.name}" is missing required attribute "${key}"`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get span names for debugging.
|
|
127
|
+
*/
|
|
128
|
+
getSpanNames() {
|
|
129
|
+
return this.spans.map((s) => s.name);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* In-memory metric exporter for testing.
|
|
134
|
+
*/
|
|
135
|
+
export class InMemoryMetricExporter {
|
|
136
|
+
metrics = [];
|
|
137
|
+
/**
|
|
138
|
+
* Export metrics to in-memory storage.
|
|
139
|
+
*/
|
|
140
|
+
export(metrics) {
|
|
141
|
+
this.metrics.push(...metrics);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get all captured metrics.
|
|
145
|
+
*/
|
|
146
|
+
getMetrics() {
|
|
147
|
+
return [...this.metrics];
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Find metrics by name.
|
|
151
|
+
*
|
|
152
|
+
* @param name - Metric name
|
|
153
|
+
* @returns Matching metrics
|
|
154
|
+
*/
|
|
155
|
+
findMetricsByName(name) {
|
|
156
|
+
return this.metrics.filter((m) => m.name === name);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Clear captured metrics.
|
|
160
|
+
*/
|
|
161
|
+
reset() {
|
|
162
|
+
this.metrics = [];
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Assert no metrics have a specific label value.
|
|
166
|
+
*
|
|
167
|
+
* @param labelKey - Label key
|
|
168
|
+
* @param value - Forbidden value
|
|
169
|
+
* @throws Error if forbidden label is found
|
|
170
|
+
*/
|
|
171
|
+
assertNoLabel(labelKey, value) {
|
|
172
|
+
for (const metric of this.metrics) {
|
|
173
|
+
for (const dp of metric.dataPoints) {
|
|
174
|
+
const label = dp.attributes[labelKey];
|
|
175
|
+
if (label === undefined)
|
|
176
|
+
continue;
|
|
177
|
+
const matches = value instanceof RegExp ? value.test(String(label)) : label === value;
|
|
178
|
+
if (matches) {
|
|
179
|
+
throw new Error(`Found forbidden label ${labelKey}=${String(label)} on metric "${metric.name}"`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* In-memory log exporter for testing.
|
|
187
|
+
*/
|
|
188
|
+
export class InMemoryLogExporter {
|
|
189
|
+
logs = [];
|
|
190
|
+
/**
|
|
191
|
+
* Export logs to in-memory storage.
|
|
192
|
+
*/
|
|
193
|
+
export(logs) {
|
|
194
|
+
this.logs.push(...logs);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get all captured logs.
|
|
198
|
+
*/
|
|
199
|
+
getLogs() {
|
|
200
|
+
return [...this.logs];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Find logs by severity.
|
|
204
|
+
*
|
|
205
|
+
* @param severityNumber - Severity level (e.g., 9 for INFO, 13 for WARN, 17 for ERROR)
|
|
206
|
+
* @returns Matching logs
|
|
207
|
+
*/
|
|
208
|
+
findLogsBySeverity(severityNumber) {
|
|
209
|
+
return this.logs.filter((l) => l.severityNumber === severityNumber);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Find logs containing text.
|
|
213
|
+
*
|
|
214
|
+
* @param text - Text to search for in log body
|
|
215
|
+
* @returns Matching logs
|
|
216
|
+
*/
|
|
217
|
+
findLogsContaining(text) {
|
|
218
|
+
return this.logs.filter((l) => {
|
|
219
|
+
if (l.body === undefined)
|
|
220
|
+
return false;
|
|
221
|
+
const bodyStr = String(l.body);
|
|
222
|
+
return text instanceof RegExp ? text.test(bodyStr) : bodyStr.includes(text);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Clear captured logs.
|
|
227
|
+
*/
|
|
228
|
+
reset() {
|
|
229
|
+
this.logs = [];
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Assert no logs contain sensitive data.
|
|
233
|
+
*
|
|
234
|
+
* @param pattern - Pattern to check for (forbidden content)
|
|
235
|
+
* @throws Error if forbidden content is found
|
|
236
|
+
*/
|
|
237
|
+
assertNoLogContains(pattern) {
|
|
238
|
+
for (const log of this.logs) {
|
|
239
|
+
if (log.body === undefined)
|
|
240
|
+
continue;
|
|
241
|
+
const bodyStr = String(log.body);
|
|
242
|
+
if (pattern.test(bodyStr)) {
|
|
243
|
+
throw new Error(`Found forbidden content in log: ${bodyStr.slice(0, 100)}...`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=in-memory-exporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-exporter.js","sourceRoot":"","sources":["../../src/testing/in-memory-exporter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAErE;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IACvB,KAAK,GAAmB,EAAE,CAAC;IAC3B,OAAO,GAAG,KAAK,CAAC;IAExB;;OAEG;IACH,MAAM,CAAC,KAAqB,EAAE,cAA8C;QAC1E,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC;YAClD,OAAO;QACT,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QAC1B,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED;;OA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AAC;YACvC,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC/B,OAAO,IAAI,YAAY,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC9E,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,mBAAmB,CAAC,OAAe;QACjC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAC5B,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS;gBAAE,SAAS;YACrC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACjC,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;YACjF,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing Utilities
|
|
3
|
+
*
|
|
4
|
+
* In-memory exporters and test helpers for telemetry assertions.
|
|
5
|
+
*/
|
|
6
|
+
export { InMemorySpanExporter, InMemoryMetricExporter, InMemoryLogExporter, type CapturedMetric, type CapturedLogRecord, } from './in-memory-exporter.js';
|
|
7
|
+
export { initTestTelemetry, getTestTelemetryInstance, resetTestTelemetry, getTestTracer, withTestSpan, type TestTelemetryInstance, } from './test-init.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,cAAc,EACnB,KAAK,iBAAiB,GACvB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,KAAK,qBAAqB,GAC3B,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing Utilities
|
|
3
|
+
*
|
|
4
|
+
* In-memory exporters and test helpers for telemetry assertions.
|
|
5
|
+
*/
|
|
6
|
+
export { InMemorySpanExporter, InMemoryMetricExporter, InMemoryLogExporter, } from './in-memory-exporter.js';
|
|
7
|
+
export { initTestTelemetry, getTestTelemetryInstance, resetTestTelemetry, getTestTracer, withTestSpan, } from './test-init.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GAGpB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,kBAAkB,EAClB,aAAa,EACb,YAAY,GAEb,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Telemetry Initialization
|
|
3
|
+
*
|
|
4
|
+
* Initialize telemetry for testing with in-memory exporters.
|
|
5
|
+
* No external connections are made.
|
|
6
|
+
*/
|
|
7
|
+
import { trace } from "@opentelemetry/api";
|
|
8
|
+
import { InMemorySpanExporter, InMemoryMetricExporter, InMemoryLogExporter } from "./in-memory-exporter.js";
|
|
9
|
+
import { TelemetryPolicyEvaluator } from "../common/policy-evaluator.js";
|
|
10
|
+
import type { BaseTelemetryConfig } from "../types/index.js";
|
|
11
|
+
/**
|
|
12
|
+
* Test telemetry instance with in-memory exporters.
|
|
13
|
+
*/
|
|
14
|
+
export interface TestTelemetryInstance {
|
|
15
|
+
/** In-memory span exporter */
|
|
16
|
+
spanExporter: InMemorySpanExporter;
|
|
17
|
+
/** In-memory metric exporter */
|
|
18
|
+
metricExporter: InMemoryMetricExporter;
|
|
19
|
+
/** In-memory log exporter */
|
|
20
|
+
logExporter: InMemoryLogExporter;
|
|
21
|
+
/** Policy evaluator */
|
|
22
|
+
policyEvaluator: TelemetryPolicyEvaluator;
|
|
23
|
+
/** Reset all exporters (call in beforeEach) */
|
|
24
|
+
reset: () => void;
|
|
25
|
+
/** Shutdown (call in afterAll) */
|
|
26
|
+
shutdown: () => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Initialize telemetry for testing.
|
|
30
|
+
*
|
|
31
|
+
* Uses in-memory exporters, no external connections.
|
|
32
|
+
* Call once per test file, use reset() in beforeEach.
|
|
33
|
+
*
|
|
34
|
+
* @param config - Optional test configuration
|
|
35
|
+
* @returns Test telemetry instance
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { initTestTelemetry } from '@superblocksteam/telemetry/testing';
|
|
40
|
+
*
|
|
41
|
+
* describe('MyService', () => {
|
|
42
|
+
* const { spanExporter, reset } = initTestTelemetry();
|
|
43
|
+
*
|
|
44
|
+
* beforeEach(() => reset());
|
|
45
|
+
*
|
|
46
|
+
* it('creates expected spans', async () => {
|
|
47
|
+
* // ... test code ...
|
|
48
|
+
* expect(spanExporter.getSpans()).toHaveLength(1);
|
|
49
|
+
* });
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function initTestTelemetry(config?: Partial<BaseTelemetryConfig>): TestTelemetryInstance;
|
|
54
|
+
/**
|
|
55
|
+
* Get the test telemetry instance.
|
|
56
|
+
*
|
|
57
|
+
* @throws Error if not initialized
|
|
58
|
+
*/
|
|
59
|
+
export declare function getTestTelemetryInstance(): TestTelemetryInstance;
|
|
60
|
+
/**
|
|
61
|
+
* Reset the test telemetry (for cleanup between test files).
|
|
62
|
+
*/
|
|
63
|
+
export declare function resetTestTelemetry(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Get a tracer for tests.
|
|
66
|
+
*
|
|
67
|
+
* @param name - Tracer name
|
|
68
|
+
* @returns Tracer instance
|
|
69
|
+
*/
|
|
70
|
+
export declare function getTestTracer(name?: string): ReturnType<typeof trace.getTracer>;
|
|
71
|
+
/**
|
|
72
|
+
* Run a function within a test span.
|
|
73
|
+
* Useful for testing span creation.
|
|
74
|
+
*
|
|
75
|
+
* @param name - Span name
|
|
76
|
+
* @param fn - Function to run
|
|
77
|
+
* @returns Function result
|
|
78
|
+
*/
|
|
79
|
+
export declare function withTestSpan<T>(name: string, fn: () => Promise<T> | T): Promise<T>;
|
|
80
|
+
//# sourceMappingURL=test-init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-init.d.ts","sourceRoot":"","sources":["../../src/testing/test-init.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAM3C,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,8BAA8B;IAC9B,YAAY,EAAE,oBAAoB,CAAC;IACnC,gCAAgC;IAChC,cAAc,EAAE,sBAAsB,CAAC;IACvC,6BAA6B;IAC7B,WAAW,EAAE,mBAAmB,CAAC;IACjC,uBAAuB;IACvB,eAAe,EAAE,wBAAwB,CAAC;IAC1C,+CAA+C;IAC/C,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAeD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GACpC,qBAAqB,CA2CvB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,qBAAqB,CAOhE;AAED;;GAEG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAIxD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,IAAI,SAAS,GACZ,UAAU,CAAC,OAAO,KAAK,CAAC,SAAS,CAAC,CAEpC;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAClC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CASZ"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Telemetry Initialization
|
|
3
|
+
*
|
|
4
|
+
* Initialize telemetry for testing with in-memory exporters.
|
|
5
|
+
* No external connections are made.
|
|
6
|
+
*/
|
|
7
|
+
import { trace } from "@opentelemetry/api";
|
|
8
|
+
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
9
|
+
import { SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
10
|
+
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
|
|
11
|
+
import { W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
12
|
+
import { InMemorySpanExporter, InMemoryMetricExporter, InMemoryLogExporter, } from "./in-memory-exporter.js";
|
|
13
|
+
import { buildResource } from "../common/resource.js";
|
|
14
|
+
import { TelemetryPolicyEvaluator } from "../common/policy-evaluator.js";
|
|
15
|
+
import { CLOUD_DEFAULT_POLICY } from "../types/policy.js";
|
|
16
|
+
// Singleton for tests
|
|
17
|
+
let testInstance;
|
|
18
|
+
let tracerProvider;
|
|
19
|
+
/**
|
|
20
|
+
* Default test configuration.
|
|
21
|
+
*/
|
|
22
|
+
const DEFAULT_TEST_CONFIG = {
|
|
23
|
+
serviceName: "test-service",
|
|
24
|
+
serviceVersion: "0.0.0-test",
|
|
25
|
+
environment: "test",
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Initialize telemetry for testing.
|
|
29
|
+
*
|
|
30
|
+
* Uses in-memory exporters, no external connections.
|
|
31
|
+
* Call once per test file, use reset() in beforeEach.
|
|
32
|
+
*
|
|
33
|
+
* @param config - Optional test configuration
|
|
34
|
+
* @returns Test telemetry instance
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { initTestTelemetry } from '@superblocksteam/telemetry/testing';
|
|
39
|
+
*
|
|
40
|
+
* describe('MyService', () => {
|
|
41
|
+
* const { spanExporter, reset } = initTestTelemetry();
|
|
42
|
+
*
|
|
43
|
+
* beforeEach(() => reset());
|
|
44
|
+
*
|
|
45
|
+
* it('creates expected spans', async () => {
|
|
46
|
+
* // ... test code ...
|
|
47
|
+
* expect(spanExporter.getSpans()).toHaveLength(1);
|
|
48
|
+
* });
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function initTestTelemetry(config) {
|
|
53
|
+
if (testInstance) {
|
|
54
|
+
return testInstance;
|
|
55
|
+
}
|
|
56
|
+
const mergedConfig = { ...DEFAULT_TEST_CONFIG, ...config };
|
|
57
|
+
const resource = buildResource(mergedConfig);
|
|
58
|
+
const spanExporter = new InMemorySpanExporter();
|
|
59
|
+
const metricExporter = new InMemoryMetricExporter();
|
|
60
|
+
const logExporter = new InMemoryLogExporter();
|
|
61
|
+
const policyEvaluator = new TelemetryPolicyEvaluator(CLOUD_DEFAULT_POLICY);
|
|
62
|
+
// Create provider with span processors in constructor (OTEL v2.x API)
|
|
63
|
+
tracerProvider = new NodeTracerProvider({
|
|
64
|
+
resource,
|
|
65
|
+
spanProcessors: [new SimpleSpanProcessor(spanExporter)],
|
|
66
|
+
});
|
|
67
|
+
// Register the provider
|
|
68
|
+
tracerProvider.register({
|
|
69
|
+
propagator: new W3CTraceContextPropagator(),
|
|
70
|
+
contextManager: new AsyncLocalStorageContextManager(),
|
|
71
|
+
});
|
|
72
|
+
testInstance = {
|
|
73
|
+
spanExporter,
|
|
74
|
+
metricExporter,
|
|
75
|
+
logExporter,
|
|
76
|
+
policyEvaluator,
|
|
77
|
+
reset: () => {
|
|
78
|
+
spanExporter.reset();
|
|
79
|
+
metricExporter.reset();
|
|
80
|
+
logExporter.reset();
|
|
81
|
+
},
|
|
82
|
+
shutdown: async () => {
|
|
83
|
+
await tracerProvider?.shutdown();
|
|
84
|
+
testInstance = undefined;
|
|
85
|
+
tracerProvider = undefined;
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
return testInstance;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the test telemetry instance.
|
|
92
|
+
*
|
|
93
|
+
* @throws Error if not initialized
|
|
94
|
+
*/
|
|
95
|
+
export function getTestTelemetryInstance() {
|
|
96
|
+
if (!testInstance) {
|
|
97
|
+
throw new Error("[TestTelemetry] Not initialized. Call initTestTelemetry() first.");
|
|
98
|
+
}
|
|
99
|
+
return testInstance;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Reset the test telemetry (for cleanup between test files).
|
|
103
|
+
*/
|
|
104
|
+
export async function resetTestTelemetry() {
|
|
105
|
+
if (testInstance) {
|
|
106
|
+
await testInstance.shutdown();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get a tracer for tests.
|
|
111
|
+
*
|
|
112
|
+
* @param name - Tracer name
|
|
113
|
+
* @returns Tracer instance
|
|
114
|
+
*/
|
|
115
|
+
export function getTestTracer(name = "test") {
|
|
116
|
+
return trace.getTracer(name);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Run a function within a test span.
|
|
120
|
+
* Useful for testing span creation.
|
|
121
|
+
*
|
|
122
|
+
* @param name - Span name
|
|
123
|
+
* @param fn - Function to run
|
|
124
|
+
* @returns Function result
|
|
125
|
+
*/
|
|
126
|
+
export async function withTestSpan(name, fn) {
|
|
127
|
+
const tracer = getTestTracer();
|
|
128
|
+
return tracer.startActiveSpan(name, async (span) => {
|
|
129
|
+
try {
|
|
130
|
+
return await fn();
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
span.end();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=test-init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-init.js","sourceRoot":"","sources":["../../src/testing/test-init.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oCAAoC,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAqB1D,sBAAsB;AACtB,IAAI,YAA+C,CAAC;AACpD,IAAI,cAA8C,CAAC;AAEnD;;GAEG;AACH,MAAM,mBAAmB,GAAwB;IAC/C,W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CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB;IACtC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,kEAAkE,CACnE,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAI,GAAG,MAAM;IAEb,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAY,EACZ,EAAwB;IAExB,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACjD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telemetry Types
|
|
3
|
+
*
|
|
4
|
+
* Re-exports policy types and config interfaces.
|
|
5
|
+
*/
|
|
6
|
+
export * from './policy.js';
|
|
7
|
+
/**
|
|
8
|
+
* Base configuration for telemetry initialization.
|
|
9
|
+
*/
|
|
10
|
+
export interface BaseTelemetryConfig {
|
|
11
|
+
/** Service name (e.g., 'superblocks-server') */
|
|
12
|
+
serviceName: string;
|
|
13
|
+
/** Service version (e.g., '1.0.0') */
|
|
14
|
+
serviceVersion: string;
|
|
15
|
+
/** Deployment environment (e.g., 'production', 'staging', 'development') */
|
|
16
|
+
environment: string;
|
|
17
|
+
/** Additional resource attributes */
|
|
18
|
+
resourceAttributes?: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Node.js specific telemetry configuration.
|
|
22
|
+
*/
|
|
23
|
+
export interface NodeTelemetryConfig extends BaseTelemetryConfig {
|
|
24
|
+
/** OTLP collector URL (e.g., http://localhost:4318) */
|
|
25
|
+
otlpUrl?: string;
|
|
26
|
+
/** OpenTelemetry instrumentations to enable */
|
|
27
|
+
instrumentations?: unknown[];
|
|
28
|
+
/** Whether to enable metrics collection */
|
|
29
|
+
metricsEnabled?: boolean;
|
|
30
|
+
/** Whether to enable log collection */
|
|
31
|
+
logsEnabled?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Browser specific telemetry configuration.
|
|
35
|
+
*/
|
|
36
|
+
export interface BrowserTelemetryConfig extends BaseTelemetryConfig {
|
|
37
|
+
/** OTLP traces endpoint URL */
|
|
38
|
+
otlpUrl: string;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IAEpB,sCAAsC;IACtC,cAAc,EAAE,MAAM,CAAC;IAEvB,4EAA4E;IAC5E,WAAW,EAAE,MAAM,CAAC;IAEpB,qCAAqC;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC9D,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC;IAE7B,2CAA2C;IAC3C,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,uCAAuC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telemetry Policy Types
|
|
3
|
+
*
|
|
4
|
+
* NOTE: In the hybrid tier architecture, the OTEL Collector handles
|
|
5
|
+
* sanitization, hashing, and routing. The SDK just emits full-fidelity data.
|
|
6
|
+
* See obs/otel-collector/config-tiered.yaml for Collector configuration.
|
|
7
|
+
*/
|
|
8
|
+
import { DeploymentTypeEnum } from "@superblocksteam/shared";
|
|
9
|
+
export { DeploymentTypeEnum as DeploymentType };
|
|
10
|
+
/**
|
|
11
|
+
* Telemetry tier definitions.
|
|
12
|
+
*
|
|
13
|
+
* Tier 1 (Local): Full fidelity data for debugging. Stored in customer LGTM.
|
|
14
|
+
* Tier 2 (Operational): Sanitized metrics/traces for ops. Exported to Superblocks.
|
|
15
|
+
* Tier 3 (Analytics): AI experience telemetry. Exported with content controls.
|
|
16
|
+
*
|
|
17
|
+
* In the hybrid architecture:
|
|
18
|
+
* - SDK emits all data to the Collector
|
|
19
|
+
* - Collector transforms and routes to appropriate tier pipelines
|
|
20
|
+
* - Tier tagging, hashing, and filtering happen at Collector level
|
|
21
|
+
*/
|
|
22
|
+
export declare enum TelemetryTier {
|
|
23
|
+
/** Full fidelity debugging data - prompts, code, tool IO, stack traces */
|
|
24
|
+
TIER_1_LOCAL = "tier_1_local",
|
|
25
|
+
/** Sanitized operational metrics and traces for dashboards/billing */
|
|
26
|
+
TIER_2_OPERATIONAL = "tier_2_operational",
|
|
27
|
+
/** AI experience telemetry - prompts, responses, quality signals (no tool outputs) */
|
|
28
|
+
TIER_3_AI_EXPERIENCE = "tier_3_ai_experience"
|
|
29
|
+
}
|
|
30
|
+
export declare enum EnforcementMode {
|
|
31
|
+
/** Log violations but allow */
|
|
32
|
+
AUDIT = "audit",
|
|
33
|
+
/** Block violations */
|
|
34
|
+
ENFORCE = "enforce"
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Tier 3 content export policy for runtime control during incidents.
|
|
38
|
+
*/
|
|
39
|
+
export interface Tier3ContentPolicy {
|
|
40
|
+
/** Export AI prompts/responses. Kill switch for incidents. */
|
|
41
|
+
contentExportEnabled: boolean;
|
|
42
|
+
/** Redact detected secrets (JWTs, API keys, PEM blocks) from content */
|
|
43
|
+
secretRedactionEnabled: boolean;
|
|
44
|
+
/** Block export if tool output patterns detected in response */
|
|
45
|
+
toolOutputFilteringEnabled: boolean;
|
|
46
|
+
/** Max prompt length in bytes */
|
|
47
|
+
maxPromptBytes: number;
|
|
48
|
+
/** Max response length in bytes */
|
|
49
|
+
maxResponseBytes: number;
|
|
50
|
+
}
|
|
51
|
+
export interface TierConfig {
|
|
52
|
+
/** Is this tier enabled for local retention? */
|
|
53
|
+
enabled: boolean;
|
|
54
|
+
/** Is this tier enabled for export? */
|
|
55
|
+
exportEnabled: boolean;
|
|
56
|
+
/** Sampling rate for this tier (0.0 - 1.0) */
|
|
57
|
+
sampleRate: number;
|
|
58
|
+
}
|
|
59
|
+
export interface TelemetryPolicy {
|
|
60
|
+
/** Deployment context */
|
|
61
|
+
deploymentType: DeploymentTypeEnum;
|
|
62
|
+
/** Per-tier configuration */
|
|
63
|
+
tiers: {
|
|
64
|
+
[TelemetryTier.TIER_1_LOCAL]: TierConfig;
|
|
65
|
+
[TelemetryTier.TIER_2_OPERATIONAL]: TierConfig;
|
|
66
|
+
[TelemetryTier.TIER_3_AI_EXPERIENCE]: TierConfig;
|
|
67
|
+
};
|
|
68
|
+
/** Tier 3 content export controls (prompts, responses). */
|
|
69
|
+
tier3Content: Tier3ContentPolicy;
|
|
70
|
+
/** Enforcement behavior */
|
|
71
|
+
enforcementMode: EnforcementMode;
|
|
72
|
+
/** Optional org-specific overrides */
|
|
73
|
+
orgOverrides?: Record<string, Partial<TelemetryPolicy>>;
|
|
74
|
+
}
|
|
75
|
+
/** Default Tier 3 content policy (enabled with all guardrails) */
|
|
76
|
+
export declare const TIER3_CONTENT_POLICY_DEFAULT: Tier3ContentPolicy;
|
|
77
|
+
/** Tier 3 content policy: disabled (kill switch) */
|
|
78
|
+
export declare const TIER3_CONTENT_POLICY_DISABLED: Tier3ContentPolicy;
|
|
79
|
+
/**
|
|
80
|
+
* Cloud deployment: all tiers enabled and exported.
|
|
81
|
+
*/
|
|
82
|
+
export declare const CLOUD_DEFAULT_POLICY: TelemetryPolicy;
|
|
83
|
+
/**
|
|
84
|
+
* Cloud-Prem deployment: Tier 1 local only, Tier 2/3 exported.
|
|
85
|
+
* Hashing/sanitization handled by OTEL Collector.
|
|
86
|
+
*/
|
|
87
|
+
export declare const CLOUD_PREM_DEFAULT_POLICY: TelemetryPolicy;
|
|
88
|
+
/**
|
|
89
|
+
* Get the default policy for a deployment type.
|
|
90
|
+
*/
|
|
91
|
+
export declare function getDefaultPolicy(deploymentType: DeploymentTypeEnum): TelemetryPolicy;
|
|
92
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/types/policy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,kBAAkB,IAAI,cAAc,EAAE,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,oBAAY,aAAa;IACvB,0EAA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