@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.d.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { g as OtelHookConfigPatch, O as OtelHookConfig } from './schema-Cn0-xz8L.js';
|
|
3
|
+
export { D as DEFAULT_CONFIG, a as DEFAULT_DETECTION_POLICY, b as DEFAULT_DIAGNOSTICS_POLICY, c as DEFAULT_EXPORTER_POLICY, d as DEFAULT_LOGS_POLICY, e as DetectionPolicy, f as DiagnosticsPolicy, E as ExporterPolicy, L as LogsPolicy, h as detectionPolicySchema, i as diagnosticsPolicySchema, j as exporterPolicySchema, l as logsPolicySchema, o as otelHookConfigPatchSchema, k as otelHookConfigSchema } from './schema-Cn0-xz8L.js';
|
|
4
|
+
import { OtelHookErrorInfo } from './errors.js';
|
|
5
|
+
import { b as Attributes } from './primitives-CJ8-rn-f.js';
|
|
6
|
+
export { g as contentModeSchema } from './policy-D1CrlYn3.js';
|
|
7
|
+
import './taxonomy-DwhTtuWd.js';
|
|
8
|
+
import './content-CoB7aNP1.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Custom OTLP **resource** attributes: facts about the emitting deployment
|
|
12
|
+
* (`deployment.environment`, `service.instance.id`, a tenant label) that belong
|
|
13
|
+
* on every span this installation exports.
|
|
14
|
+
*
|
|
15
|
+
* These are deliberately *not* {@link ConsumerAttributes}. Consumer attributes
|
|
16
|
+
* are opaque per-invocation metadata that travels with one observation's
|
|
17
|
+
* identity and is sanitized by the privacy service; resource attributes are
|
|
18
|
+
* per-process exporter policy, resolved from configuration layers, and describe
|
|
19
|
+
* the producer rather than the observation. The two never share a field name, a
|
|
20
|
+
* flag, or a code path — see ADR 0001 on keeping identity out of configuration.
|
|
21
|
+
*/
|
|
22
|
+
/** Upper bound on how many custom resource attributes one installation may set. */
|
|
23
|
+
declare const MAX_RESOURCE_ATTRIBUTES = 64;
|
|
24
|
+
/** Upper bound on a resource attribute key, matching the OpenTelemetry guidance. */
|
|
25
|
+
declare const MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH = 255;
|
|
26
|
+
/** Upper bound on a resource attribute value; values are repeated on every export. */
|
|
27
|
+
declare const MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH = 2048;
|
|
28
|
+
/**
|
|
29
|
+
* Accepted shape of a resource attribute key.
|
|
30
|
+
*
|
|
31
|
+
* Deliberately narrower than "any string": a key becomes an attribute name on
|
|
32
|
+
* the wire, so restricting it to the OpenTelemetry naming vocabulary keeps
|
|
33
|
+
* newlines, control characters, and arbitrary binary out of the exported
|
|
34
|
+
* resource by construction.
|
|
35
|
+
*/
|
|
36
|
+
declare const RESOURCE_ATTRIBUTE_KEY_PATTERN: RegExp;
|
|
37
|
+
/**
|
|
38
|
+
* Keys that resource attributes may never set directly.
|
|
39
|
+
*
|
|
40
|
+
* `service.name` and `service.namespace` are typed exporter policy with their
|
|
41
|
+
* own precedence chain and their own diagnostics. If a resource-attribute map
|
|
42
|
+
* could also write them, the winner would depend on merge order inside the
|
|
43
|
+
* exporter rather than on the documented configuration precedence — which is
|
|
44
|
+
* exactly the silent override this reservation prevents. Supplying either one
|
|
45
|
+
* through `OTEL_RESOURCE_ATTRIBUTES` still works: the environment parser routes
|
|
46
|
+
* it to the policy field at a defined precedence instead of smuggling it into
|
|
47
|
+
* the resource map.
|
|
48
|
+
*/
|
|
49
|
+
declare const RESERVED_RESOURCE_ATTRIBUTE_KEYS: readonly string[];
|
|
50
|
+
/** Case-insensitive: `Service.Name` is the same reservation, spelled differently. */
|
|
51
|
+
declare const isReservedResourceAttributeKey: (key: string) => boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Whether a key names something that should never be exported.
|
|
54
|
+
*
|
|
55
|
+
* A resource attribute is attached to *every* span, so `api_key=...` in a
|
|
56
|
+
* config file or a shell profile would be the most durable possible leak. The
|
|
57
|
+
* central privacy policy's key patterns are reused rather than re-invented, so
|
|
58
|
+
* one list governs both content sanitization and this boundary.
|
|
59
|
+
*/
|
|
60
|
+
declare const isSecretResourceAttributeKey: (key: string) => boolean;
|
|
61
|
+
type ResourceAttributeKeyRejection = "empty" | "too-long" | "malformed" | "reserved" | "secret-like";
|
|
62
|
+
/** Non-sensitive explanations. None of these ever quotes an attribute *value*. */
|
|
63
|
+
declare const RESOURCE_ATTRIBUTE_KEY_REJECTION_DETAIL: Readonly<Record<ResourceAttributeKeyRejection, string>>;
|
|
64
|
+
/** Returns why a key is unusable, or `undefined` when it is acceptable. */
|
|
65
|
+
declare const checkResourceAttributeKey: (key: string) => ResourceAttributeKeyRejection | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Resource attribute values are single primitives, never arrays.
|
|
68
|
+
*
|
|
69
|
+
* `OTEL_RESOURCE_ATTRIBUTES` cannot express an array, and allowing one only in
|
|
70
|
+
* the file layer would make per-key precedence depend on which layer supplied a
|
|
71
|
+
* key. A single primitive keeps the merge total and order-independent.
|
|
72
|
+
*/
|
|
73
|
+
declare const resourceAttributeValueSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
74
|
+
type ResourceAttributeValue = z.infer<typeof resourceAttributeValueSchema>;
|
|
75
|
+
declare const resourceAttributesSchema: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
76
|
+
type ResourceAttributes = z.infer<typeof resourceAttributesSchema>;
|
|
77
|
+
declare const EMPTY_RESOURCE_ATTRIBUTES: ResourceAttributes;
|
|
78
|
+
type ParsedResourceAttributes = {
|
|
79
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
80
|
+
/** `service.name`, routed to exporter policy rather than into `attributes`. */
|
|
81
|
+
readonly serviceName?: string;
|
|
82
|
+
/** `service.namespace`, routed the same way. */
|
|
83
|
+
readonly serviceNamespace?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Why entries were skipped. Every message identifies an entry by its
|
|
86
|
+
* *position*, never by quoting the entry — an ambient environment variable
|
|
87
|
+
* may hold anything, and a diagnostic that echoes it would publish it.
|
|
88
|
+
*/
|
|
89
|
+
readonly warnings: readonly string[];
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Parse the standard `OTEL_RESOURCE_ATTRIBUTES` variable.
|
|
93
|
+
*
|
|
94
|
+
* The OpenTelemetry specification defines this as W3C Baggage: comma-separated
|
|
95
|
+
* `key=value` pairs, optional whitespace around each part, an optional
|
|
96
|
+
* `;`-delimited metadata suffix that carries no attribute meaning, and
|
|
97
|
+
* **percent-encoded values**. Escaping is the part naive parsers get wrong, and
|
|
98
|
+
* it is load-bearing here: without it `deployment.note=a%2Cb` silently becomes
|
|
99
|
+
* two malformed entries, and `region=eu%2Dwest` keeps a literal `%2D`.
|
|
100
|
+
*
|
|
101
|
+
* Every rejection is reported and skipped rather than failing the whole
|
|
102
|
+
* variable: a stale entry in a shell profile must not cost an operator the
|
|
103
|
+
* attributes they got right, and must never disable telemetry (ADR 0004).
|
|
104
|
+
*/
|
|
105
|
+
declare const parseResourceAttributesValue: (raw: string) => ParsedResourceAttributes;
|
|
106
|
+
/**
|
|
107
|
+
* Drop anything that must not reach the exported resource.
|
|
108
|
+
*
|
|
109
|
+
* The schema already refuses these keys, but a {@link ExporterPolicy} can also
|
|
110
|
+
* be hand-built by a library caller who never ran it through the schema. This
|
|
111
|
+
* is the last gate before the wire, so it filters rather than trusts.
|
|
112
|
+
*/
|
|
113
|
+
declare const sanitizeResourceAttributes: (attributes: ResourceAttributes) => Readonly<Record<string, ResourceAttributeValue>>;
|
|
114
|
+
/**
|
|
115
|
+
* Attribute *names* only, for a logged or exported configuration snapshot.
|
|
116
|
+
*
|
|
117
|
+
* Names are safe to disclose because they are already part of every exported
|
|
118
|
+
* resource; values are not disclosed, because a value is the half an operator
|
|
119
|
+
* may have filled with something they would not want in a log line.
|
|
120
|
+
*/
|
|
121
|
+
declare const describeResourceAttributeNames: (attributes: ResourceAttributes) => readonly string[];
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Configuration layers, lowest precedence first.
|
|
125
|
+
*
|
|
126
|
+
* Precedence is fixed and total: `inline-override` beats `environment`, which
|
|
127
|
+
* beats `file`, which beats `defaults`. There is no partial-merge surprise —
|
|
128
|
+
* merging happens per leaf field, so a file may set an endpoint while the
|
|
129
|
+
* environment sets only a content mode.
|
|
130
|
+
*
|
|
131
|
+
* `exporter.resourceAttributes` follows the same rule one level deeper: each
|
|
132
|
+
* *attribute key* is its own leaf. A file may set `deployment.environment`
|
|
133
|
+
* while `OTEL_RESOURCE_ATTRIBUTES` adds `service.instance.id` and
|
|
134
|
+
* `--resource-attr` overrides just one of them; the result is the union, with
|
|
135
|
+
* the highest-precedence layer winning per key and provenance recorded per key.
|
|
136
|
+
* A layer cannot *remove* a key a lower layer set — precedence is an override
|
|
137
|
+
* relation, not a replacement one.
|
|
138
|
+
*/
|
|
139
|
+
declare const CONFIG_SOURCE_PRECEDENCE: readonly ["defaults", "file", "environment", "inline-override"];
|
|
140
|
+
type ConfigSource = (typeof CONFIG_SOURCE_PRECEDENCE)[number];
|
|
141
|
+
declare const configSourceSchema: z.ZodEnum<{
|
|
142
|
+
file: "file";
|
|
143
|
+
defaults: "defaults";
|
|
144
|
+
environment: "environment";
|
|
145
|
+
"inline-override": "inline-override";
|
|
146
|
+
}>;
|
|
147
|
+
type ConfigLayer = {
|
|
148
|
+
readonly source: Exclude<ConfigSource, "defaults">;
|
|
149
|
+
readonly patch: OtelHookConfigPatch;
|
|
150
|
+
/** Non-sensitive origin label, e.g. a file name without its directory. */
|
|
151
|
+
readonly origin?: string;
|
|
152
|
+
};
|
|
153
|
+
/** Which layer supplied each resolved leaf, keyed by `section.field` path. */
|
|
154
|
+
type ConfigProvenance = Readonly<Record<string, ConfigSource>>;
|
|
155
|
+
type ConfigResolution = {
|
|
156
|
+
readonly status: "ok";
|
|
157
|
+
readonly config: OtelHookConfig;
|
|
158
|
+
readonly provenance: ConfigProvenance;
|
|
159
|
+
readonly notes: readonly string[];
|
|
160
|
+
} | {
|
|
161
|
+
readonly status: "invalid";
|
|
162
|
+
readonly errors: readonly OtelHookErrorInfo[];
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Resolve configuration from layered patches.
|
|
166
|
+
*
|
|
167
|
+
* Invalid layers are rejected rather than partially applied: a half-applied
|
|
168
|
+
* privacy policy is exactly the failure mode this contract exists to prevent.
|
|
169
|
+
* Callers that must not fail hard should fall back to {@link DEFAULT_CONFIG},
|
|
170
|
+
* which is always valid.
|
|
171
|
+
*/
|
|
172
|
+
declare const resolveConfig: (layers?: readonly ConfigLayer[]) => ConfigResolution;
|
|
173
|
+
/**
|
|
174
|
+
* Attribute-safe snapshot of resolved configuration, for logging and telemetry.
|
|
175
|
+
*
|
|
176
|
+
* Endpoints are reduced to origin form and header values never appear, because a
|
|
177
|
+
* snapshot is exported to the very system whose credentials it would leak.
|
|
178
|
+
*/
|
|
179
|
+
declare const describeResolvedConfig: (config: OtelHookConfig) => Attributes;
|
|
180
|
+
|
|
181
|
+
type EnvironmentRecord = Readonly<Record<string, string | undefined>>;
|
|
182
|
+
type EnvironmentConfigResult = {
|
|
183
|
+
readonly patch: OtelHookConfigPatch;
|
|
184
|
+
/**
|
|
185
|
+
* Unusable variables are reported and skipped rather than failing resolution.
|
|
186
|
+
* The environment is ambient: a stale variable in a shell profile must not
|
|
187
|
+
* disable telemetry, and it must not silently change privacy either — hence
|
|
188
|
+
* the warning.
|
|
189
|
+
*/
|
|
190
|
+
readonly warnings: readonly OtelHookErrorInfo[];
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Environment variables read by the library.
|
|
194
|
+
*
|
|
195
|
+
* No identity variable appears here by design: session, invocation, and
|
|
196
|
+
* workspace identity are supplied per invocation as identity claims, never
|
|
197
|
+
* through ambient configuration (ADR 0001).
|
|
198
|
+
*/
|
|
199
|
+
declare const ENVIRONMENT_VARIABLES: Readonly<{
|
|
200
|
+
exporterEnabled: "OTEL_HOOK_ENABLED";
|
|
201
|
+
exporterEndpoint: "OTEL_HOOK_EXPORTER_ENDPOINT";
|
|
202
|
+
otlpEndpoint: "OTEL_EXPORTER_OTLP_ENDPOINT";
|
|
203
|
+
exporterProtocol: "OTEL_HOOK_EXPORTER_PROTOCOL";
|
|
204
|
+
exporterTimeoutMillis: "OTEL_HOOK_EXPORTER_TIMEOUT_MS";
|
|
205
|
+
logsEnabled: "OTEL_HOOK_LOGS_ENABLED";
|
|
206
|
+
logsEndpoint: "OTEL_HOOK_LOGS_ENDPOINT";
|
|
207
|
+
/** Standard per-signal endpoint; the weaker source of the two. */
|
|
208
|
+
otlpLogsEndpoint: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT";
|
|
209
|
+
logsIncludeContent: "OTEL_HOOK_LOGS_INCLUDE_CONTENT";
|
|
210
|
+
serviceName: "OTEL_HOOK_SERVICE_NAME";
|
|
211
|
+
otlpServiceName: "OTEL_SERVICE_NAME";
|
|
212
|
+
serviceNamespace: "OTEL_HOOK_SERVICE_NAMESPACE";
|
|
213
|
+
/** Standard W3C-Baggage-encoded resource attributes (percent-encoded values). */
|
|
214
|
+
resourceAttributes: "OTEL_RESOURCE_ATTRIBUTES";
|
|
215
|
+
contentMode: "OTEL_HOOK_CONTENT_MODE";
|
|
216
|
+
allowRawContent: "OTEL_HOOK_ALLOW_RAW_CONTENT";
|
|
217
|
+
hashSalt: "OTEL_HOOK_HASH_SALT";
|
|
218
|
+
maxStringLength: "OTEL_HOOK_MAX_STRING_LENGTH";
|
|
219
|
+
maxDepth: "OTEL_HOOK_MAX_DEPTH";
|
|
220
|
+
maxArrayLength: "OTEL_HOOK_MAX_ARRAY_LENGTH";
|
|
221
|
+
maxEventsPerInvocation: "OTEL_HOOK_MAX_EVENTS_PER_INVOCATION";
|
|
222
|
+
minimumConfidence: "OTEL_HOOK_MIN_DETECTION_CONFIDENCE";
|
|
223
|
+
logLevel: "OTEL_HOOK_LOG_LEVEL";
|
|
224
|
+
}>;
|
|
225
|
+
/**
|
|
226
|
+
* Read configuration from an environment record.
|
|
227
|
+
*
|
|
228
|
+
* Pure: the process environment is never read implicitly, which keeps tests and
|
|
229
|
+
* hosted embeddings from inheriting the developer's shell.
|
|
230
|
+
*/
|
|
231
|
+
declare const parseEnvironmentConfig: (env: EnvironmentRecord) => EnvironmentConfigResult;
|
|
232
|
+
|
|
233
|
+
export { CONFIG_SOURCE_PRECEDENCE, type ConfigLayer, type ConfigProvenance, type ConfigResolution, type ConfigSource, EMPTY_RESOURCE_ATTRIBUTES, ENVIRONMENT_VARIABLES, type EnvironmentConfigResult, type EnvironmentRecord, MAX_RESOURCE_ATTRIBUTES, MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH, MAX_RESOURCE_ATTRIBUTE_VALUE_LENGTH, OtelHookConfig, OtelHookConfigPatch, type ParsedResourceAttributes, RESERVED_RESOURCE_ATTRIBUTE_KEYS, RESOURCE_ATTRIBUTE_KEY_PATTERN, RESOURCE_ATTRIBUTE_KEY_REJECTION_DETAIL, type ResourceAttributeKeyRejection, type ResourceAttributeValue, type ResourceAttributes, checkResourceAttributeKey, configSourceSchema, describeResolvedConfig, describeResourceAttributeNames, isReservedResourceAttributeKey, isSecretResourceAttributeKey, parseEnvironmentConfig, parseResourceAttributesValue, resolveConfig, resourceAttributeValueSchema, resourceAttributesSchema, sanitizeResourceAttributes };
|