@osfactory/otel-hook 0.1.0
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 -0
- package/README.md +1020 -0
- package/dist/adapter-DIgRACtL.d.ts +303 -0
- package/dist/cli.js +12607 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +233 -0
- package/dist/config.js +996 -0
- package/dist/config.js.map +1 -0
- package/dist/content-CoB7aNP1.d.ts +118 -0
- package/dist/diagnostics.d.ts +58 -0
- package/dist/diagnostics.js +46 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/errors.d.ts +91 -0
- package/dist/errors.js +322 -0
- package/dist/errors.js.map +1 -0
- package/dist/events-VxBnDFaO.d.ts +2044 -0
- package/dist/filesystem-store-J8jjDMTh.d.ts +65 -0
- package/dist/hook-CGpo-vks.d.ts +292 -0
- package/dist/identity-BrVBs901.d.ts +227 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +11798 -0
- package/dist/index.js.map +1 -0
- package/dist/install.d.ts +1021 -0
- package/dist/install.js +3271 -0
- package/dist/install.js.map +1 -0
- package/dist/integration.d.ts +303 -0
- package/dist/integration.js +5942 -0
- package/dist/integration.js.map +1 -0
- package/dist/keys-Dej5bN3L.d.ts +7 -0
- package/dist/lifecycle.d.ts +428 -0
- package/dist/lifecycle.js +1077 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/memory-DXVBc8V9.d.ts +94 -0
- package/dist/model.d.ts +45 -0
- package/dist/model.js +1023 -0
- package/dist/model.js.map +1 -0
- package/dist/otlp-log-sink-CeIFDDpn.d.ts +457 -0
- package/dist/payload-CHr53E_v.d.ts +201 -0
- package/dist/policy-D1CrlYn3.d.ts +73 -0
- package/dist/ports-Q8x0ODhs.d.ts +200 -0
- package/dist/primitives-CJ8-rn-f.d.ts +75 -0
- package/dist/privacy.d.ts +51 -0
- package/dist/privacy.js +633 -0
- package/dist/privacy.js.map +1 -0
- package/dist/providers.d.ts +257 -0
- package/dist/providers.js +4398 -0
- package/dist/providers.js.map +1 -0
- package/dist/registry-BzYmC9OC.d.ts +49 -0
- package/dist/runtime.d.ts +32 -0
- package/dist/runtime.js +2907 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema-Cn0-xz8L.d.ts +224 -0
- package/dist/semconv-Baoz-0OI.d.ts +188 -0
- package/dist/service-j4jEO6cZ.d.ts +68 -0
- package/dist/state.d.ts +36 -0
- package/dist/state.js +710 -0
- package/dist/state.js.map +1 -0
- package/dist/taxonomy-DwhTtuWd.d.ts +87 -0
- package/dist/telemetry.d.ts +77 -0
- package/dist/telemetry.js +2294 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/testing.d.ts +155 -0
- package/dist/testing.js +6513 -0
- package/dist/testing.js.map +1 -0
- package/package.json +124 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,996 @@
|
|
|
1
|
+
// src/config/resource-attributes.ts
|
|
2
|
+
import { z as z3 } from "zod";
|
|
3
|
+
|
|
4
|
+
// src/model/primitives.ts
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var MAX_IDENTIFIER_LENGTH = 256;
|
|
7
|
+
var MAX_ATTRIBUTE_STRING_LENGTH = 4096;
|
|
8
|
+
var MAX_ATTRIBUTE_ARRAY_LENGTH = 128;
|
|
9
|
+
var nonEmptyStringSchema = z.string().min(1).max(MAX_IDENTIFIER_LENGTH);
|
|
10
|
+
var epochMillisSchema = z.number().int().min(0).max(864e13);
|
|
11
|
+
var durationMillisSchema = z.number().min(0).finite();
|
|
12
|
+
var tokenCountSchema = z.number().int().min(0);
|
|
13
|
+
var sequenceNumberSchema = z.number().int().min(0);
|
|
14
|
+
var brandedIdSchema = () => z.string().min(1).max(MAX_IDENTIFIER_LENGTH);
|
|
15
|
+
var invocationIdSchema = brandedIdSchema().brand();
|
|
16
|
+
var sessionIdSchema = brandedIdSchema().brand();
|
|
17
|
+
var eventIdSchema = brandedIdSchema().brand();
|
|
18
|
+
var WORKSPACE_ID_PATTERN = /^[a-z][a-z0-9]{0,15}:[A-Za-z0-9_-]{8,128}$/;
|
|
19
|
+
var workspaceIdSchema = z.string().regex(WORKSPACE_ID_PATTERN, "workspace id must be an opaque `<scheme>:<token>` handle").brand();
|
|
20
|
+
var PROVIDER_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
21
|
+
var providerIdSchema = z.string().min(1).max(64).regex(PROVIDER_ID_PATTERN, "provider id must be lowercase and hyphenated").brand();
|
|
22
|
+
var UNKNOWN_PROVIDER_ID = "unknown";
|
|
23
|
+
var resolvedProviderIdSchema = z.union([
|
|
24
|
+
providerIdSchema,
|
|
25
|
+
z.literal(UNKNOWN_PROVIDER_ID)
|
|
26
|
+
]);
|
|
27
|
+
var attributePrimitiveSchema = z.union([
|
|
28
|
+
z.string().max(MAX_ATTRIBUTE_STRING_LENGTH),
|
|
29
|
+
z.number().finite(),
|
|
30
|
+
z.boolean()
|
|
31
|
+
]);
|
|
32
|
+
var attributeValueSchema = z.union([
|
|
33
|
+
attributePrimitiveSchema,
|
|
34
|
+
z.array(attributePrimitiveSchema).max(MAX_ATTRIBUTE_ARRAY_LENGTH)
|
|
35
|
+
]);
|
|
36
|
+
var attributesSchema = z.record(z.string().min(1).max(MAX_IDENTIFIER_LENGTH), attributeValueSchema);
|
|
37
|
+
var detectionConfidenceSchema = z.enum(["none", "weak", "strong", "exact"]);
|
|
38
|
+
var DETECTION_CONFIDENCE_RANK = Object.freeze({
|
|
39
|
+
none: 0,
|
|
40
|
+
weak: 1,
|
|
41
|
+
strong: 2,
|
|
42
|
+
exact: 3
|
|
43
|
+
});
|
|
44
|
+
var sourceTransportSchema = z.enum([
|
|
45
|
+
"hook-stdin",
|
|
46
|
+
"cli-argument",
|
|
47
|
+
"library-call",
|
|
48
|
+
"test-fixture"
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
// src/privacy/policy.ts
|
|
52
|
+
import { z as z2 } from "zod";
|
|
53
|
+
var contentModeSchema = z2.enum(["omit", "mask", "redact", "raw"]);
|
|
54
|
+
var CONTENT_MODE_DISCLOSURE = Object.freeze({
|
|
55
|
+
omit: "omitted",
|
|
56
|
+
mask: "masked",
|
|
57
|
+
redact: "redacted",
|
|
58
|
+
raw: "raw"
|
|
59
|
+
});
|
|
60
|
+
var DEFAULT_SECRET_KEY_PATTERNS = Object.freeze([
|
|
61
|
+
"(^|[._-])(secret|secrets)([._-]|$)",
|
|
62
|
+
"(^|[._-])(token|tokens)([._-]|$)",
|
|
63
|
+
"(^|[._-])(password|passwd|pwd)([._-]|$)",
|
|
64
|
+
"(^|[._-])(credential|credentials)([._-]|$)",
|
|
65
|
+
"(^|[._-])(api[._-]?key|apikey|access[._-]?key|secret[._-]?key|private[._-]?key)([._-]|$)",
|
|
66
|
+
"(^|[._-])(authorization|auth[._-]?header|bearer)([._-]|$)",
|
|
67
|
+
"(^|[._-])(cookie|set[._-]?cookie)([._-]|$)",
|
|
68
|
+
"(^|[._-])(signature|sig)([._-]|$)"
|
|
69
|
+
]);
|
|
70
|
+
var DEFAULT_SECRET_VALUE_PATTERNS = Object.freeze([
|
|
71
|
+
"AKIA[0-9A-Z]{16}",
|
|
72
|
+
"sk-[A-Za-z0-9_-]{16,}",
|
|
73
|
+
"gh[pousr]_[A-Za-z0-9]{16,}",
|
|
74
|
+
"xox[abprs]-[A-Za-z0-9-]{10,}",
|
|
75
|
+
"-----BEGIN[A-Z ]*PRIVATE KEY-----",
|
|
76
|
+
"eyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}",
|
|
77
|
+
"(?:Bearer|Basic)\\s+[A-Za-z0-9._~+/=-]{12,}"
|
|
78
|
+
]);
|
|
79
|
+
var privacyLimitsSchema = z2.strictObject({
|
|
80
|
+
/** Maximum characters of disclosed text per content fact or string value. */
|
|
81
|
+
maxStringLength: z2.number().int().min(0).max(65536),
|
|
82
|
+
/** Maximum nesting depth walked when sanitizing structured values. */
|
|
83
|
+
maxDepth: z2.number().int().min(1).max(32),
|
|
84
|
+
/** Maximum array entries retained when sanitizing structured values. */
|
|
85
|
+
maxArrayLength: z2.number().int().min(1).max(4096),
|
|
86
|
+
/** Maximum canonical events emitted per invocation. */
|
|
87
|
+
maxEventsPerInvocation: z2.number().int().min(1).max(1e4),
|
|
88
|
+
/** Maximum object keys retained per level when sanitizing. */
|
|
89
|
+
maxObjectKeys: z2.number().int().min(1).max(1024)
|
|
90
|
+
});
|
|
91
|
+
var privacyPolicySchema = z2.strictObject({
|
|
92
|
+
contentMode: contentModeSchema,
|
|
93
|
+
/**
|
|
94
|
+
* `raw` mode is refused unless this is also true, so a single mistyped
|
|
95
|
+
* environment variable cannot start exporting prompts.
|
|
96
|
+
*/
|
|
97
|
+
allowRawContent: z2.boolean(),
|
|
98
|
+
/**
|
|
99
|
+
* Salt mixed into every hash. A per-deployment salt makes hashes
|
|
100
|
+
* non-correlatable across deployments; an empty salt makes them globally
|
|
101
|
+
* comparable. Both are legitimate; the choice is explicit.
|
|
102
|
+
*/
|
|
103
|
+
hashSalt: z2.string().max(256),
|
|
104
|
+
maskCharacter: z2.string().length(1),
|
|
105
|
+
redactionPlaceholder: z2.string().min(1).max(64),
|
|
106
|
+
secretKeyPatterns: z2.array(z2.string().min(1)).max(128).readonly(),
|
|
107
|
+
secretValuePatterns: z2.array(z2.string().min(1)).max(128).readonly(),
|
|
108
|
+
limits: privacyLimitsSchema
|
|
109
|
+
});
|
|
110
|
+
var DEFAULT_PRIVACY_LIMITS = Object.freeze({
|
|
111
|
+
maxStringLength: 1024,
|
|
112
|
+
maxDepth: 6,
|
|
113
|
+
maxArrayLength: 64,
|
|
114
|
+
maxEventsPerInvocation: 512,
|
|
115
|
+
maxObjectKeys: 128
|
|
116
|
+
});
|
|
117
|
+
var DEFAULT_PRIVACY_POLICY = Object.freeze({
|
|
118
|
+
contentMode: "omit",
|
|
119
|
+
allowRawContent: false,
|
|
120
|
+
hashSalt: "",
|
|
121
|
+
maskCharacter: "*",
|
|
122
|
+
redactionPlaceholder: "[redacted]",
|
|
123
|
+
secretKeyPatterns: DEFAULT_SECRET_KEY_PATTERNS,
|
|
124
|
+
secretValuePatterns: DEFAULT_SECRET_VALUE_PATTERNS,
|
|
125
|
+
limits: DEFAULT_PRIVACY_LIMITS
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// src/config/resource-attributes.ts
|
|
129
|
+
var MAX_RESOURCE_ATTRIBUTES = 64;
|
|
130
|
+
var MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH = 255;
|
|
131
|
+
var MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH = 2048;
|
|
132
|
+
var RESOURCE_ATTRIBUTE_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_./-]*$/;
|
|
133
|
+
var RESERVED_RESOURCE_ATTRIBUTE_KEYS = Object.freeze([
|
|
134
|
+
"service.name",
|
|
135
|
+
"service.namespace"
|
|
136
|
+
]);
|
|
137
|
+
var isReservedResourceAttributeKey = (key) => RESERVED_RESOURCE_ATTRIBUTE_KEYS.includes(key.toLowerCase());
|
|
138
|
+
var SECRET_KEY_MATCHERS = Object.freeze(
|
|
139
|
+
DEFAULT_SECRET_KEY_PATTERNS.flatMap((source) => {
|
|
140
|
+
try {
|
|
141
|
+
return [new RegExp(source, "i")];
|
|
142
|
+
} catch {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
);
|
|
147
|
+
var isSecretResourceAttributeKey = (key) => SECRET_KEY_MATCHERS.some((pattern) => pattern.test(key));
|
|
148
|
+
var RESOURCE_ATTRIBUTE_KEY_REJECTION_DETAIL = Object.freeze({
|
|
149
|
+
empty: "resource attribute key is empty",
|
|
150
|
+
"too-long": `resource attribute key exceeds ${String(MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH)} characters`,
|
|
151
|
+
malformed: "resource attribute key must start with a letter and use only letters, digits, and `_`, `.`, `-`, `/`",
|
|
152
|
+
reserved: "service.name and service.namespace are exporter policy (--service-name / OTEL_HOOK_SERVICE_NAME), not resource attributes",
|
|
153
|
+
"secret-like": "resource attribute key matches a secret-name pattern, so it is never exported"
|
|
154
|
+
});
|
|
155
|
+
var checkResourceAttributeKey = (key) => {
|
|
156
|
+
if (key.length === 0) {
|
|
157
|
+
return "empty";
|
|
158
|
+
}
|
|
159
|
+
if (key.length > MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH) {
|
|
160
|
+
return "too-long";
|
|
161
|
+
}
|
|
162
|
+
if (!RESOURCE_ATTRIBUTE_KEY_PATTERN.test(key)) {
|
|
163
|
+
return "malformed";
|
|
164
|
+
}
|
|
165
|
+
if (isReservedResourceAttributeKey(key)) {
|
|
166
|
+
return "reserved";
|
|
167
|
+
}
|
|
168
|
+
if (isSecretResourceAttributeKey(key)) {
|
|
169
|
+
return "secret-like";
|
|
170
|
+
}
|
|
171
|
+
return void 0;
|
|
172
|
+
};
|
|
173
|
+
var resourceAttributeValueSchema = z3.union([
|
|
174
|
+
z3.string().max(MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH),
|
|
175
|
+
z3.number().finite(),
|
|
176
|
+
z3.boolean()
|
|
177
|
+
]);
|
|
178
|
+
var resourceAttributesSchema = z3.record(z3.string(), resourceAttributeValueSchema).superRefine((value, ctx) => {
|
|
179
|
+
const keys = Object.keys(value);
|
|
180
|
+
if (keys.length > MAX_RESOURCE_ATTRIBUTES) {
|
|
181
|
+
ctx.addIssue({
|
|
182
|
+
code: "custom",
|
|
183
|
+
message: `at most ${String(MAX_RESOURCE_ATTRIBUTES)} resource attributes are accepted`
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
for (const key of keys) {
|
|
187
|
+
const rejection = checkResourceAttributeKey(key);
|
|
188
|
+
if (rejection !== void 0) {
|
|
189
|
+
ctx.addIssue({
|
|
190
|
+
code: "custom",
|
|
191
|
+
path: [key],
|
|
192
|
+
message: RESOURCE_ATTRIBUTE_KEY_REJECTION_DETAIL[rejection]
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}).readonly();
|
|
197
|
+
var EMPTY_RESOURCE_ATTRIBUTES = Object.freeze({});
|
|
198
|
+
var stripSurroundingQuotes = (value) => value.length >= 2 && value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value;
|
|
199
|
+
var parseResourceAttributesValue = (raw) => {
|
|
200
|
+
const attributes = {};
|
|
201
|
+
const warnings = [];
|
|
202
|
+
let serviceName;
|
|
203
|
+
let serviceNamespace;
|
|
204
|
+
let overflowed = false;
|
|
205
|
+
const entries = raw.split(",");
|
|
206
|
+
for (const [index, rawEntry] of entries.entries()) {
|
|
207
|
+
const position = index + 1;
|
|
208
|
+
const entry = (rawEntry.split(";")[0] ?? "").trim();
|
|
209
|
+
if (entry === "") {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const equals = entry.indexOf("=");
|
|
213
|
+
if (equals <= 0) {
|
|
214
|
+
warnings.push(`entry ${String(position)} is not a key=value pair`);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const key = entry.slice(0, equals).trim();
|
|
218
|
+
const encoded = stripSurroundingQuotes(entry.slice(equals + 1).trim());
|
|
219
|
+
let value;
|
|
220
|
+
try {
|
|
221
|
+
value = decodeURIComponent(encoded);
|
|
222
|
+
} catch {
|
|
223
|
+
warnings.push(`entry ${String(position)} has a malformed percent-encoded value`);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (isReservedResourceAttributeKey(key)) {
|
|
227
|
+
if (value.length === 0 || value.length > MAX_IDENTIFIER_LENGTH) {
|
|
228
|
+
warnings.push(
|
|
229
|
+
`entry ${String(position)} sets ${key.toLowerCase()} to an empty or over-long value`
|
|
230
|
+
);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (key.toLowerCase() === "service.name") {
|
|
234
|
+
serviceName = value;
|
|
235
|
+
} else {
|
|
236
|
+
serviceNamespace = value;
|
|
237
|
+
}
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const rejection = checkResourceAttributeKey(key);
|
|
241
|
+
if (rejection !== void 0) {
|
|
242
|
+
warnings.push(
|
|
243
|
+
`entry ${String(position)} was skipped: ${RESOURCE_ATTRIBUTE_KEY_REJECTION_DETAIL[rejection]}`
|
|
244
|
+
);
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (value.length > MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH) {
|
|
248
|
+
warnings.push(
|
|
249
|
+
`entry ${String(position)} has a value longer than ${String(MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH)} characters`
|
|
250
|
+
);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (!(key in attributes) && Object.keys(attributes).length >= MAX_RESOURCE_ATTRIBUTES) {
|
|
254
|
+
overflowed = true;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
attributes[key] = value;
|
|
258
|
+
}
|
|
259
|
+
if (overflowed) {
|
|
260
|
+
warnings.push(
|
|
261
|
+
`more than ${String(MAX_RESOURCE_ATTRIBUTES)} resource attributes were supplied; the excess was dropped`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
attributes,
|
|
266
|
+
...serviceName === void 0 ? {} : { serviceName },
|
|
267
|
+
...serviceNamespace === void 0 ? {} : { serviceNamespace },
|
|
268
|
+
warnings
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
var sanitizeResourceAttributes = (attributes) => {
|
|
272
|
+
const safe = {};
|
|
273
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
274
|
+
if (checkResourceAttributeKey(key) !== void 0) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (Object.keys(safe).length >= MAX_RESOURCE_ATTRIBUTES) {
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
safe[key] = value;
|
|
281
|
+
}
|
|
282
|
+
return safe;
|
|
283
|
+
};
|
|
284
|
+
var describeResourceAttributeNames = (attributes) => Object.keys(attributes).sort();
|
|
285
|
+
|
|
286
|
+
// src/config/schema.ts
|
|
287
|
+
import { z as z4 } from "zod";
|
|
288
|
+
var logsPolicySchema = z4.strictObject({
|
|
289
|
+
enabled: z4.boolean(),
|
|
290
|
+
/**
|
|
291
|
+
* Full URL for the logs signal.
|
|
292
|
+
*
|
|
293
|
+
* Absent, it is derived from `endpoint`: a trailing `/v1/traces` becomes
|
|
294
|
+
* `/v1/logs`, and an endpoint with no signal path has `/v1/logs` appended.
|
|
295
|
+
*/
|
|
296
|
+
endpoint: z4.string().url().max(2048).optional(),
|
|
297
|
+
includeContent: z4.boolean(),
|
|
298
|
+
maxBatchSize: z4.number().int().min(1).max(4096)
|
|
299
|
+
});
|
|
300
|
+
var DEFAULT_LOGS_POLICY = Object.freeze({
|
|
301
|
+
enabled: false,
|
|
302
|
+
includeContent: false,
|
|
303
|
+
maxBatchSize: 128
|
|
304
|
+
});
|
|
305
|
+
var exporterPolicySchema = z4.strictObject({
|
|
306
|
+
enabled: z4.boolean(),
|
|
307
|
+
protocol: z4.enum(["http/protobuf", "http/json", "none"]),
|
|
308
|
+
endpoint: z4.string().url().max(2048).optional(),
|
|
309
|
+
/**
|
|
310
|
+
* Header names only. Values are supplied separately at construction time and
|
|
311
|
+
* are never part of a resolved-config snapshot, which is logged and exported.
|
|
312
|
+
*/
|
|
313
|
+
headerNames: z4.array(nonEmptyStringSchema).max(32).readonly(),
|
|
314
|
+
timeoutMillis: z4.number().int().min(1).max(6e5),
|
|
315
|
+
maxBatchSize: z4.number().int().min(1).max(4096),
|
|
316
|
+
maxQueueSize: z4.number().int().min(1).max(65536),
|
|
317
|
+
maxRetryAttempts: z4.number().int().min(0).max(10),
|
|
318
|
+
serviceName: nonEmptyStringSchema,
|
|
319
|
+
serviceNamespace: nonEmptyStringSchema.optional(),
|
|
320
|
+
/**
|
|
321
|
+
* Custom attributes merged into the exported OTLP Resource.
|
|
322
|
+
*
|
|
323
|
+
* Bounded and validated, and refusing `service.name`/`service.namespace`,
|
|
324
|
+
* which are the two fields above. Distinct from an invocation's
|
|
325
|
+
* `consumerAttributes`: this describes the emitting deployment, carries no
|
|
326
|
+
* identity, and is the same for every span this process exports.
|
|
327
|
+
*/
|
|
328
|
+
resourceAttributes: resourceAttributesSchema,
|
|
329
|
+
/**
|
|
330
|
+
* The logs signal. Nested under the exporter because it shares the endpoint,
|
|
331
|
+
* headers, timeout, protocol, service identity, and resource attributes above —
|
|
332
|
+
* a second top-level section would invite two of each to drift apart.
|
|
333
|
+
*/
|
|
334
|
+
logs: logsPolicySchema
|
|
335
|
+
});
|
|
336
|
+
var detectionPolicySchema = z4.strictObject({
|
|
337
|
+
/** Detections below this confidence resolve to the unknown provider. */
|
|
338
|
+
minimumConfidence: detectionConfidenceSchema,
|
|
339
|
+
/** When false, an ambiguous detection is an error rather than unknown. */
|
|
340
|
+
allowAmbiguousFallback: z4.boolean(),
|
|
341
|
+
/** Optional allow-list of provider ids; empty means "any registered". */
|
|
342
|
+
allowedProviderIds: z4.array(nonEmptyStringSchema).max(32).readonly()
|
|
343
|
+
});
|
|
344
|
+
var diagnosticsPolicySchema = z4.strictObject({
|
|
345
|
+
logLevel: z4.enum(["silent", "error", "warn", "info", "debug"]),
|
|
346
|
+
/** Emit `error.raised` events for contained failures. */
|
|
347
|
+
emitErrorEvents: z4.boolean()
|
|
348
|
+
});
|
|
349
|
+
var otelHookConfigSchema = z4.strictObject({
|
|
350
|
+
exporter: exporterPolicySchema,
|
|
351
|
+
privacy: privacyPolicySchema,
|
|
352
|
+
detection: detectionPolicySchema,
|
|
353
|
+
diagnostics: diagnosticsPolicySchema
|
|
354
|
+
});
|
|
355
|
+
var otelHookConfigPatchSchema = z4.strictObject({
|
|
356
|
+
// `logs` is unwrapped and re-partialled for the same reason `privacy.limits` is:
|
|
357
|
+
// merging happens per leaf, so a layer must be able to set `logs.enabled` alone
|
|
358
|
+
// without also restating the endpoint and the batch size.
|
|
359
|
+
exporter: exporterPolicySchema.omit({ logs: true }).partial().extend({ logs: logsPolicySchema.partial().optional() }).optional(),
|
|
360
|
+
privacy: privacyPolicySchema.omit({ limits: true }).partial().extend({ limits: privacyPolicySchema.shape.limits.partial().optional() }).optional(),
|
|
361
|
+
detection: detectionPolicySchema.partial().optional(),
|
|
362
|
+
diagnostics: diagnosticsPolicySchema.partial().optional()
|
|
363
|
+
});
|
|
364
|
+
var DEFAULT_EXPORTER_POLICY = Object.freeze({
|
|
365
|
+
enabled: true,
|
|
366
|
+
protocol: "http/protobuf",
|
|
367
|
+
headerNames: Object.freeze([]),
|
|
368
|
+
timeoutMillis: 1e4,
|
|
369
|
+
maxBatchSize: 128,
|
|
370
|
+
maxQueueSize: 2048,
|
|
371
|
+
maxRetryAttempts: 2,
|
|
372
|
+
serviceName: "coding-agent",
|
|
373
|
+
resourceAttributes: EMPTY_RESOURCE_ATTRIBUTES,
|
|
374
|
+
logs: DEFAULT_LOGS_POLICY
|
|
375
|
+
});
|
|
376
|
+
var DEFAULT_DETECTION_POLICY = Object.freeze({
|
|
377
|
+
minimumConfidence: "strong",
|
|
378
|
+
allowAmbiguousFallback: true,
|
|
379
|
+
allowedProviderIds: Object.freeze([])
|
|
380
|
+
});
|
|
381
|
+
var DEFAULT_DIAGNOSTICS_POLICY = Object.freeze({
|
|
382
|
+
logLevel: "warn",
|
|
383
|
+
emitErrorEvents: true
|
|
384
|
+
});
|
|
385
|
+
var DEFAULT_CONFIG = Object.freeze({
|
|
386
|
+
exporter: DEFAULT_EXPORTER_POLICY,
|
|
387
|
+
privacy: DEFAULT_PRIVACY_POLICY,
|
|
388
|
+
detection: DEFAULT_DETECTION_POLICY,
|
|
389
|
+
diagnostics: DEFAULT_DIAGNOSTICS_POLICY
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
// src/config/resolve.ts
|
|
393
|
+
import { z as z7 } from "zod";
|
|
394
|
+
|
|
395
|
+
// src/errors/index.ts
|
|
396
|
+
import { z as z6 } from "zod";
|
|
397
|
+
|
|
398
|
+
// src/errors/taxonomy.ts
|
|
399
|
+
import { z as z5 } from "zod";
|
|
400
|
+
var otelHookErrorCodeSchema = z5.enum([
|
|
401
|
+
/** Input was not usable at all (empty stdin, unparsable JSON). */
|
|
402
|
+
"invalid-input",
|
|
403
|
+
/** Input parsed but failed canonical schema validation. */
|
|
404
|
+
"schema-validation-failed",
|
|
405
|
+
/** No adapter claimed the input with sufficient confidence. */
|
|
406
|
+
"provider-unknown",
|
|
407
|
+
/** Several adapters claimed the input at the same confidence. */
|
|
408
|
+
"provider-detection-ambiguous",
|
|
409
|
+
/** An adapter threw or returned a malformed result. */
|
|
410
|
+
"provider-adapter-failure",
|
|
411
|
+
/** Two identity claims disagreed at equal confidence. */
|
|
412
|
+
"identity-conflict",
|
|
413
|
+
/** Required identity fields were absent. */
|
|
414
|
+
"identity-incomplete",
|
|
415
|
+
/** A usage report violated the canonical usage invariants. */
|
|
416
|
+
"usage-invalid",
|
|
417
|
+
/** The state store could not be read or written. */
|
|
418
|
+
"state-store-failure",
|
|
419
|
+
/** The telemetry sink rejected or could not deliver a batch. */
|
|
420
|
+
"telemetry-export-failure",
|
|
421
|
+
/** Content reached the sink boundary in a state the policy forbids. */
|
|
422
|
+
"privacy-policy-violation",
|
|
423
|
+
/** Configuration could not be resolved. */
|
|
424
|
+
"configuration-invalid",
|
|
425
|
+
/** A configured bound (events, batch size) dropped data. */
|
|
426
|
+
"limit-exceeded",
|
|
427
|
+
/**
|
|
428
|
+
* No replay-stable delivery identifier was available for a callback while
|
|
429
|
+
* deduplication was required.
|
|
430
|
+
*/
|
|
431
|
+
"delivery-identifier-unavailable",
|
|
432
|
+
"delivery-claim-superseded",
|
|
433
|
+
/** Anything unanticipated. Always reported, never fatal to the host. */
|
|
434
|
+
"internal-error"
|
|
435
|
+
]);
|
|
436
|
+
var errorSeveritySchema = z5.enum(["warning", "error"]);
|
|
437
|
+
var errorPhaseSchema = z5.enum([
|
|
438
|
+
"configuration",
|
|
439
|
+
"detection",
|
|
440
|
+
"identity",
|
|
441
|
+
"parsing",
|
|
442
|
+
"normalization",
|
|
443
|
+
"privacy",
|
|
444
|
+
"state",
|
|
445
|
+
"export",
|
|
446
|
+
"shutdown"
|
|
447
|
+
]);
|
|
448
|
+
var failurePostureSchema = z5.enum(["fail-open", "fail-closed-attribution"]);
|
|
449
|
+
var ERROR_TAXONOMY = Object.freeze({
|
|
450
|
+
"invalid-input": {
|
|
451
|
+
code: "invalid-input",
|
|
452
|
+
severity: "warning",
|
|
453
|
+
posture: "fail-open",
|
|
454
|
+
retryable: false,
|
|
455
|
+
summary: "Input could not be read or decoded."
|
|
456
|
+
},
|
|
457
|
+
"schema-validation-failed": {
|
|
458
|
+
code: "schema-validation-failed",
|
|
459
|
+
severity: "error",
|
|
460
|
+
posture: "fail-closed-attribution",
|
|
461
|
+
retryable: false,
|
|
462
|
+
summary: "A canonical event failed schema validation and was dropped."
|
|
463
|
+
},
|
|
464
|
+
"provider-unknown": {
|
|
465
|
+
code: "provider-unknown",
|
|
466
|
+
severity: "warning",
|
|
467
|
+
posture: "fail-closed-attribution",
|
|
468
|
+
retryable: false,
|
|
469
|
+
summary: "No adapter recognized the source provider; the input stays unattributed."
|
|
470
|
+
},
|
|
471
|
+
"provider-detection-ambiguous": {
|
|
472
|
+
code: "provider-detection-ambiguous",
|
|
473
|
+
severity: "warning",
|
|
474
|
+
posture: "fail-closed-attribution",
|
|
475
|
+
retryable: false,
|
|
476
|
+
summary: "Multiple adapters claimed the input at equal confidence."
|
|
477
|
+
},
|
|
478
|
+
"provider-adapter-failure": {
|
|
479
|
+
code: "provider-adapter-failure",
|
|
480
|
+
severity: "error",
|
|
481
|
+
posture: "fail-open",
|
|
482
|
+
retryable: false,
|
|
483
|
+
summary: "A provider adapter failed while parsing."
|
|
484
|
+
},
|
|
485
|
+
"identity-conflict": {
|
|
486
|
+
code: "identity-conflict",
|
|
487
|
+
severity: "error",
|
|
488
|
+
posture: "fail-closed-attribution",
|
|
489
|
+
retryable: false,
|
|
490
|
+
summary: "Identity claims disagreed; attribution was declined."
|
|
491
|
+
},
|
|
492
|
+
"identity-incomplete": {
|
|
493
|
+
code: "identity-incomplete",
|
|
494
|
+
severity: "warning",
|
|
495
|
+
posture: "fail-closed-attribution",
|
|
496
|
+
retryable: false,
|
|
497
|
+
summary: "Required identity fields were missing; attribution was declined."
|
|
498
|
+
},
|
|
499
|
+
"usage-invalid": {
|
|
500
|
+
code: "usage-invalid",
|
|
501
|
+
severity: "error",
|
|
502
|
+
posture: "fail-open",
|
|
503
|
+
retryable: false,
|
|
504
|
+
summary: "A usage report violated the canonical usage invariants."
|
|
505
|
+
},
|
|
506
|
+
"state-store-failure": {
|
|
507
|
+
code: "state-store-failure",
|
|
508
|
+
severity: "warning",
|
|
509
|
+
posture: "fail-open",
|
|
510
|
+
retryable: true,
|
|
511
|
+
summary: "State could not be read or written; derived values may be incomplete."
|
|
512
|
+
},
|
|
513
|
+
"telemetry-export-failure": {
|
|
514
|
+
code: "telemetry-export-failure",
|
|
515
|
+
severity: "warning",
|
|
516
|
+
posture: "fail-open",
|
|
517
|
+
retryable: true,
|
|
518
|
+
summary: "The telemetry sink could not accept a batch."
|
|
519
|
+
},
|
|
520
|
+
"privacy-policy-violation": {
|
|
521
|
+
code: "privacy-policy-violation",
|
|
522
|
+
severity: "error",
|
|
523
|
+
posture: "fail-closed-attribution",
|
|
524
|
+
retryable: false,
|
|
525
|
+
summary: "Content violated the resolved privacy policy and was dropped."
|
|
526
|
+
},
|
|
527
|
+
"configuration-invalid": {
|
|
528
|
+
code: "configuration-invalid",
|
|
529
|
+
severity: "error",
|
|
530
|
+
posture: "fail-open",
|
|
531
|
+
retryable: false,
|
|
532
|
+
summary: "Configuration could not be resolved; defaults apply."
|
|
533
|
+
},
|
|
534
|
+
"limit-exceeded": {
|
|
535
|
+
code: "limit-exceeded",
|
|
536
|
+
severity: "warning",
|
|
537
|
+
posture: "fail-open",
|
|
538
|
+
retryable: false,
|
|
539
|
+
summary: "A configured bound was reached and data was dropped."
|
|
540
|
+
},
|
|
541
|
+
"delivery-identifier-unavailable": {
|
|
542
|
+
code: "delivery-identifier-unavailable",
|
|
543
|
+
severity: "warning",
|
|
544
|
+
// Fail-open: the observation is still attributed and exported. Only the
|
|
545
|
+
// at-most-once guarantee is missing, and refusing the telemetry to protect
|
|
546
|
+
// a duplicate count would trade a certain loss for a possible one.
|
|
547
|
+
posture: "fail-open",
|
|
548
|
+
retryable: false,
|
|
549
|
+
summary: "No replay-stable delivery identifier was available; this callback was exported without deduplication."
|
|
550
|
+
},
|
|
551
|
+
"delivery-claim-superseded": {
|
|
552
|
+
code: "delivery-claim-superseded",
|
|
553
|
+
severity: "warning",
|
|
554
|
+
// Fail-open, and specifically *not* silent. A peer reclaimed this callback's
|
|
555
|
+
// claim while this process was still working on it, which means the
|
|
556
|
+
// configured stale window is shorter than this installation's real worst
|
|
557
|
+
// case. Both processes may now have exported the callback, so the
|
|
558
|
+
// at-most-once guarantee did not hold for it — the only honest response is
|
|
559
|
+
// to say so and let the operator raise the window.
|
|
560
|
+
posture: "fail-open",
|
|
561
|
+
retryable: false,
|
|
562
|
+
summary: "A delivery claim was reclaimed by another process before this one committed; the callback may have been exported twice."
|
|
563
|
+
},
|
|
564
|
+
"internal-error": {
|
|
565
|
+
code: "internal-error",
|
|
566
|
+
severity: "error",
|
|
567
|
+
posture: "fail-open",
|
|
568
|
+
retryable: false,
|
|
569
|
+
summary: "An unexpected failure was contained."
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
var describeErrorCode = (code) => ERROR_TAXONOMY[code];
|
|
573
|
+
var attributionOutcomeSchema = z5.enum([
|
|
574
|
+
/** Identity resolved; events carry provider and session identity. */
|
|
575
|
+
"attributed",
|
|
576
|
+
/** Identity could not be established safely; nothing was attributed. */
|
|
577
|
+
"declined",
|
|
578
|
+
/** Attribution was attempted and failed unexpectedly. */
|
|
579
|
+
"failed",
|
|
580
|
+
/** Input was recognized but intentionally carried no telemetry. */
|
|
581
|
+
"not-applicable"
|
|
582
|
+
]);
|
|
583
|
+
var attributionReasonSchema = z5.enum([
|
|
584
|
+
"provider-unknown",
|
|
585
|
+
"provider-detection-ambiguous",
|
|
586
|
+
"identity-conflict",
|
|
587
|
+
"identity-incomplete",
|
|
588
|
+
"adapter-ignored-input",
|
|
589
|
+
"adapter-failure",
|
|
590
|
+
"invalid-input",
|
|
591
|
+
"internal-error"
|
|
592
|
+
]);
|
|
593
|
+
|
|
594
|
+
// src/errors/index.ts
|
|
595
|
+
var otelHookErrorInfoSchema = z6.strictObject({
|
|
596
|
+
code: otelHookErrorCodeSchema,
|
|
597
|
+
severity: errorSeveritySchema,
|
|
598
|
+
phase: errorPhaseSchema,
|
|
599
|
+
posture: failurePostureSchema,
|
|
600
|
+
retryable: z6.boolean(),
|
|
601
|
+
message: z6.string().min(1).max(512),
|
|
602
|
+
details: attributesSchema.optional(),
|
|
603
|
+
occurredAt: epochMillisSchema.optional()
|
|
604
|
+
});
|
|
605
|
+
var createErrorInfo = (input) => {
|
|
606
|
+
const descriptor = describeErrorCode(input.code);
|
|
607
|
+
const message = input.detail === void 0 ? `${input.code} during ${input.phase}: ${descriptor.summary}` : `${input.code} during ${input.phase}: ${input.detail}`;
|
|
608
|
+
return otelHookErrorInfoSchema.parse({
|
|
609
|
+
code: descriptor.code,
|
|
610
|
+
severity: descriptor.severity,
|
|
611
|
+
phase: input.phase,
|
|
612
|
+
posture: descriptor.posture,
|
|
613
|
+
retryable: descriptor.retryable,
|
|
614
|
+
message: message.slice(0, 512),
|
|
615
|
+
...input.details === void 0 ? {} : { details: input.details },
|
|
616
|
+
...input.occurredAt === void 0 ? {} : { occurredAt: input.occurredAt }
|
|
617
|
+
});
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
// src/config/resolve.ts
|
|
621
|
+
var CONFIG_SOURCE_PRECEDENCE = ["defaults", "file", "environment", "inline-override"];
|
|
622
|
+
var configSourceSchema = z7.enum(CONFIG_SOURCE_PRECEDENCE);
|
|
623
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
624
|
+
var mergeLeaf = (target, patch, source, provenance, path) => {
|
|
625
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
626
|
+
if (value === void 0) {
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
const childPath = path === "" ? key : `${path}.${key}`;
|
|
630
|
+
const existing = target[key];
|
|
631
|
+
if (isPlainObject(value) && isPlainObject(existing)) {
|
|
632
|
+
const child = { ...existing };
|
|
633
|
+
mergeLeaf(child, value, source, provenance, childPath);
|
|
634
|
+
target[key] = child;
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
target[key] = value;
|
|
638
|
+
provenance[childPath] = source;
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
var initialProvenance = (config) => {
|
|
642
|
+
const provenance = {};
|
|
643
|
+
const walk = (value, path) => {
|
|
644
|
+
if (isPlainObject(value)) {
|
|
645
|
+
for (const [key, child] of Object.entries(value)) {
|
|
646
|
+
walk(child, path === "" ? key : `${path}.${key}`);
|
|
647
|
+
}
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
provenance[path] = "defaults";
|
|
651
|
+
};
|
|
652
|
+
walk(config, "");
|
|
653
|
+
return provenance;
|
|
654
|
+
};
|
|
655
|
+
var resolveConfig = (layers = []) => {
|
|
656
|
+
const errors = [];
|
|
657
|
+
const ordered = [...layers].sort(
|
|
658
|
+
(a, b) => CONFIG_SOURCE_PRECEDENCE.indexOf(a.source) - CONFIG_SOURCE_PRECEDENCE.indexOf(b.source)
|
|
659
|
+
);
|
|
660
|
+
const validated = [];
|
|
661
|
+
for (const layer of ordered) {
|
|
662
|
+
const parsed2 = otelHookConfigPatchSchema.safeParse(layer.patch);
|
|
663
|
+
if (!parsed2.success) {
|
|
664
|
+
errors.push(
|
|
665
|
+
createErrorInfo({
|
|
666
|
+
code: "configuration-invalid",
|
|
667
|
+
phase: "configuration",
|
|
668
|
+
detail: `layer ${layer.source} rejected: ${parsed2.error.issues.map((issue) => `${issue.path.join(".") || "<root>"} ${issue.message}`).join("; ")}`.slice(0, 480),
|
|
669
|
+
details: {
|
|
670
|
+
"config.layer": layer.source,
|
|
671
|
+
...layer.origin === void 0 ? {} : { "config.origin": layer.origin }
|
|
672
|
+
}
|
|
673
|
+
})
|
|
674
|
+
);
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
validated.push({ source: layer.source, patch: parsed2.data });
|
|
678
|
+
}
|
|
679
|
+
if (errors.length > 0) {
|
|
680
|
+
return { status: "invalid", errors };
|
|
681
|
+
}
|
|
682
|
+
const merged = structuredClone(DEFAULT_CONFIG);
|
|
683
|
+
const provenance = initialProvenance(DEFAULT_CONFIG);
|
|
684
|
+
for (const layer of validated) {
|
|
685
|
+
mergeLeaf(merged, layer.patch, layer.source, provenance, "");
|
|
686
|
+
}
|
|
687
|
+
const parsed = otelHookConfigSchema.safeParse(merged);
|
|
688
|
+
if (!parsed.success) {
|
|
689
|
+
return {
|
|
690
|
+
status: "invalid",
|
|
691
|
+
errors: [
|
|
692
|
+
createErrorInfo({
|
|
693
|
+
code: "configuration-invalid",
|
|
694
|
+
phase: "configuration",
|
|
695
|
+
detail: `merged configuration rejected: ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "<root>"} ${issue.message}`).join("; ")}`.slice(0, 480)
|
|
696
|
+
})
|
|
697
|
+
]
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
const notes = [];
|
|
701
|
+
if (parsed.data.privacy.contentMode === "raw" && !parsed.data.privacy.allowRawContent) {
|
|
702
|
+
notes.push("privacy.contentMode=raw will be downgraded to omit: allowRawContent is false");
|
|
703
|
+
}
|
|
704
|
+
if (parsed.data.exporter.enabled && parsed.data.exporter.protocol !== "none" && parsed.data.exporter.endpoint === void 0) {
|
|
705
|
+
notes.push("exporter.enabled is true but no endpoint is configured");
|
|
706
|
+
}
|
|
707
|
+
if (parsed.data.exporter.logs.enabled && parsed.data.exporter.logs.endpoint === void 0 && parsed.data.exporter.endpoint === void 0) {
|
|
708
|
+
notes.push(
|
|
709
|
+
"exporter.logs.enabled is true but neither a logs endpoint nor a trace endpoint to derive one from is configured"
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
if (parsed.data.exporter.logs.includeContent && parsed.data.privacy.contentMode === "omit") {
|
|
713
|
+
notes.push(
|
|
714
|
+
"exporter.logs.includeContent is true but privacy.contentMode is omit, so no content is disclosed to describe"
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
return { status: "ok", config: parsed.data, provenance, notes };
|
|
718
|
+
};
|
|
719
|
+
var describeResolvedConfig = (config) => {
|
|
720
|
+
const originOf = (endpoint) => {
|
|
721
|
+
if (endpoint === void 0) {
|
|
722
|
+
return void 0;
|
|
723
|
+
}
|
|
724
|
+
try {
|
|
725
|
+
return new URL(endpoint).origin;
|
|
726
|
+
} catch {
|
|
727
|
+
return "<unparsable>";
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
const endpointOrigin = originOf(config.exporter.endpoint);
|
|
731
|
+
const logsEndpointOrigin = originOf(config.exporter.logs.endpoint);
|
|
732
|
+
return {
|
|
733
|
+
"exporter.enabled": config.exporter.enabled,
|
|
734
|
+
"exporter.protocol": config.exporter.protocol,
|
|
735
|
+
...endpointOrigin === void 0 ? {} : { "exporter.endpoint_origin": endpointOrigin },
|
|
736
|
+
"exporter.logs_enabled": config.exporter.logs.enabled,
|
|
737
|
+
"exporter.logs_include_content": config.exporter.logs.includeContent,
|
|
738
|
+
"exporter.logs_max_batch_size": config.exporter.logs.maxBatchSize,
|
|
739
|
+
...logsEndpointOrigin === void 0 ? {} : { "exporter.logs_endpoint_origin": logsEndpointOrigin },
|
|
740
|
+
"exporter.header_names": [...config.exporter.headerNames],
|
|
741
|
+
// Names only. A resource attribute *name* is already on the wire in every
|
|
742
|
+
// exported resource, so disclosing it here adds nothing; a *value* may hold
|
|
743
|
+
// whatever an operator put in a shell profile, so it never appears.
|
|
744
|
+
"exporter.resource_attribute_names": [
|
|
745
|
+
...describeResourceAttributeNames(config.exporter.resourceAttributes)
|
|
746
|
+
],
|
|
747
|
+
"exporter.timeout_millis": config.exporter.timeoutMillis,
|
|
748
|
+
"exporter.max_batch_size": config.exporter.maxBatchSize,
|
|
749
|
+
"exporter.service_name": config.exporter.serviceName,
|
|
750
|
+
"privacy.content_mode": config.privacy.contentMode,
|
|
751
|
+
"privacy.allow_raw_content": config.privacy.allowRawContent,
|
|
752
|
+
"privacy.hash_salted": config.privacy.hashSalt.length > 0,
|
|
753
|
+
"privacy.max_string_length": config.privacy.limits.maxStringLength,
|
|
754
|
+
"privacy.max_depth": config.privacy.limits.maxDepth,
|
|
755
|
+
"privacy.max_array_length": config.privacy.limits.maxArrayLength,
|
|
756
|
+
"privacy.max_events_per_invocation": config.privacy.limits.maxEventsPerInvocation,
|
|
757
|
+
"detection.minimum_confidence": config.detection.minimumConfidence,
|
|
758
|
+
"detection.allow_ambiguous_fallback": config.detection.allowAmbiguousFallback,
|
|
759
|
+
"diagnostics.log_level": config.diagnostics.logLevel,
|
|
760
|
+
"diagnostics.emit_error_events": config.diagnostics.emitErrorEvents
|
|
761
|
+
};
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
// src/config/environment.ts
|
|
765
|
+
var ENVIRONMENT_VARIABLES = Object.freeze({
|
|
766
|
+
exporterEnabled: "OTEL_HOOK_ENABLED",
|
|
767
|
+
exporterEndpoint: "OTEL_HOOK_EXPORTER_ENDPOINT",
|
|
768
|
+
otlpEndpoint: "OTEL_EXPORTER_OTLP_ENDPOINT",
|
|
769
|
+
exporterProtocol: "OTEL_HOOK_EXPORTER_PROTOCOL",
|
|
770
|
+
exporterTimeoutMillis: "OTEL_HOOK_EXPORTER_TIMEOUT_MS",
|
|
771
|
+
logsEnabled: "OTEL_HOOK_LOGS_ENABLED",
|
|
772
|
+
logsEndpoint: "OTEL_HOOK_LOGS_ENDPOINT",
|
|
773
|
+
/** Standard per-signal endpoint; the weaker source of the two. */
|
|
774
|
+
otlpLogsEndpoint: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT",
|
|
775
|
+
logsIncludeContent: "OTEL_HOOK_LOGS_INCLUDE_CONTENT",
|
|
776
|
+
serviceName: "OTEL_HOOK_SERVICE_NAME",
|
|
777
|
+
otlpServiceName: "OTEL_SERVICE_NAME",
|
|
778
|
+
serviceNamespace: "OTEL_HOOK_SERVICE_NAMESPACE",
|
|
779
|
+
/** Standard W3C-Baggage-encoded resource attributes (percent-encoded values). */
|
|
780
|
+
resourceAttributes: "OTEL_RESOURCE_ATTRIBUTES",
|
|
781
|
+
contentMode: "OTEL_HOOK_CONTENT_MODE",
|
|
782
|
+
allowRawContent: "OTEL_HOOK_ALLOW_RAW_CONTENT",
|
|
783
|
+
hashSalt: "OTEL_HOOK_HASH_SALT",
|
|
784
|
+
maxStringLength: "OTEL_HOOK_MAX_STRING_LENGTH",
|
|
785
|
+
maxDepth: "OTEL_HOOK_MAX_DEPTH",
|
|
786
|
+
maxArrayLength: "OTEL_HOOK_MAX_ARRAY_LENGTH",
|
|
787
|
+
maxEventsPerInvocation: "OTEL_HOOK_MAX_EVENTS_PER_INVOCATION",
|
|
788
|
+
minimumConfidence: "OTEL_HOOK_MIN_DETECTION_CONFIDENCE",
|
|
789
|
+
logLevel: "OTEL_HOOK_LOG_LEVEL"
|
|
790
|
+
});
|
|
791
|
+
var BOOLEAN_TRUE = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
|
|
792
|
+
var BOOLEAN_FALSE = /* @__PURE__ */ new Set(["0", "false", "no", "off"]);
|
|
793
|
+
var parseEnvironmentConfig = (env) => {
|
|
794
|
+
const warnings = [];
|
|
795
|
+
const warn = (variable, detail) => {
|
|
796
|
+
warnings.push(
|
|
797
|
+
createErrorInfo({
|
|
798
|
+
code: "configuration-invalid",
|
|
799
|
+
phase: "configuration",
|
|
800
|
+
detail: `${variable}: ${detail}`,
|
|
801
|
+
details: { "config.variable": variable }
|
|
802
|
+
})
|
|
803
|
+
);
|
|
804
|
+
};
|
|
805
|
+
const readBoolean = (variable) => {
|
|
806
|
+
const raw = env[variable];
|
|
807
|
+
if (raw === void 0 || raw === "") {
|
|
808
|
+
return void 0;
|
|
809
|
+
}
|
|
810
|
+
const normalized = raw.trim().toLowerCase();
|
|
811
|
+
if (BOOLEAN_TRUE.has(normalized)) {
|
|
812
|
+
return true;
|
|
813
|
+
}
|
|
814
|
+
if (BOOLEAN_FALSE.has(normalized)) {
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
817
|
+
warn(variable, "expected a boolean");
|
|
818
|
+
return void 0;
|
|
819
|
+
};
|
|
820
|
+
const readInteger = (variable) => {
|
|
821
|
+
const raw = env[variable];
|
|
822
|
+
if (raw === void 0 || raw === "") {
|
|
823
|
+
return void 0;
|
|
824
|
+
}
|
|
825
|
+
const value = Number(raw.trim());
|
|
826
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
827
|
+
warn(variable, "expected a non-negative integer");
|
|
828
|
+
return void 0;
|
|
829
|
+
}
|
|
830
|
+
return value;
|
|
831
|
+
};
|
|
832
|
+
const readString = (variable) => {
|
|
833
|
+
const raw = env[variable];
|
|
834
|
+
if (raw === void 0) {
|
|
835
|
+
return void 0;
|
|
836
|
+
}
|
|
837
|
+
const trimmed = raw.trim();
|
|
838
|
+
return trimmed === "" ? void 0 : trimmed;
|
|
839
|
+
};
|
|
840
|
+
const exporterEnabled = readBoolean(ENVIRONMENT_VARIABLES.exporterEnabled);
|
|
841
|
+
const endpoint = readString(ENVIRONMENT_VARIABLES.exporterEndpoint) ?? readString(ENVIRONMENT_VARIABLES.otlpEndpoint);
|
|
842
|
+
const timeoutMillis = readInteger(ENVIRONMENT_VARIABLES.exporterTimeoutMillis);
|
|
843
|
+
const resourceRaw = readString(ENVIRONMENT_VARIABLES.resourceAttributes);
|
|
844
|
+
const resource = resourceRaw === void 0 ? void 0 : parseResourceAttributesValue(resourceRaw);
|
|
845
|
+
for (const detail of resource?.warnings ?? []) {
|
|
846
|
+
warn(ENVIRONMENT_VARIABLES.resourceAttributes, detail);
|
|
847
|
+
}
|
|
848
|
+
const resourceAttributes = resource?.attributes ?? {};
|
|
849
|
+
const resolveServiceField = (sources) => {
|
|
850
|
+
const present = sources.filter(
|
|
851
|
+
(source) => source.value !== void 0
|
|
852
|
+
);
|
|
853
|
+
const winner = present[0];
|
|
854
|
+
if (winner === void 0) {
|
|
855
|
+
return void 0;
|
|
856
|
+
}
|
|
857
|
+
for (const loser of present.slice(1)) {
|
|
858
|
+
if (loser.value !== winner.value) {
|
|
859
|
+
warn(loser.variable, `overridden by ${winner.variable}, which sets a different value`);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return winner.value;
|
|
863
|
+
};
|
|
864
|
+
const serviceName = resolveServiceField([
|
|
865
|
+
{ variable: ENVIRONMENT_VARIABLES.serviceName, value: readString(ENVIRONMENT_VARIABLES.serviceName) },
|
|
866
|
+
{
|
|
867
|
+
variable: ENVIRONMENT_VARIABLES.otlpServiceName,
|
|
868
|
+
value: readString(ENVIRONMENT_VARIABLES.otlpServiceName)
|
|
869
|
+
},
|
|
870
|
+
{
|
|
871
|
+
variable: `service.name in ${ENVIRONMENT_VARIABLES.resourceAttributes}`,
|
|
872
|
+
value: resource?.serviceName
|
|
873
|
+
}
|
|
874
|
+
]);
|
|
875
|
+
const serviceNamespace = resolveServiceField([
|
|
876
|
+
{
|
|
877
|
+
variable: ENVIRONMENT_VARIABLES.serviceNamespace,
|
|
878
|
+
value: readString(ENVIRONMENT_VARIABLES.serviceNamespace)
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
variable: `service.namespace in ${ENVIRONMENT_VARIABLES.resourceAttributes}`,
|
|
882
|
+
value: resource?.serviceNamespace
|
|
883
|
+
}
|
|
884
|
+
]);
|
|
885
|
+
const protocolRaw = readString(ENVIRONMENT_VARIABLES.exporterProtocol);
|
|
886
|
+
let protocol;
|
|
887
|
+
if (protocolRaw !== void 0) {
|
|
888
|
+
if (protocolRaw === "http/protobuf" || protocolRaw === "http/json" || protocolRaw === "none") {
|
|
889
|
+
protocol = protocolRaw;
|
|
890
|
+
} else {
|
|
891
|
+
warn(ENVIRONMENT_VARIABLES.exporterProtocol, "expected http/protobuf, http/json, or none");
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
const contentModeRaw = readString(ENVIRONMENT_VARIABLES.contentMode);
|
|
895
|
+
const contentModeParsed = contentModeRaw === void 0 ? void 0 : contentModeSchema.safeParse(contentModeRaw);
|
|
896
|
+
if (contentModeParsed !== void 0 && !contentModeParsed.success) {
|
|
897
|
+
warn(ENVIRONMENT_VARIABLES.contentMode, "expected omit, mask, redact, or raw");
|
|
898
|
+
}
|
|
899
|
+
const confidenceRaw = readString(ENVIRONMENT_VARIABLES.minimumConfidence);
|
|
900
|
+
const confidenceParsed = confidenceRaw === void 0 ? void 0 : detectionConfidenceSchema.safeParse(confidenceRaw);
|
|
901
|
+
if (confidenceParsed !== void 0 && !confidenceParsed.success) {
|
|
902
|
+
warn(ENVIRONMENT_VARIABLES.minimumConfidence, "expected none, weak, strong, or exact");
|
|
903
|
+
}
|
|
904
|
+
const logLevelRaw = readString(ENVIRONMENT_VARIABLES.logLevel);
|
|
905
|
+
const logLevels = ["silent", "error", "warn", "info", "debug"];
|
|
906
|
+
let logLevel;
|
|
907
|
+
if (logLevelRaw !== void 0) {
|
|
908
|
+
const match = logLevels.find((level) => level === logLevelRaw);
|
|
909
|
+
if (match === void 0) {
|
|
910
|
+
warn(ENVIRONMENT_VARIABLES.logLevel, `expected one of ${logLevels.join(", ")}`);
|
|
911
|
+
} else {
|
|
912
|
+
logLevel = match;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
const allowRawContent = readBoolean(ENVIRONMENT_VARIABLES.allowRawContent);
|
|
916
|
+
const hashSalt = readString(ENVIRONMENT_VARIABLES.hashSalt);
|
|
917
|
+
const maxStringLength = readInteger(ENVIRONMENT_VARIABLES.maxStringLength);
|
|
918
|
+
const maxDepth = readInteger(ENVIRONMENT_VARIABLES.maxDepth);
|
|
919
|
+
const maxArrayLength = readInteger(ENVIRONMENT_VARIABLES.maxArrayLength);
|
|
920
|
+
const maxEventsPerInvocation = readInteger(ENVIRONMENT_VARIABLES.maxEventsPerInvocation);
|
|
921
|
+
const logsEnabled = readBoolean(ENVIRONMENT_VARIABLES.logsEnabled);
|
|
922
|
+
const logsIncludeContent = readBoolean(ENVIRONMENT_VARIABLES.logsIncludeContent);
|
|
923
|
+
const logsEndpoint = readString(ENVIRONMENT_VARIABLES.logsEndpoint) ?? readString(ENVIRONMENT_VARIABLES.otlpLogsEndpoint);
|
|
924
|
+
const logs = {
|
|
925
|
+
...logsEnabled === void 0 ? {} : { enabled: logsEnabled },
|
|
926
|
+
...logsEndpoint === void 0 ? {} : { endpoint: logsEndpoint },
|
|
927
|
+
...logsIncludeContent === void 0 ? {} : { includeContent: logsIncludeContent }
|
|
928
|
+
};
|
|
929
|
+
const exporter = {
|
|
930
|
+
...exporterEnabled === void 0 ? {} : { enabled: exporterEnabled },
|
|
931
|
+
...endpoint === void 0 ? {} : { endpoint },
|
|
932
|
+
...protocol === void 0 ? {} : { protocol },
|
|
933
|
+
...timeoutMillis === void 0 ? {} : { timeoutMillis },
|
|
934
|
+
...serviceName === void 0 ? {} : { serviceName },
|
|
935
|
+
...serviceNamespace === void 0 ? {} : { serviceNamespace },
|
|
936
|
+
...Object.keys(resourceAttributes).length === 0 ? {} : { resourceAttributes },
|
|
937
|
+
...Object.keys(logs).length === 0 ? {} : { logs }
|
|
938
|
+
};
|
|
939
|
+
const limits = {
|
|
940
|
+
...maxStringLength === void 0 ? {} : { maxStringLength },
|
|
941
|
+
...maxDepth === void 0 ? {} : { maxDepth },
|
|
942
|
+
...maxArrayLength === void 0 ? {} : { maxArrayLength },
|
|
943
|
+
...maxEventsPerInvocation === void 0 ? {} : { maxEventsPerInvocation }
|
|
944
|
+
};
|
|
945
|
+
const privacy = {
|
|
946
|
+
...contentModeParsed?.success === true ? { contentMode: contentModeParsed.data } : {},
|
|
947
|
+
...allowRawContent === void 0 ? {} : { allowRawContent },
|
|
948
|
+
...hashSalt === void 0 ? {} : { hashSalt },
|
|
949
|
+
...Object.keys(limits).length === 0 ? {} : { limits }
|
|
950
|
+
};
|
|
951
|
+
const detection = confidenceParsed?.success === true ? { minimumConfidence: confidenceParsed.data } : {};
|
|
952
|
+
const diagnostics = logLevel === void 0 ? {} : { logLevel };
|
|
953
|
+
const patch = {
|
|
954
|
+
...Object.keys(exporter).length === 0 ? {} : { exporter },
|
|
955
|
+
...Object.keys(privacy).length === 0 ? {} : { privacy },
|
|
956
|
+
...Object.keys(detection).length === 0 ? {} : { detection },
|
|
957
|
+
...Object.keys(diagnostics).length === 0 ? {} : { diagnostics }
|
|
958
|
+
};
|
|
959
|
+
return { patch, warnings };
|
|
960
|
+
};
|
|
961
|
+
export {
|
|
962
|
+
CONFIG_SOURCE_PRECEDENCE,
|
|
963
|
+
DEFAULT_CONFIG,
|
|
964
|
+
DEFAULT_DETECTION_POLICY,
|
|
965
|
+
DEFAULT_DIAGNOSTICS_POLICY,
|
|
966
|
+
DEFAULT_EXPORTER_POLICY,
|
|
967
|
+
DEFAULT_LOGS_POLICY,
|
|
968
|
+
EMPTY_RESOURCE_ATTRIBUTES,
|
|
969
|
+
ENVIRONMENT_VARIABLES,
|
|
970
|
+
MAX_RESOURCE_ATTRIBUTES,
|
|
971
|
+
MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH,
|
|
972
|
+
MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH,
|
|
973
|
+
RESERVED_RESOURCE_ATTRIBUTE_KEYS,
|
|
974
|
+
RESOURCE_ATTRIBUTE_KEY_PATTERN,
|
|
975
|
+
RESOURCE_ATTRIBUTE_KEY_REJECTION_DETAIL,
|
|
976
|
+
checkResourceAttributeKey,
|
|
977
|
+
configSourceSchema,
|
|
978
|
+
contentModeSchema,
|
|
979
|
+
describeResolvedConfig,
|
|
980
|
+
describeResourceAttributeNames,
|
|
981
|
+
detectionPolicySchema,
|
|
982
|
+
diagnosticsPolicySchema,
|
|
983
|
+
exporterPolicySchema,
|
|
984
|
+
isReservedResourceAttributeKey,
|
|
985
|
+
isSecretResourceAttributeKey,
|
|
986
|
+
logsPolicySchema,
|
|
987
|
+
otelHookConfigPatchSchema,
|
|
988
|
+
otelHookConfigSchema,
|
|
989
|
+
parseEnvironmentConfig,
|
|
990
|
+
parseResourceAttributesValue,
|
|
991
|
+
resolveConfig,
|
|
992
|
+
resourceAttributeValueSchema,
|
|
993
|
+
resourceAttributesSchema,
|
|
994
|
+
sanitizeResourceAttributes
|
|
995
|
+
};
|
|
996
|
+
//# sourceMappingURL=config.js.map
|