@osfactory/otel-hook 0.13.2 → 0.14.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.
Files changed (37) hide show
  1. package/README.md +43 -0
  2. package/dist/{adapter-DyCb7y1N.d.ts → adapter-D5R8lhfl.d.ts} +1 -1
  3. package/dist/cli.js +427 -37
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts +30 -4
  6. package/dist/config.js +161 -9
  7. package/dist/config.js.map +1 -1
  8. package/dist/{destinations-C4sSKjDO.d.ts → destinations-2KrcRslo.d.ts} +92 -2
  9. package/dist/{export-destinations-BjRXDots.d.ts → export-destinations-DvoH4QOe.d.ts} +101 -9
  10. package/dist/{hook-CKLpgrYP.d.ts → hook-DVK8Don-.d.ts} +4 -4
  11. package/dist/index.d.ts +10 -10
  12. package/dist/index.js +424 -36
  13. package/dist/index.js.map +1 -1
  14. package/dist/install.d.ts +3 -3
  15. package/dist/integration.d.ts +7 -7
  16. package/dist/integration.js +376 -34
  17. package/dist/integration.js.map +1 -1
  18. package/dist/lifecycle.js +1 -1
  19. package/dist/lifecycle.js.map +1 -1
  20. package/dist/{payload-DLK7QaBB.d.ts → payload-D4r71EL-.d.ts} +1 -1
  21. package/dist/privacy.d.ts +2 -2
  22. package/dist/privacy.js +42 -1
  23. package/dist/privacy.js.map +1 -1
  24. package/dist/providers.d.ts +8 -8
  25. package/dist/{registry-DM-4YvIA.d.ts → registry-DOJh9mzB.d.ts} +2 -2
  26. package/dist/runtime.d.ts +5 -5
  27. package/dist/runtime.js +128 -2
  28. package/dist/runtime.js.map +1 -1
  29. package/dist/{schema-CD61uW99.d.ts → schema-oRsbo7WO.d.ts} +45 -0
  30. package/dist/{service-CbI9CObT.d.ts → service-DySC7KQM.d.ts} +6 -1
  31. package/dist/telemetry.d.ts +5 -4
  32. package/dist/telemetry.js +285 -15
  33. package/dist/telemetry.js.map +1 -1
  34. package/dist/testing.d.ts +5 -5
  35. package/dist/testing.js +128 -2
  36. package/dist/testing.js.map +1 -1
  37. package/package.json +1 -1
@@ -111,6 +111,21 @@ declare const exporterPolicySchema: z.ZodObject<{
111
111
  logs: "logs";
112
112
  metrics: "metrics";
113
113
  }>>>>;
114
+ scopes: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
115
+ repositories: z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodReadonly<z.ZodArray<z.ZodString>>]>;
116
+ signals: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
117
+ traces: "traces";
118
+ logs: "logs";
119
+ metrics: "metrics";
120
+ }>>>>;
121
+ contentMode: z.ZodOptional<z.ZodEnum<{
122
+ raw: "raw";
123
+ omit: "omit";
124
+ mask: "mask";
125
+ redact: "redact";
126
+ }>>;
127
+ includeSessionId: z.ZodOptional<z.ZodBoolean>;
128
+ }, z.core.$strict>>>>;
114
129
  }, z.core.$strict>>>>;
115
130
  spool: z.ZodOptional<z.ZodObject<{
116
131
  maxBytes: z.ZodOptional<z.ZodNumber>;
@@ -239,6 +254,21 @@ declare const otelHookConfigSchema: z.ZodObject<{
239
254
  logs: "logs";
240
255
  metrics: "metrics";
241
256
  }>>>>;
257
+ scopes: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
258
+ repositories: z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodReadonly<z.ZodArray<z.ZodString>>]>;
259
+ signals: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
260
+ traces: "traces";
261
+ logs: "logs";
262
+ metrics: "metrics";
263
+ }>>>>;
264
+ contentMode: z.ZodOptional<z.ZodEnum<{
265
+ raw: "raw";
266
+ omit: "omit";
267
+ mask: "mask";
268
+ redact: "redact";
269
+ }>>;
270
+ includeSessionId: z.ZodOptional<z.ZodBoolean>;
271
+ }, z.core.$strict>>>>;
242
272
  }, z.core.$strict>>>>;
243
273
  spool: z.ZodOptional<z.ZodObject<{
244
274
  maxBytes: z.ZodOptional<z.ZodNumber>;
@@ -338,6 +368,21 @@ declare const otelHookConfigPatchSchema: z.ZodObject<{
338
368
  logs: "logs";
339
369
  metrics: "metrics";
340
370
  }>>>>;
371
+ scopes: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
372
+ repositories: z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodReadonly<z.ZodArray<z.ZodString>>]>;
373
+ signals: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
374
+ traces: "traces";
375
+ logs: "logs";
376
+ metrics: "metrics";
377
+ }>>>>;
378
+ contentMode: z.ZodOptional<z.ZodEnum<{
379
+ raw: "raw";
380
+ omit: "omit";
381
+ mask: "mask";
382
+ redact: "redact";
383
+ }>>;
384
+ includeSessionId: z.ZodOptional<z.ZodBoolean>;
385
+ }, z.core.$strict>>>>;
341
386
  }, z.core.$strict>>>>>;
342
387
  exportBudgetMillis: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
343
388
  endpointDownMillis: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
@@ -1,6 +1,6 @@
1
1
  import { c as ContentKind, d as ContentRole, b as ContentFact } from './content-M9xIKG7h.js';
2
2
  import { b as Attributes, a as AttributeValue } from './primitives-CJ8-rn-f.js';
3
- import { f as PrivacyPolicy } from './policy-CimmCfRp.js';
3
+ import { f as PrivacyPolicy, a as ContentMode } from './policy-CimmCfRp.js';
4
4
 
5
5
  type SanitizedValue = string | number | boolean | null | readonly SanitizedValue[] | {
6
6
  readonly [key: string]: SanitizedValue;
@@ -68,6 +68,11 @@ interface PrivacyService {
68
68
  readonly text: string;
69
69
  readonly truncated: boolean;
70
70
  };
71
+ /**
72
+ * The same fact disclosed at most at `mode` (a per-destination restriction).
73
+ * Never raises disclosure: a fact already at or below `mode` is returned as is.
74
+ */
75
+ restrictContent(fact: ContentFact, mode: ContentMode): ContentFact;
71
76
  }
72
77
  declare const createPrivacyService: (policyInput: PrivacyPolicy) => PrivacyService;
73
78
 
@@ -1,20 +1,21 @@
1
1
  export { D as DEFAULT_INSTRUMENTATION_SCOPE, a as DeriveMetricObservationsInput, E as EventTraceIdentity, M as MAX_RECOVERED_START_ATTRIBUTES, b as METRIC_COST_USAGE, c as METRIC_INSTRUMENTS, d as METRIC_OPERATION_DURATION, e as METRIC_SESSIONS, f as METRIC_TOKEN_USAGE, g as METRIC_TOOL_CALLS, h as MetricInstrument, i as MetricInstrumentName, j as MetricObservation, k as MetricPoint, l as MetricsTemporality, O as OPERATION_DURATION_BUCKETS, S as SemanticMappingOptions, m as SpanCorrelation, n as SpanCorrelationResolver, o as SpanDisposition, p as SpanFamily, q as SpanOrphanClassification, r as SpanPairing, s as SpanScopeRef, T as TOKEN_USAGE_BUCKETS, t as TokenType, u as aggregateDeltaPoints, v as canonicalEventTraceIdentities, w as canonicalEventsToReadableSpans, x as deriveMetricObservations, y as parentScopeRefOf, z as spanScopeRefOf, A as startOnlySpanAttributes } from './metric-model-B4lIuk6i.js';
2
- export { C as ContentWithholdingReason, D as DurableLogSpool, a as DurableLogSpoolOptions, b as DurableMetricSpool, c as DurableMetricSpoolOptions, d as DurableSpool, e as DurableSpoolOptions, E as ExportDestinationSinks, f as ExportDestinationsOptions, L as LOG_MAPPING_VERSION, g as LOG_SIGNALS, h as LogContentPolicy, i as LogMappingOptions, j as LogMappingResult, k as LogSignal, l as LogSpoolBatch, m as LogsDeliverability, M as MAX_LOG_BODY_CHARACTERS, n as MAX_LOG_RECORDS_PER_BATCH, o as MAX_LOG_RECORDS_PER_EVENT, p as MCP_TOOL_NAME_PATTERN, q as MetricExportResult, r as MetricSpoolBatch, s as MetricsDeliverability, N as NO_LOG_CONTENT, O as OtlpLogSinkOptions, t as OtlpLogTelemetrySink, u as OtlpMetricSinkOptions, v as OtlpMetricTelemetrySink, w as OtlpTelemetrySink, x as OtlpTraceSinkOptions, S as SerializedLogRecord, y as SerializedSpan, z as SignalFanoutOptions, A as SignalFanoutSink, B as SkippedExportDestination, F as SpoolBatch, G as SpoolDrainResult, H as SpoolDropCounts, I as SpoolDropReason, J as SpoolEnqueueResult, K as SpoolOverflowPolicy, P as SpoolSendOutcome, Q as SpoolStats, R as canonicalEventsToLogRecords, T as createDestinationFanout, U as createExportDestinationSinks, V as createFileDurableLogSpool, W as createFileDurableMetricSpool, X as createFileDurableSpool, Y as createOtlpLogSink, Z as createOtlpMetricSink, _ as createOtlpTraceSink, $ as createSignalFanout, a0 as describeLogsDeliverability, a1 as describeMetricsDeliverability, a2 as exporterPolicyForDestination, a3 as logSignalOf, a4 as logSignalsForLifecycleEvents, a5 as resolveLogsEndpoint, a6 as resolveMetricsEndpoint, a7 as shareCorrelationPerBatch, a8 as spoolQueueNamesFor, a9 as validateMetricSpoolBatch } from './export-destinations-BjRXDots.js';
2
+ export { C as ContentRestrictor, a as ContentWithholdingReason, D as DestinationFanoutOptions, b as DurableLogSpool, c as DurableLogSpoolOptions, d as DurableMetricSpool, e as DurableMetricSpoolOptions, f as DurableSpool, g as DurableSpoolOptions, E as ExportDestinationSinks, h as ExportDestinationsOptions, L as LOG_MAPPING_VERSION, i as LOG_SIGNALS, j as LogContentPolicy, k as LogMappingOptions, l as LogMappingResult, m as LogSignal, n as LogSpoolBatch, o as LogsDeliverability, M as MAX_LOG_BODY_CHARACTERS, p as MAX_LOG_RECORDS_PER_BATCH, q as MAX_LOG_RECORDS_PER_EVENT, r as MCP_TOOL_NAME_PATTERN, s as MetricExportResult, t as MetricSpoolBatch, u as MetricsDeliverability, N as NO_LOG_CONTENT, O as OtlpLogSinkOptions, v as OtlpLogTelemetrySink, w as OtlpMetricSinkOptions, x as OtlpMetricTelemetrySink, y as OtlpTelemetrySink, z as OtlpTraceSinkOptions, R as RouteEventsOptions, S as ScopedBatch, A as SerializedLogRecord, B as SerializedSpan, F as SharedCorrelationResolver, G as SignalFanoutOptions, H as SignalFanoutSink, I as SkippedExportDestination, J as SpoolBatch, K as SpoolDrainResult, P as SpoolDropCounts, Q as SpoolDropReason, T as SpoolEnqueueResult, U as SpoolOverflowPolicy, V as SpoolSendOutcome, W as SpoolStats, X as canonicalEventsToLogRecords, Y as createDestinationFanout, Z as createExportDestinationSinks, _ as createFileDurableLogSpool, $ as createFileDurableMetricSpool, a0 as createFileDurableSpool, a1 as createOtlpLogSink, a2 as createOtlpMetricSink, a3 as createOtlpTraceSink, a4 as createSignalFanout, a5 as describeLogsDeliverability, a6 as describeMetricsDeliverability, a7 as eventRepositoryKey, a8 as exporterPolicyForDestination, a9 as logSignalOf, aa as logSignalsForLifecycleEvents, ab as omitRestrictedContent, ac as pointRepositoryKey, ad as resolveLogsEndpoint, ae as resolveMetricsEndpoint, af as resourceRepositoryKey, ag as restrictEventContent, ah as routeEventsToScopes, ai as routePointsToScopes, aj as sessionIdVariantsFor, ak as shareCorrelationPerBatch, al as spoolQueueNamesFor, am as validateMetricSpoolBatch } from './export-destinations-DvoH4QOe.js';
3
3
  import { ExportResult } from '@opentelemetry/core';
4
4
  import '@opentelemetry/api';
5
5
  import '@opentelemetry/resources';
6
6
  import '@opentelemetry/sdk-trace';
7
7
  import './events-fcomX6d5.js';
8
8
  import 'zod';
9
- import './destinations-C4sSKjDO.js';
10
- import './schema-CD61uW99.js';
9
+ import './destinations-2KrcRslo.js';
10
+ import './policy-CimmCfRp.js';
11
+ import './content-M9xIKG7h.js';
12
+ import './schema-oRsbo7WO.js';
11
13
  import './ports-DhpSDIkp.js';
12
14
  import './errors.js';
13
15
  import './primitives-CJ8-rn-f.js';
14
16
  import './taxonomy-DwhTtuWd.js';
15
17
  import './keys-Dej5bN3L.js';
16
18
  import '@opentelemetry/sdk-logs';
17
- import './content-M9xIKG7h.js';
18
19
  import './diagnostics.js';
19
20
 
20
21
  /**
package/dist/telemetry.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  } from "@opentelemetry/semantic-conventions/incubating";
19
19
 
20
20
  // src/version.ts
21
- var VERSION = "0.13.2";
21
+ var VERSION = "0.14.0";
22
22
 
23
23
  // src/telemetry/export-identity.ts
24
24
  import { ATTR_SESSION_ID } from "@opentelemetry/semantic-conventions/incubating";
@@ -1378,6 +1378,17 @@ var planGroup = (group, correlation, correlationAvailable) => {
1378
1378
  };
1379
1379
  var runDiscriminatorOf = (correlation) => correlation?.runSpanIdDiscriminator === void 0 ? void 0 : `run:${correlation.runSpanIdDiscriminator}`;
1380
1380
  var resumedSessionParent = (ref, correlation) => ref.family === "session" && correlation?.runSpanIdDiscriminator !== void 0 ? ref : void 0;
1381
+ var spanEndEdgesOf = (events) => {
1382
+ const layout = layoutBatch(events);
1383
+ const ends = /* @__PURE__ */ new Map();
1384
+ for (const [eventId, groupKey] of layout.groupOf) {
1385
+ const end = layout.groups.get(groupKey)?.end;
1386
+ if (end !== void 0) {
1387
+ ends.set(eventId, end);
1388
+ }
1389
+ }
1390
+ return ends;
1391
+ };
1381
1392
  var canonicalEventTraceIdentities = (events, options = {}) => {
1382
1393
  const layout = layoutBatch(events);
1383
1394
  const correlations = indexCorrelations(options.correlations);
@@ -2184,6 +2195,60 @@ var OTLP_HEADER_VARIABLES = Object.freeze({
2184
2195
  logs: "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
2185
2196
  });
2186
2197
 
2198
+ // src/config/repository-key.ts
2199
+ var ATTR_VCS_REPOSITORY_URL_FULL = "vcs.repository.url.full";
2200
+ var MAX_REPOSITORY_REFERENCE_LENGTH = 2048;
2201
+ var SCHEME_PATTERN = /^[a-z][a-z0-9+.-]*:\/\//i;
2202
+ var SCP_LIKE_PATTERN = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/\/)(.+)$/;
2203
+ var trimTrailingSlashes = (value) => {
2204
+ let end = value.length;
2205
+ while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
2206
+ return value.slice(0, end);
2207
+ };
2208
+ var keyOf = (host, pathname) => {
2209
+ const withoutSlashes = trimTrailingSlashes(pathname);
2210
+ const cleanedPath = trimTrailingSlashes(
2211
+ withoutSlashes.toLowerCase().endsWith(".git") ? withoutSlashes.slice(0, -4) : withoutSlashes
2212
+ );
2213
+ if (host.length === 0 || cleanedPath.length === 0 || cleanedPath === "/") {
2214
+ return void 0;
2215
+ }
2216
+ const withSlash = cleanedPath.startsWith("/") ? cleanedPath : `/${cleanedPath}`;
2217
+ return `${host}${withSlash}`.toLowerCase();
2218
+ };
2219
+ var normalizeRepositoryKey = (reference) => {
2220
+ const trimmed = reference.trim();
2221
+ if (trimmed.length === 0 || trimmed.length > MAX_REPOSITORY_REFERENCE_LENGTH) {
2222
+ return void 0;
2223
+ }
2224
+ if (SCHEME_PATTERN.test(trimmed)) {
2225
+ let url;
2226
+ try {
2227
+ url = new URL(trimmed);
2228
+ } catch {
2229
+ return void 0;
2230
+ }
2231
+ if (url.protocol === "file:") {
2232
+ return void 0;
2233
+ }
2234
+ return keyOf(url.hostname, url.pathname);
2235
+ }
2236
+ if (trimmed.startsWith("/") || trimmed.startsWith(".") || trimmed.includes("\\")) {
2237
+ return void 0;
2238
+ }
2239
+ const scp = SCP_LIKE_PATTERN.exec(trimmed);
2240
+ if (scp !== null && !trimmed.split(":")[0]?.includes("/")) {
2241
+ const [, host, pathPart] = scp;
2242
+ return host === void 0 || pathPart === void 0 ? void 0 : keyOf(host, pathPart);
2243
+ }
2244
+ try {
2245
+ const url = new URL(`https://${trimmed}`);
2246
+ return keyOf(url.hostname, url.pathname);
2247
+ } catch {
2248
+ return void 0;
2249
+ }
2250
+ };
2251
+
2187
2252
  // src/config/destinations.ts
2188
2253
  var DEFAULT_DESTINATION_NAME = "default";
2189
2254
  var DESTINATION_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,62}$/;
@@ -2202,6 +2267,30 @@ var headerValueSchema = z12.string().min(1).max(MAX_HEADER_VALUE_LENGTH).refine(
2202
2267
  "an env: header reference must name an environment variable, e.g. env:COLLECTOR_TOKEN"
2203
2268
  );
2204
2269
  var endpointSchema = z12.string().url().max(2048);
2270
+ var MAX_DESTINATION_SCOPES = 64;
2271
+ var MAX_SCOPE_REPOSITORIES = 256;
2272
+ var ALL_REPOSITORIES = "*";
2273
+ var repositoryReferenceSchema = z12.string().min(1).max(MAX_REPOSITORY_REFERENCE_LENGTH).refine(
2274
+ (value) => normalizeRepositoryKey(value) !== void 0,
2275
+ "not a repository URL: use https://host/owner/repo, git@host:owner/repo.git, or host/owner/repo"
2276
+ );
2277
+ var destinationScopeSchema = z12.strictObject({
2278
+ /**
2279
+ * Repository URLs (any spelling of the remote; compared by host and path,
2280
+ * case-insensitively, without `.git`), or `"*"` for every record that names
2281
+ * a repository. A record that names none never matches a scope.
2282
+ */
2283
+ repositories: z12.union([
2284
+ z12.literal(ALL_REPOSITORIES),
2285
+ z12.array(repositoryReferenceSchema).min(1).max(MAX_SCOPE_REPOSITORIES).readonly()
2286
+ ]),
2287
+ /** Signals sent for these repositories. Default: every signal the destination takes. */
2288
+ signals: z12.array(exportSignalSchema).min(1).max(3).readonly().optional(),
2289
+ /** Content disclosure for these repositories, never above `privacy.contentMode`. Default: unchanged. */
2290
+ contentMode: contentModeSchema.optional(),
2291
+ /** False leaves `session.id` off metric data points for these repositories. Default true. */
2292
+ includeSessionId: z12.boolean().optional()
2293
+ });
2205
2294
  var exportDestinationSchema = z12.strictObject({
2206
2295
  /** Unique, lowercase, filesystem-safe. `default` is reserved for the single-endpoint settings. */
2207
2296
  name: z12.string().regex(DESTINATION_NAME_PATTERN, "destination names are lowercase letters, digits, _ and -"),
@@ -2235,7 +2324,15 @@ var exportDestinationSchema = z12.strictObject({
2235
2324
  * opt-in for content-bearing records leaving the host. `metrics` is never on by
2236
2325
  * default: a destination receives hook-derived metrics only when it lists them.
2237
2326
  */
2238
- signals: z12.array(exportSignalSchema).min(1).max(3).readonly().optional()
2327
+ signals: z12.array(exportSignalSchema).min(1).max(3).readonly().optional(),
2328
+ /**
2329
+ * Per-repository filter. Absent: every record goes to this destination, as
2330
+ * before scopes existed. Present: a record goes only when its repository
2331
+ * (`vcs.repository.url.full`) matches a scope — the first matching scope
2332
+ * decides its signals, content mode, and session id — and a record that
2333
+ * names no repository is not sent here at all.
2334
+ */
2335
+ scopes: z12.array(destinationScopeSchema).min(1).max(MAX_DESTINATION_SCOPES).readonly().optional()
2239
2336
  }).refine(
2240
2337
  (destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0 || destination.metricsEndpoint !== void 0,
2241
2338
  "a destination needs an endpoint, or a tracesEndpoint / logsEndpoint / metricsEndpoint"
@@ -2279,6 +2376,32 @@ var effectiveSpoolPolicy = (exporter) => ({
2279
2376
  maxAgeMillis: exporter.spool?.maxAgeMillis ?? DEFAULT_SPOOL_POLICY.maxAgeMillis,
2280
2377
  maxBatches: exporter.spool?.maxBatches ?? DEFAULT_SPOOL_POLICY.maxBatches
2281
2378
  });
2379
+ var resolveDestinationScopes = (scopes, destinationSignals) => scopes.map((scope) => {
2380
+ const listed = scope.signals ?? exportSignalSchema.options;
2381
+ return {
2382
+ repositories: scope.repositories === ALL_REPOSITORIES ? ALL_REPOSITORIES : new Set(
2383
+ scope.repositories.flatMap((reference) => {
2384
+ const key = normalizeRepositoryKey(reference);
2385
+ return key === void 0 ? [] : [key];
2386
+ })
2387
+ ),
2388
+ signals: {
2389
+ traces: destinationSignals.traces && listed.includes("traces"),
2390
+ logs: destinationSignals.logs && listed.includes("logs"),
2391
+ metrics: destinationSignals.metrics && listed.includes("metrics")
2392
+ },
2393
+ ...scope.contentMode === void 0 ? {} : { contentMode: scope.contentMode },
2394
+ includeSessionId: scope.includeSessionId ?? true
2395
+ };
2396
+ });
2397
+ var matchDestinationScope = (scopes, repositoryKey) => {
2398
+ if (repositoryKey === void 0) {
2399
+ return void 0;
2400
+ }
2401
+ return scopes.find(
2402
+ (scope) => scope.repositories === ALL_REPOSITORIES || scope.repositories.has(repositoryKey)
2403
+ );
2404
+ };
2282
2405
  var legacyDestination = (exporter) => ({
2283
2406
  name: DEFAULT_DESTINATION_NAME,
2284
2407
  source: "exporter",
@@ -2303,6 +2426,11 @@ var resolveExportDestinations = (exporter) => {
2303
2426
  continue;
2304
2427
  }
2305
2428
  const signals = destination.signals ?? DEFAULT_DESTINATION_SIGNALS;
2429
+ const flags = {
2430
+ traces: signals.includes("traces"),
2431
+ logs: exporter.logs.enabled && signals.includes("logs"),
2432
+ metrics: signals.includes("metrics")
2433
+ };
2306
2434
  resolved.push({
2307
2435
  name: destination.name,
2308
2436
  source: "destinations",
@@ -2311,12 +2439,9 @@ var resolveExportDestinations = (exporter) => {
2311
2439
  ...destination.tracesEndpoint === void 0 ? {} : { tracesEndpoint: destination.tracesEndpoint },
2312
2440
  ...destination.logsEndpoint === void 0 ? {} : { logsEndpoint: destination.logsEndpoint },
2313
2441
  ...destination.metricsEndpoint === void 0 ? {} : { metricsEndpoint: destination.metricsEndpoint },
2314
- signals: {
2315
- traces: signals.includes("traces"),
2316
- logs: exporter.logs.enabled && signals.includes("logs"),
2317
- metrics: signals.includes("metrics")
2318
- },
2319
- headers: { ...destination.headers ?? {} }
2442
+ signals: flags,
2443
+ headers: { ...destination.headers ?? {} },
2444
+ ...destination.scopes === void 0 ? {} : { scopes: resolveDestinationScopes(destination.scopes, flags) }
2320
2445
  });
2321
2446
  }
2322
2447
  return resolved;
@@ -3989,14 +4114,20 @@ var createSignalFanout = (options) => {
3989
4114
  };
3990
4115
  var shareCorrelationPerBatch = (correlate) => {
3991
4116
  let pending;
3992
- return (events) => {
3993
- if (pending?.events === events) {
4117
+ const resolve = (events) => {
4118
+ if (pending !== void 0 && (pending.events === events || pending.aliases.has(events))) {
3994
4119
  return pending.result;
3995
4120
  }
3996
4121
  const result = correlate(events);
3997
- pending = { events, result };
4122
+ pending = { events, aliases: /* @__PURE__ */ new Set(), result };
3998
4123
  return result;
3999
4124
  };
4125
+ const alias = (subset, batch) => {
4126
+ if (pending?.events === batch && subset !== batch) {
4127
+ pending.aliases.add(subset);
4128
+ }
4129
+ };
4130
+ return Object.assign(resolve, { alias });
4000
4131
  };
4001
4132
 
4002
4133
  // src/telemetry/metric-model.ts
@@ -4625,6 +4756,101 @@ var createOtlpMetricSink = (options) => {
4625
4756
  };
4626
4757
  };
4627
4758
 
4759
+ // src/telemetry/destination-scope.ts
4760
+ var DISCLOSURE_RANK = Object.freeze({
4761
+ omitted: 0,
4762
+ masked: 1,
4763
+ redacted: 2,
4764
+ raw: 3
4765
+ });
4766
+ var omitRestrictedContent = (fact, mode) => {
4767
+ if (fact.text === void 0 || DISCLOSURE_RANK[fact.disclosure] <= DISCLOSURE_RANK[CONTENT_MODE_DISCLOSURE[mode]]) {
4768
+ return fact;
4769
+ }
4770
+ const { text, ...rest } = fact;
4771
+ void text;
4772
+ return { ...rest, disclosure: "omitted", truncated: false };
4773
+ };
4774
+ var keyOfValue = (value) => typeof value === "string" ? normalizeRepositoryKey(value) : void 0;
4775
+ var resourceRepositoryKey = (attributes) => keyOfValue(attributes[ATTR_VCS_REPOSITORY_URL_FULL]);
4776
+ var eventRepositoryKey = (event2, fallbackKey) => {
4777
+ const stamped = event2.contextAttributes?.[ATTR_VCS_REPOSITORY_URL_FULL];
4778
+ return stamped === void 0 ? fallbackKey : keyOfValue(stamped);
4779
+ };
4780
+ var pointRepositoryKey = (point, fallbackKey) => {
4781
+ const stamped = point.attributes[ATTR_VCS_REPOSITORY_URL_FULL];
4782
+ return stamped === void 0 ? fallbackKey : keyOfValue(stamped);
4783
+ };
4784
+ var restrictFacts = (facts, mode, restrict) => facts?.map((fact) => restrict(fact, mode));
4785
+ var restrictEventContent = (event2, mode, restrict) => {
4786
+ switch (event2.type) {
4787
+ case "prompt.submitted":
4788
+ return event2.content === void 0 ? event2 : { ...event2, content: restrict(event2.content, mode) };
4789
+ case "generation.start": {
4790
+ const inputContent = restrictFacts(event2.inputContent, mode, restrict);
4791
+ return inputContent === void 0 ? event2 : { ...event2, inputContent };
4792
+ }
4793
+ case "generation.end": {
4794
+ const outputContent = restrictFacts(event2.outputContent, mode, restrict);
4795
+ return outputContent === void 0 ? event2 : { ...event2, outputContent };
4796
+ }
4797
+ case "tool.start":
4798
+ return event2.input === void 0 ? event2 : { ...event2, input: restrict(event2.input, mode) };
4799
+ case "tool.end":
4800
+ return event2.output === void 0 ? event2 : { ...event2, output: restrict(event2.output, mode) };
4801
+ case "error.raised":
4802
+ return event2.message === void 0 ? event2 : { ...event2, message: restrict(event2.message, mode) };
4803
+ default:
4804
+ return event2;
4805
+ }
4806
+ };
4807
+ var routeEventsToScopes = (events, scopes, options) => {
4808
+ const ends = spanEndEdgesOf(events);
4809
+ const traces = [];
4810
+ const logs = [];
4811
+ let unchanged = true;
4812
+ for (const event2 of events) {
4813
+ const anchor = ends.get(event2.eventId) ?? event2;
4814
+ const scope = matchDestinationScope(scopes, eventRepositoryKey(anchor, options.resourceRepositoryKey));
4815
+ if (scope === void 0 || !scope.signals.traces || !scope.signals.logs) {
4816
+ unchanged = false;
4817
+ }
4818
+ if (scope === void 0) {
4819
+ continue;
4820
+ }
4821
+ const restricted = scope.contentMode === void 0 ? event2 : restrictEventContent(event2, scope.contentMode, options.restrict);
4822
+ if (restricted !== event2) {
4823
+ unchanged = false;
4824
+ }
4825
+ if (scope.signals.traces) {
4826
+ traces.push(restricted);
4827
+ }
4828
+ if (scope.signals.logs) {
4829
+ logs.push(restricted);
4830
+ }
4831
+ }
4832
+ return unchanged ? { traces: events, logs: events } : { traces, logs };
4833
+ };
4834
+ var routePointsToScopes = (scopes, pointsFor, options) => {
4835
+ const effective = (scope) => options.includeSessionId && scope.includeSessionId;
4836
+ const kept = [];
4837
+ for (const variant of [true, false]) {
4838
+ if (!scopes.some((scope) => scope.signals.metrics && effective(scope) === variant)) {
4839
+ continue;
4840
+ }
4841
+ for (const point of pointsFor(variant) ?? []) {
4842
+ const scope = matchDestinationScope(scopes, pointRepositoryKey(point, options.fallbackKey));
4843
+ if (scope?.signals.metrics === true && effective(scope) === variant) {
4844
+ kept.push(point);
4845
+ }
4846
+ }
4847
+ }
4848
+ return kept;
4849
+ };
4850
+ var sessionIdVariantsFor = (scopes, includeSessionId) => new Set(
4851
+ scopes.filter((scope) => scope.signals.metrics).map((scope) => includeSessionId && scope.includeSessionId)
4852
+ );
4853
+
4628
4854
  // src/telemetry/export-destinations.ts
4629
4855
  var spoolQueueNamesFor = (destination) => destination === DEFAULT_DESTINATION_NAME ? { traces: "spool", logs: "spool-logs", metrics: "spool-metrics" } : {
4630
4856
  traces: `destinations/${destination}/spool`,
@@ -4691,6 +4917,8 @@ var createExportDestinationSinks = (options) => {
4691
4917
  ...options.exporter.endpointDownMillis === void 0 ? {} : { downMillis: options.exporter.endpointDownMillis },
4692
4918
  probeMillis: effectiveExportTimeoutMillis(options.exporter) + 1e3
4693
4919
  });
4920
+ const scopedResourceKey = resourceRepositoryKey(resourceFromExporterPolicy(options.exporter).attributes);
4921
+ const restrict = options.restrictContent ?? omitRestrictedContent;
4694
4922
  for (const destination of resolveExportDestinations(options.exporter)) {
4695
4923
  let headers;
4696
4924
  let logHeaders;
@@ -4780,17 +5008,51 @@ var createExportDestinationSinks = (options) => {
4780
5008
  metrics,
4781
5009
  ...spool === void 0 ? {} : { spool },
4782
5010
  ...logSpool === void 0 ? {} : { logSpool },
4783
- ...metricSpool === void 0 ? {} : { metricSpool }
5011
+ ...metricSpool === void 0 ? {} : { metricSpool },
5012
+ ...destination.scopes === void 0 ? {} : {
5013
+ scopes: destination.scopes,
5014
+ route: (events) => routeEventsToScopes(events, destination.scopes ?? [], {
5015
+ ...scopedResourceKey === void 0 ? {} : { resourceRepositoryKey: scopedResourceKey },
5016
+ restrict
5017
+ })
5018
+ }
4784
5019
  });
4785
5020
  }
4786
5021
  return { destinations, skipped };
4787
5022
  };
4788
- var createDestinationFanout = (destinations) => {
5023
+ var createScopedFanout = (destination, correlate) => {
5024
+ const route = destination.route;
5025
+ const unscoped = createSignalFanout({ traces: destination.traces, logs: destination.logs });
5026
+ if (route === void 0) {
5027
+ return unscoped;
5028
+ }
5029
+ const none = { accepted: 0, rejected: 0, errors: [] };
5030
+ return {
5031
+ ...unscoped,
5032
+ emit: async (events) => {
5033
+ const batch = route(events);
5034
+ if (correlate !== void 0 && (batch.traces.length > 0 || batch.logs.length > 0)) {
5035
+ await correlate(events);
5036
+ correlate.alias(batch.traces, events);
5037
+ correlate.alias(batch.logs, events);
5038
+ }
5039
+ const traces = batch.traces.length === 0 ? none : await destination.traces.emit(batch.traces);
5040
+ const logs = batch.logs.length === 0 ? none : await destination.logs.emit(batch.logs);
5041
+ return {
5042
+ accepted: traces.accepted + logs.accepted,
5043
+ rejected: traces.rejected + logs.rejected,
5044
+ errors: [...traces.errors, ...logs.errors]
5045
+ };
5046
+ }
5047
+ };
5048
+ };
5049
+ var createDestinationFanout = (destinations, options = {}) => {
4789
5050
  const fanouts = destinations.map((destination) => ({
4790
5051
  name: destination.name,
4791
- sink: createSignalFanout({ traces: destination.traces, logs: destination.logs })
5052
+ sink: createScopedFanout(destination, options.correlate)
4792
5053
  }));
4793
- const only = fanouts.length === 1 ? fanouts[0] : void 0;
5054
+ const scoped = destinations.some((destination) => destination.route !== void 0);
5055
+ const only = fanouts.length === 1 && !scoped ? fanouts[0] : void 0;
4794
5056
  if (only !== void 0) {
4795
5057
  return only.sink;
4796
5058
  }
@@ -4859,13 +5121,21 @@ export {
4859
5121
  deriveMetricObservations,
4860
5122
  describeLogsDeliverability,
4861
5123
  describeMetricsDeliverability,
5124
+ eventRepositoryKey,
4862
5125
  exporterPolicyForDestination,
4863
5126
  isPermanentExportFailure,
4864
5127
  logSignalOf,
4865
5128
  logSignalsForLifecycleEvents,
5129
+ omitRestrictedContent,
4866
5130
  parentScopeRefOf,
5131
+ pointRepositoryKey,
4867
5132
  resolveLogsEndpoint,
4868
5133
  resolveMetricsEndpoint,
5134
+ resourceRepositoryKey,
5135
+ restrictEventContent,
5136
+ routeEventsToScopes,
5137
+ routePointsToScopes,
5138
+ sessionIdVariantsFor,
4869
5139
  shareCorrelationPerBatch,
4870
5140
  spanScopeRefOf,
4871
5141
  spoolQueueNamesFor,