@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,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy Evaluator
|
|
3
|
+
*
|
|
4
|
+
* Evaluates telemetry routing decisions based on policy configuration.
|
|
5
|
+
*/
|
|
6
|
+
import { TelemetryTier, EnforcementMode, } from "../types/policy.js";
|
|
7
|
+
/**
|
|
8
|
+
* Evaluator for telemetry policy decisions.
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: This evaluator determines ROUTING eligibility, not trace sampling.
|
|
11
|
+
*
|
|
12
|
+
* For TRACES: Sampling must be handled by the OTel SDK Sampler (parent-based,
|
|
13
|
+
* trace-ID ratio) to ensure trace consistency.
|
|
14
|
+
*
|
|
15
|
+
* For METRICS/LOGS: sampleRate applies with deterministic trace-ID-based logic.
|
|
16
|
+
*/
|
|
17
|
+
export class TelemetryPolicyEvaluator {
|
|
18
|
+
policy;
|
|
19
|
+
constructor(policy) {
|
|
20
|
+
this.policy = policy;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the current policy.
|
|
24
|
+
*/
|
|
25
|
+
getPolicy() {
|
|
26
|
+
return this.policy;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Evaluate whether a telemetry signal should be processed/exported.
|
|
30
|
+
*
|
|
31
|
+
* @param tier - The tier this signal belongs to
|
|
32
|
+
* @param orgId - Optional org ID for org-specific overrides
|
|
33
|
+
* @param traceId - Optional trace ID for deterministic sampling
|
|
34
|
+
* @returns PolicyDecision
|
|
35
|
+
*/
|
|
36
|
+
evaluate(tier, orgId, traceId) {
|
|
37
|
+
const effectivePolicy = this.getEffectivePolicy(orgId);
|
|
38
|
+
const tierConfig = effectivePolicy.tiers[tier];
|
|
39
|
+
if (!tierConfig.enabled) {
|
|
40
|
+
return {
|
|
41
|
+
retainLocal: false,
|
|
42
|
+
export: false,
|
|
43
|
+
sampled: false,
|
|
44
|
+
blockReason: `Tier ${tier} is disabled`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// Use trace-ID-based deterministic sampling (NOT Math.random)
|
|
48
|
+
// This ensures same trace ID = same decision across all services.
|
|
49
|
+
//
|
|
50
|
+
// SAMPLING FALLBACK BEHAVIOR:
|
|
51
|
+
// When no traceId is provided (e.g., for standalone metrics or logs),
|
|
52
|
+
// we only sample if sampleRate >= 1.0. This is intentionally conservative:
|
|
53
|
+
// - For traces: traceId should always be available from span context
|
|
54
|
+
// - For metrics: typically want 100% capture (sampleRate = 1.0) or explicit control
|
|
55
|
+
// - For logs: same as metrics
|
|
56
|
+
//
|
|
57
|
+
// If probabilistic sampling without traceId is needed, callers should generate
|
|
58
|
+
// a synthetic traceId or use a different sampling mechanism.
|
|
59
|
+
const sampled = traceId
|
|
60
|
+
? this.traceIdBasedSample(traceId, tierConfig.sampleRate)
|
|
61
|
+
: tierConfig.sampleRate >= 1.0;
|
|
62
|
+
return {
|
|
63
|
+
retainLocal: tierConfig.enabled,
|
|
64
|
+
export: tierConfig.exportEnabled && sampled,
|
|
65
|
+
sampled,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if export infrastructure should be created for a tier.
|
|
70
|
+
*
|
|
71
|
+
* This checks ONLY whether export is enabled in policy configuration.
|
|
72
|
+
* It does NOT apply sampling - use this for SDK initialization decisions.
|
|
73
|
+
*
|
|
74
|
+
* @param tier - The tier to check
|
|
75
|
+
* @param orgId - Optional org ID for org-specific overrides
|
|
76
|
+
* @returns true if export infrastructure should be created
|
|
77
|
+
*/
|
|
78
|
+
isExportEnabled(tier, orgId) {
|
|
79
|
+
const effectivePolicy = this.getEffectivePolicy(orgId);
|
|
80
|
+
const tierConfig = effectivePolicy.tiers[tier];
|
|
81
|
+
return tierConfig.enabled && tierConfig.exportEnabled;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if an export attempt is allowed (includes sampling).
|
|
85
|
+
*
|
|
86
|
+
* This applies sampling logic and should be used for per-span/per-signal
|
|
87
|
+
* decisions at runtime, NOT for infrastructure initialization.
|
|
88
|
+
*
|
|
89
|
+
* @param tier - The tier to check
|
|
90
|
+
* @param orgId - Optional org ID for org-specific overrides
|
|
91
|
+
* @param traceId - Optional trace ID for deterministic sampling
|
|
92
|
+
* @returns true if export is allowed for this specific signal
|
|
93
|
+
*/
|
|
94
|
+
canExport(tier, orgId, traceId) {
|
|
95
|
+
const decision = this.evaluate(tier, orgId, traceId);
|
|
96
|
+
return decision.export;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Assert export is allowed, throwing or logging based on enforcement mode.
|
|
100
|
+
*
|
|
101
|
+
* @param tier - The tier to check
|
|
102
|
+
* @param orgId - Optional org ID for org-specific overrides
|
|
103
|
+
* @throws Error if in ENFORCE mode and export is blocked
|
|
104
|
+
*/
|
|
105
|
+
assertCanExport(tier, orgId) {
|
|
106
|
+
if (!this.canExport(tier, orgId)) {
|
|
107
|
+
const msg = `Export blocked for tier ${tier}`;
|
|
108
|
+
if (this.policy.enforcementMode === EnforcementMode.ENFORCE) {
|
|
109
|
+
throw new Error(msg);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
console.warn(`[AUDIT] ${msg}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Check if Tier 3 content export is enabled.
|
|
118
|
+
*
|
|
119
|
+
* @returns true if Tier 3 prompts/responses can be exported
|
|
120
|
+
*/
|
|
121
|
+
canExportTier3Content() {
|
|
122
|
+
return (this.canExport(TelemetryTier.TIER_3_AI_EXPERIENCE) &&
|
|
123
|
+
this.policy.tier3Content.contentExportEnabled);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get the effective policy for an org (applying overrides if present).
|
|
127
|
+
*
|
|
128
|
+
* Performs deep merge for nested objects (tiers, tier3Content) to ensure
|
|
129
|
+
* partial overrides don't clobber unspecified configurations.
|
|
130
|
+
*
|
|
131
|
+
* @param orgId - Optional org ID
|
|
132
|
+
* @returns Effective policy
|
|
133
|
+
*/
|
|
134
|
+
getEffectivePolicy(orgId) {
|
|
135
|
+
if (!orgId || !this.policy.orgOverrides?.[orgId]) {
|
|
136
|
+
return this.policy;
|
|
137
|
+
}
|
|
138
|
+
const override = this.policy.orgOverrides[orgId];
|
|
139
|
+
// Valid tier keys for filtering
|
|
140
|
+
const validTiers = new Set(Object.values(TelemetryTier));
|
|
141
|
+
// Deep merge tiers: only override specified tiers, preserve others
|
|
142
|
+
// Filter out invalid tier keys and null/undefined configs
|
|
143
|
+
const mergedTiers = override.tiers
|
|
144
|
+
? {
|
|
145
|
+
...this.policy.tiers,
|
|
146
|
+
...Object.fromEntries(Object.entries(override.tiers)
|
|
147
|
+
.filter(([tier, config]) => validTiers.has(tier) && config != null)
|
|
148
|
+
.map(([tier, config]) => [
|
|
149
|
+
tier,
|
|
150
|
+
{ ...this.policy.tiers[tier], ...config },
|
|
151
|
+
])),
|
|
152
|
+
}
|
|
153
|
+
: this.policy.tiers;
|
|
154
|
+
// Deep merge tier3Content if present and not null
|
|
155
|
+
const mergedTier3Content = override.tier3Content != null
|
|
156
|
+
? { ...this.policy.tier3Content, ...override.tier3Content }
|
|
157
|
+
: this.policy.tier3Content;
|
|
158
|
+
return {
|
|
159
|
+
...this.policy,
|
|
160
|
+
...override,
|
|
161
|
+
tiers: mergedTiers,
|
|
162
|
+
tier3Content: mergedTier3Content,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Deterministic sampling based on trace ID (W3C TraceContext recommendation).
|
|
167
|
+
* Uses last 8 hex chars for uniform distribution in [0, 1).
|
|
168
|
+
*
|
|
169
|
+
* @param traceId - The trace ID (must be at least 8 hex characters)
|
|
170
|
+
* @param sampleRate - Sample rate (0.0 - 1.0)
|
|
171
|
+
* @returns true if sampled
|
|
172
|
+
*/
|
|
173
|
+
traceIdBasedSample(traceId, sampleRate) {
|
|
174
|
+
if (sampleRate >= 1.0)
|
|
175
|
+
return true;
|
|
176
|
+
if (sampleRate <= 0.0)
|
|
177
|
+
return false;
|
|
178
|
+
// Validate trace ID has sufficient hex characters
|
|
179
|
+
if (!traceId || traceId.length < 8) {
|
|
180
|
+
// Malformed trace ID - fail safe by not sampling
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const sampleHex = traceId.slice(-8);
|
|
184
|
+
// Validate hex characters
|
|
185
|
+
if (!/^[0-9a-fA-F]{8}$/.test(sampleHex)) {
|
|
186
|
+
// Non-hex characters in trace ID - fail safe by not sampling
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
// Parse last 8 hex chars as 32-bit unsigned int (range: 0 to 0xFFFFFFFF)
|
|
190
|
+
// Divide by 2^32 (0x100000000) to get uniform distribution in [0, 1)
|
|
191
|
+
// Using 0xFFFFFFFF would incorrectly produce 1.0 for max trace IDs
|
|
192
|
+
const sampleValue = parseInt(sampleHex, 16) / 0x100000000;
|
|
193
|
+
return sampleValue < sampleRate;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=policy-evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-evaluator.js","sourceRoot":"","sources":["../../src/common/policy-evaluator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource Builder
|
|
3
|
+
*
|
|
4
|
+
* Standardized resource attributes for all Superblocks services.
|
|
5
|
+
*
|
|
6
|
+
* CRITICAL: Resource Attributes vs Span Attributes
|
|
7
|
+
*
|
|
8
|
+
* `service.name`, `service.version`, and `deployment.environment.name` MUST be set as
|
|
9
|
+
* **resource attributes** (once, at SDK initialization), NOT as span attributes (per-span).
|
|
10
|
+
*
|
|
11
|
+
* - Resource attributes: Set once, inherited by all spans/metrics/logs
|
|
12
|
+
* - Span attributes: Set per-span, for request-specific data
|
|
13
|
+
*/
|
|
14
|
+
import { type Resource } from "@opentelemetry/resources";
|
|
15
|
+
import type { BaseTelemetryConfig } from '../types/index.js';
|
|
16
|
+
/**
|
|
17
|
+
* Required RESOURCE attributes for correlation.
|
|
18
|
+
* These must NOT be added as span attributes (they're inherited from resource).
|
|
19
|
+
*/
|
|
20
|
+
export declare const REQUIRED_RESOURCE_ATTRIBUTES: readonly ["service.name", "service.version", "deployment.environment.name"];
|
|
21
|
+
/**
|
|
22
|
+
* Attributes that should NEVER be set at span level (use resource instead).
|
|
23
|
+
* Used by linting/validation to catch misuse.
|
|
24
|
+
*/
|
|
25
|
+
export declare const RESOURCE_ONLY_ATTRIBUTES: Set<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Superblocks namespace for custom resource attributes.
|
|
28
|
+
*/
|
|
29
|
+
export declare const SUPERBLOCKS_NAMESPACE = "superblocks";
|
|
30
|
+
/**
|
|
31
|
+
* Build standardized resource for a Superblocks service.
|
|
32
|
+
*
|
|
33
|
+
* IMPORTANT: These are RESOURCE attributes (set once at init), not span attributes.
|
|
34
|
+
* They are inherited by ALL telemetry from this SDK instance.
|
|
35
|
+
*
|
|
36
|
+
* Semantic conventions used:
|
|
37
|
+
* - service.name (required)
|
|
38
|
+
* - service.version (required)
|
|
39
|
+
* - deployment.environment.name (required)
|
|
40
|
+
* - superblocks.* (custom namespace)
|
|
41
|
+
*
|
|
42
|
+
* @param config - Service configuration
|
|
43
|
+
* @returns Resource with standardized attributes
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildResource(config: BaseTelemetryConfig): Resource;
|
|
46
|
+
/**
|
|
47
|
+
* Validate that a resource has all required attributes.
|
|
48
|
+
*
|
|
49
|
+
* @param resource - Resource to validate
|
|
50
|
+
* @throws Error if missing required attributes
|
|
51
|
+
*/
|
|
52
|
+
export declare function validateResource(resource: Resource): void;
|
|
53
|
+
/**
|
|
54
|
+
* Assert that span attributes don't include resource-only attributes.
|
|
55
|
+
* Throws an error if resource-only attributes are present.
|
|
56
|
+
* For use in linting/CI or development mode.
|
|
57
|
+
*
|
|
58
|
+
* @param spanAttrs - Span attributes to validate
|
|
59
|
+
* @throws Error if resource-only attributes are present
|
|
60
|
+
*/
|
|
61
|
+
export declare function assertNoResourceAttributes(spanAttrs: Record<string, unknown>): void;
|
|
62
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/common/resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAGL,KAAK,QAAQ,EACd,MAAM,0BAA0B,CAAC;AAOlC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAK7D;;;GAGG;AACH,eAAO,MAAM,4BAA4B,6EAI/B,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,wBAAwB,aAKnC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AAEnD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,QAAQ,CAiBnE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAOzD;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CASnF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource Builder
|
|
3
|
+
*
|
|
4
|
+
* Standardized resource attributes for all Superblocks services.
|
|
5
|
+
*
|
|
6
|
+
* CRITICAL: Resource Attributes vs Span Attributes
|
|
7
|
+
*
|
|
8
|
+
* `service.name`, `service.version`, and `deployment.environment.name` MUST be set as
|
|
9
|
+
* **resource attributes** (once, at SDK initialization), NOT as span attributes (per-span).
|
|
10
|
+
*
|
|
11
|
+
* - Resource attributes: Set once, inherited by all spans/metrics/logs
|
|
12
|
+
* - Span attributes: Set per-span, for request-specific data
|
|
13
|
+
*/
|
|
14
|
+
import { resourceFromAttributes, defaultResource, } from "@opentelemetry/resources";
|
|
15
|
+
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, } from "@opentelemetry/semantic-conventions";
|
|
16
|
+
/** OTEL semantic convention for deployment environment. */
|
|
17
|
+
const ATTR_DEPLOYMENT_ENVIRONMENT_NAME = "deployment.environment.name";
|
|
18
|
+
/**
|
|
19
|
+
* Required RESOURCE attributes for correlation.
|
|
20
|
+
* These must NOT be added as span attributes (they're inherited from resource).
|
|
21
|
+
*/
|
|
22
|
+
export const REQUIRED_RESOURCE_ATTRIBUTES = [
|
|
23
|
+
"service.name",
|
|
24
|
+
"service.version",
|
|
25
|
+
"deployment.environment.name",
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Attributes that should NEVER be set at span level (use resource instead).
|
|
29
|
+
* Used by linting/validation to catch misuse.
|
|
30
|
+
*/
|
|
31
|
+
export const RESOURCE_ONLY_ATTRIBUTES = new Set([
|
|
32
|
+
"service.name",
|
|
33
|
+
"service.version",
|
|
34
|
+
"deployment.environment.name",
|
|
35
|
+
"superblocks.environment",
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* Superblocks namespace for custom resource attributes.
|
|
39
|
+
*/
|
|
40
|
+
export const SUPERBLOCKS_NAMESPACE = 'superblocks';
|
|
41
|
+
/**
|
|
42
|
+
* Build standardized resource for a Superblocks service.
|
|
43
|
+
*
|
|
44
|
+
* IMPORTANT: These are RESOURCE attributes (set once at init), not span attributes.
|
|
45
|
+
* They are inherited by ALL telemetry from this SDK instance.
|
|
46
|
+
*
|
|
47
|
+
* Semantic conventions used:
|
|
48
|
+
* - service.name (required)
|
|
49
|
+
* - service.version (required)
|
|
50
|
+
* - deployment.environment.name (required)
|
|
51
|
+
* - superblocks.* (custom namespace)
|
|
52
|
+
*
|
|
53
|
+
* @param config - Service configuration
|
|
54
|
+
* @returns Resource with standardized attributes
|
|
55
|
+
*/
|
|
56
|
+
export function buildResource(config) {
|
|
57
|
+
const baseAttributes = {
|
|
58
|
+
// OTEL semantic conventions — RESOURCE level, not span level
|
|
59
|
+
[ATTR_SERVICE_NAME]: config.serviceName,
|
|
60
|
+
[ATTR_SERVICE_VERSION]: config.serviceVersion,
|
|
61
|
+
[ATTR_DEPLOYMENT_ENVIRONMENT_NAME]: config.environment,
|
|
62
|
+
// Superblocks namespace for compatibility
|
|
63
|
+
[`${SUPERBLOCKS_NAMESPACE}.environment`]: config.environment,
|
|
64
|
+
};
|
|
65
|
+
return defaultResource().merge(resourceFromAttributes({
|
|
66
|
+
...baseAttributes,
|
|
67
|
+
...config.resourceAttributes,
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validate that a resource has all required attributes.
|
|
72
|
+
*
|
|
73
|
+
* @param resource - Resource to validate
|
|
74
|
+
* @throws Error if missing required attributes
|
|
75
|
+
*/
|
|
76
|
+
export function validateResource(resource) {
|
|
77
|
+
const attributes = resource.attributes;
|
|
78
|
+
for (const attr of REQUIRED_RESOURCE_ATTRIBUTES) {
|
|
79
|
+
if (!attributes[attr]) {
|
|
80
|
+
throw new Error(`Missing required resource attribute: ${attr}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Assert that span attributes don't include resource-only attributes.
|
|
86
|
+
* Throws an error if resource-only attributes are present.
|
|
87
|
+
* For use in linting/CI or development mode.
|
|
88
|
+
*
|
|
89
|
+
* @param spanAttrs - Span attributes to validate
|
|
90
|
+
* @throws Error if resource-only attributes are present
|
|
91
|
+
*/
|
|
92
|
+
export function assertNoResourceAttributes(spanAttrs) {
|
|
93
|
+
for (const key of Object.keys(spanAttrs)) {
|
|
94
|
+
if (RESOURCE_ONLY_ATTRIBUTES.has(key)) {
|
|
95
|
+
throw new Error(`Attribute '${key}' should be a RESOURCE attribute, not a span attribute. ` +
|
|
96
|
+
`Set it in ResourceConfig at SDK init, not per-span.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/common/resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,sBAAsB,EACtB,eAAe,GAEhB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,qCAAqC,CAAC;AAI7C,2DAA2D;AAC3D,MAAM,gCAAgC,GAAG,6BAA6B,CAAC;AAEvE;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,cAAc;IACd,iBAAiB;IACjB,6BAA6B;CACrB,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IAC9C,cAAc;IACd,iBAAiB;IACjB,6BAA6B;IAC7B,yBAAyB;CAC1B,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AAEnD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAAC,MAA2B;IACvD,MAAM,cAAc,GAAe;QACjC,6DAA6D;QAC7D,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC,WAAW;QACvC,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC,cAAc;QAC7C,CAAC,gCAAgC,CAAC,EAAE,MAAM,CAAC,WAAW;QAEtD,0CAA0C;QAC1C,CAAC,GAAG,qBAAqB,cAAc,CAAC,EAAE,MAAM,CAAC,WAAW;KAC7D,CAAC;IAEF,OAAO,eAAe,EAAE,CAAC,KAAK,CAC5B,sBAAsB,CAAC;QACrB,GAAG,cAAc;QACjB,GAAG,MAAM,CAAC,kBAAkB;KAC7B,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAkB;IACjD,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;IACvC,KAAK,MAAM,IAAI,IAAI,4BAA4B,EAAE,CAAC;QAChD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,EAAE,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CAAC,SAAkC;IAC3E,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACzC,IAAI,wBAAwB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CACb,cAAc,GAAG,0DAA0D;gBACzE,qDAAqD,CACxD,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tier Policy Hints
|
|
3
|
+
*
|
|
4
|
+
* SDK-level hints that inform the OTEL Collector how to route spans.
|
|
5
|
+
* These are HINTS, not guarantees — the Collector makes final routing decisions.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This is different from tier TAGS (which indicate which pipeline processed
|
|
8
|
+
* a span). Hints are prescriptive ("please route this way"), tags are descriptive
|
|
9
|
+
* ("this was processed by Tier X"). The Collector adds tier tags; the SDK adds hints.
|
|
10
|
+
*
|
|
11
|
+
* See: engineering/projects/o11y-refactor/proposals/sdk-tier-policy-hints.md
|
|
12
|
+
*/
|
|
13
|
+
import type { Span } from "@opentelemetry/api";
|
|
14
|
+
/**
|
|
15
|
+
* The attribute key used for tier policy hints.
|
|
16
|
+
* Collector filters on this attribute to make routing decisions.
|
|
17
|
+
*/
|
|
18
|
+
export declare const TIER_HINT_ATTRIBUTE = "superblocks.tier_hint";
|
|
19
|
+
/**
|
|
20
|
+
* Tier policy hints that inform the Collector how to route spans.
|
|
21
|
+
*
|
|
22
|
+
* These are HINTS, not guarantees — the Collector makes final routing decisions
|
|
23
|
+
* based on its configuration. In cloud-prem deployments, the Collector respects
|
|
24
|
+
* these hints to control which tiers receive the span.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { trace } from '@opentelemetry/api';
|
|
29
|
+
* import { TierPolicyHint, TIER_HINT_ATTRIBUTE } from '@superblocksteam/telemetry';
|
|
30
|
+
*
|
|
31
|
+
* const span = tracer.startSpan('sensitive_operation');
|
|
32
|
+
* span.setAttribute(TIER_HINT_ATTRIBUTE, TierPolicyHint.TIER1_ONLY);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare enum TierPolicyHint {
|
|
36
|
+
/**
|
|
37
|
+
* Route to Tier 1 only. Do not export to Tier 2 or Tier 3.
|
|
38
|
+
*
|
|
39
|
+
* Use for:
|
|
40
|
+
* - Spans containing customer secrets or credentials
|
|
41
|
+
* - Highly sensitive customer data that must not leave their environment
|
|
42
|
+
* - Debug/diagnostic spans that should remain local
|
|
43
|
+
*
|
|
44
|
+
* The span will be stored in the customer's Tier 1 backend (e.g., Tempo)
|
|
45
|
+
* but will NOT be exported to Superblocks (Tier 2) or AI analytics (Tier 3).
|
|
46
|
+
*/
|
|
47
|
+
TIER1_ONLY = "tier1_only",
|
|
48
|
+
/**
|
|
49
|
+
* Include in Tier 3 (AI quality analysis) in addition to Tier 1 and Tier 2.
|
|
50
|
+
*
|
|
51
|
+
* Use for:
|
|
52
|
+
* - GenAI spans that should be analyzed for quality metrics
|
|
53
|
+
* - AI/LLM operations where prompts and responses are valuable for analysis
|
|
54
|
+
* - Spans with AI quality signals (latency, token usage, etc.)
|
|
55
|
+
*
|
|
56
|
+
* The span will go to all tiers: Tier 1 (full fidelity), Tier 2 (sanitized),
|
|
57
|
+
* and Tier 3 (AI analytics with identity stripped).
|
|
58
|
+
*/
|
|
59
|
+
INCLUDE_TIER3 = "include_tier3",
|
|
60
|
+
/**
|
|
61
|
+
* Skip all external export. Tier 1 (local) only, no Tier 2/3.
|
|
62
|
+
* Alias for TIER1_ONLY, kept for semantic clarity.
|
|
63
|
+
*
|
|
64
|
+
* Use for:
|
|
65
|
+
* - High-cardinality diagnostic spans (cost control)
|
|
66
|
+
* - Temporary debug spans that shouldn't persist
|
|
67
|
+
* - Spans that are only useful for local debugging
|
|
68
|
+
*
|
|
69
|
+
* This is functionally equivalent to TIER1_ONLY but communicates
|
|
70
|
+
* a different intent: "this is for cost/noise control" rather than
|
|
71
|
+
* "this contains sensitive data."
|
|
72
|
+
*/
|
|
73
|
+
SKIP_EXPORT = "skip_export"
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set a tier policy hint on a span.
|
|
77
|
+
*
|
|
78
|
+
* This is a convenience function that sets the `superblocks.tier_hint` attribute.
|
|
79
|
+
* You can also set the attribute directly if preferred.
|
|
80
|
+
*
|
|
81
|
+
* @param span - The span to set the hint on
|
|
82
|
+
* @param hint - The tier policy hint
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { setTierHint, TierPolicyHint } from '@superblocksteam/telemetry';
|
|
87
|
+
*
|
|
88
|
+
* tracer.startActiveSpan('decrypt_secret', (span) => {
|
|
89
|
+
* setTierHint(span, TierPolicyHint.TIER1_ONLY);
|
|
90
|
+
* // ... perform operation
|
|
91
|
+
* span.end();
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function setTierHint(span: Span, hint: TierPolicyHint): void;
|
|
96
|
+
/**
|
|
97
|
+
* Mark a span as containing sensitive data that should not leave Tier 1.
|
|
98
|
+
*
|
|
99
|
+
* Use this for spans that handle customer secrets, credentials, or other
|
|
100
|
+
* highly sensitive data that must remain in the customer's environment.
|
|
101
|
+
*
|
|
102
|
+
* @param span - The span to mark as sensitive
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* import { markSensitive } from '@superblocksteam/telemetry';
|
|
107
|
+
*
|
|
108
|
+
* tracer.startActiveSpan('decrypt_customer_secret', (span) => {
|
|
109
|
+
* markSensitive(span);
|
|
110
|
+
* // ... decrypt operation
|
|
111
|
+
* span.end();
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function markSensitive(span: Span): void;
|
|
116
|
+
/**
|
|
117
|
+
* Mark a span for AI quality analysis (Tier 3).
|
|
118
|
+
*
|
|
119
|
+
* Use this for GenAI spans that should be analyzed for quality metrics.
|
|
120
|
+
* The span will go to all tiers, with Tier 3 receiving the content
|
|
121
|
+
* (prompts/responses) for AI quality analysis.
|
|
122
|
+
*
|
|
123
|
+
* @param span - The span to mark for AI analysis
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* import { markForAIAnalysis } from '@superblocksteam/telemetry';
|
|
128
|
+
*
|
|
129
|
+
* tracer.startActiveSpan('gen_ai.chat', (span) => {
|
|
130
|
+
* markForAIAnalysis(span);
|
|
131
|
+
* span.setAttribute('gen_ai.system', 'anthropic');
|
|
132
|
+
* // ... LLM call
|
|
133
|
+
* span.end();
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function markForAIAnalysis(span: Span): void;
|
|
138
|
+
/**
|
|
139
|
+
* Mark a span as debug-only (no export to Tier 2/3).
|
|
140
|
+
*
|
|
141
|
+
* Use this for high-cardinality diagnostic spans where you want to
|
|
142
|
+
* control costs by preventing export to paid backends.
|
|
143
|
+
*
|
|
144
|
+
* @param span - The span to mark as debug-only
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* import { markDebugOnly } from '@superblocksteam/telemetry';
|
|
149
|
+
*
|
|
150
|
+
* tracer.startActiveSpan('debug.cache_lookup', (span) => {
|
|
151
|
+
* markDebugOnly(span);
|
|
152
|
+
* span.setAttribute('cache.key', cacheKey); // High cardinality OK
|
|
153
|
+
* // ... lookup
|
|
154
|
+
* span.end();
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function markDebugOnly(span: Span): void;
|
|
159
|
+
/**
|
|
160
|
+
* Check if a span has a tier hint set.
|
|
161
|
+
*
|
|
162
|
+
* @param span - The span to check (must be a ReadableSpan with attributes)
|
|
163
|
+
* @returns The tier hint if set, undefined otherwise
|
|
164
|
+
*/
|
|
165
|
+
export declare function getTierHint(span: {
|
|
166
|
+
attributes?: Record<string, unknown>;
|
|
167
|
+
}): TierPolicyHint | undefined;
|
|
168
|
+
/**
|
|
169
|
+
* Check if a tier hint indicates the span should skip Tier 2 export.
|
|
170
|
+
*
|
|
171
|
+
* @param hint - The tier hint to check
|
|
172
|
+
* @returns true if Tier 2 should be skipped
|
|
173
|
+
*/
|
|
174
|
+
export declare function shouldSkipTier2(hint: TierPolicyHint | undefined): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Check if a tier hint indicates the span should be included in Tier 3.
|
|
177
|
+
*
|
|
178
|
+
* @param hint - The tier hint to check
|
|
179
|
+
* @returns true if Tier 3 should be included
|
|
180
|
+
*/
|
|
181
|
+
export declare function shouldIncludeTier3(hint: TierPolicyHint | undefined): boolean;
|
|
182
|
+
//# sourceMappingURL=tier-hints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tier-hints.d.ts","sourceRoot":"","sources":["../../src/common/tier-hints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AAE3D;;;;;;;;;;;;;;;GAeG;AACH,oBAAY,cAAc;IACxB;;;;;;;;;;OAUG;IACH,UAAU,eAAe;IAEzB;;;;;;;;;;OAUG;IACH,aAAa,kBAAkB;IAE/B;;;;;;;;;;;;OAYG;IACH,WAAW,gBAAgB;CAC5B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAElE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAE9C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAElD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC,GAAG,cAAc,GAAG,SAAS,CAS7B;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,GAAG,OAAO,CAIzE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,GAAG,OAAO,CAE5E"}
|