@osfactory/otel-hook 0.11.0 → 0.13.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 (49) hide show
  1. package/README.md +32 -5
  2. package/dist/{adapter-DiLknaTF.d.ts → adapter-DyCb7y1N.d.ts} +2 -2
  3. package/dist/cli.js +507 -108
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts +3 -3
  6. package/dist/config.js +16 -3
  7. package/dist/config.js.map +1 -1
  8. package/dist/{destinations-BIl3gGzx.d.ts → destinations-DvqsPulb.d.ts} +1 -1
  9. package/dist/{events-CSD_YiJ2.d.ts → events-fcomX6d5.d.ts} +22 -0
  10. package/dist/{export-destinations-QWKGGEjk.d.ts → export-destinations-Bey2djRk.d.ts} +11 -6
  11. package/dist/{filesystem-store-D3SCNmbX.d.ts → filesystem-store-B3CpiIRl.d.ts} +1 -1
  12. package/dist/{hook-BOecWGSz.d.ts → hook-D5imE0Qc.d.ts} +11 -5
  13. package/dist/index.d.ts +14 -14
  14. package/dist/index.js +525 -143
  15. package/dist/index.js.map +1 -1
  16. package/dist/install.d.ts +4 -4
  17. package/dist/install.js +19 -2
  18. package/dist/install.js.map +1 -1
  19. package/dist/integration.d.ts +16 -10
  20. package/dist/integration.js +447 -111
  21. package/dist/integration.js.map +1 -1
  22. package/dist/lifecycle.d.ts +3 -3
  23. package/dist/lifecycle.js +10 -2
  24. package/dist/lifecycle.js.map +1 -1
  25. package/dist/{memory-Cs51jyRk.d.ts → memory-B3r6sZtC.d.ts} +2 -2
  26. package/dist/{metric-model-DDnWxL9d.d.ts → metric-model-CFIeUwqd.d.ts} +6 -2
  27. package/dist/model.d.ts +1 -1
  28. package/dist/model.js +9 -1
  29. package/dist/model.js.map +1 -1
  30. package/dist/{payload-ChtrEX6A.d.ts → payload-CdDKeRpH.d.ts} +1 -1
  31. package/dist/{ports-CeqLq31i.d.ts → ports-DhpSDIkp.d.ts} +41 -3
  32. package/dist/providers.d.ts +30 -14
  33. package/dist/providers.js +131 -42
  34. package/dist/providers.js.map +1 -1
  35. package/dist/{registry-CcJNF3WY.d.ts → registry-BKQhhIO3.d.ts} +2 -2
  36. package/dist/runtime.d.ts +97 -9
  37. package/dist/runtime.js +269 -26
  38. package/dist/runtime.js.map +1 -1
  39. package/dist/{schema-DMnoU1V_.d.ts → schema-SpFM6YQY.d.ts} +24 -1
  40. package/dist/state.d.ts +4 -4
  41. package/dist/state.js +9 -1
  42. package/dist/state.js.map +1 -1
  43. package/dist/telemetry.d.ts +6 -6
  44. package/dist/telemetry.js +80 -22
  45. package/dist/telemetry.js.map +1 -1
  46. package/dist/testing.d.ts +10 -8
  47. package/dist/testing.js +161 -30
  48. package/dist/testing.js.map +1 -1
  49. package/package.json +1 -1
@@ -1,14 +1,14 @@
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-DDnWxL9d.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-QWKGGEjk.js';
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-CFIeUwqd.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-Bey2djRk.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
- import './events-CSD_YiJ2.js';
7
+ import './events-fcomX6d5.js';
8
8
  import 'zod';
9
- import './destinations-BIl3gGzx.js';
10
- import './schema-DMnoU1V_.js';
11
- import './ports-CeqLq31i.js';
9
+ import './destinations-DvqsPulb.js';
10
+ import './schema-SpFM6YQY.js';
11
+ import './ports-DhpSDIkp.js';
12
12
  import './errors.js';
13
13
  import './primitives-CJ8-rn-f.js';
14
14
  import './taxonomy-DwhTtuWd.js';
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.11.0";
21
+ var VERSION = "0.13.0";
22
22
 
23
23
  // src/telemetry/export-identity.ts
24
24
  import { ATTR_SESSION_ID } from "@opentelemetry/semantic-conventions/incubating";
@@ -663,7 +663,15 @@ var baseEventFields = {
663
663
  * factory, never by hand.
664
664
  */
665
665
  subagentId: subagentIdSchema.optional(),
666
- extensions: extensionsSchema.default(emptyExtensions)
666
+ extensions: extensionsSchema.default(emptyExtensions),
667
+ /**
668
+ * Attributes of the session context segment in force when the event
669
+ * occurred (`docs/session-context.md`), stamped by the core from a file a
670
+ * harness wrote. Exported on every record of the event, over the same keys
671
+ * from the Resource. Absent when no context applies. Set by the core only,
672
+ * never by an adapter.
673
+ */
674
+ contextAttributes: z9.record(z9.string().min(1).max(255), z9.union([z9.string(), z9.number(), z9.boolean()])).optional()
667
675
  };
668
676
  var event = (shape) => z9.strictObject({ ...baseEventFields, ...shape });
669
677
  var sessionStartEventSchema = event({
@@ -850,6 +858,11 @@ var passthroughResourceAttributes = (resource) => {
850
858
  }
851
859
  return attributes;
852
860
  };
861
+ var contextAttributesOf = (event2) => event2.contextAttributes === void 0 ? {} : { ...event2.contextAttributes };
862
+ var profileAttributes = (event2, resource) => ({
863
+ ...passthroughResourceAttributes(resource),
864
+ ...contextAttributesOf(event2)
865
+ });
853
866
  var resolveExportedSessionId = (eventSessionId, resource) => {
854
867
  for (const key of EXTERNAL_SESSION_KEY_ATTRIBUTES) {
855
868
  const supplied = resource.attributes[key];
@@ -870,6 +883,8 @@ var hexTraceAttributes = (ids) => ({
870
883
  var exportIdentityAttributes = (event2, resource, ids) => {
871
884
  const { sessionId, providerSessionId } = resolveExportedSessionId(event2.sessionId, resource);
872
885
  return {
886
+ // First, so nothing in the profile layer can replace an identity attribute.
887
+ ...profileAttributes(event2, resource),
873
888
  [ATTR_SESSION_ID]: sessionId,
874
889
  [ATTR_OTELHOOK_SESSION_ID]: providerSessionId,
875
890
  [ATTR_GEN_AI_CONVERSATION_ID]: providerSessionId,
@@ -878,7 +893,6 @@ var exportIdentityAttributes = (event2, resource, ids) => {
878
893
  ...event2.provenance.providerVersion === void 0 ? {} : { [ATTR_OTELHOOK_PROVIDER_VERSION]: event2.provenance.providerVersion },
879
894
  [ATTR_OTELHOOK_WORKSPACE_ID]: event2.workspace.workspaceId,
880
895
  ...event2.subagentId === void 0 ? {} : { [ATTR_OTELHOOK_SUBAGENT_ID]: event2.subagentId },
881
- ...passthroughResourceAttributes(resource),
882
896
  ...hexTraceAttributes(ids)
883
897
  };
884
898
  };
@@ -1029,12 +1043,12 @@ var pickTarget = (attributes) => {
1029
1043
  }
1030
1044
  return picked;
1031
1045
  };
1032
- var withoutTarget = (attributes, resource) => {
1046
+ var withoutTarget = (attributes, resource, event2) => {
1033
1047
  const rest = { ...attributes };
1034
1048
  for (const key of TARGET_KEYS) {
1035
1049
  delete rest[key];
1036
1050
  }
1037
- return { ...rest, ...pickTarget(passthroughResourceAttributes(resource)) };
1051
+ return { ...rest, ...pickTarget(profileAttributes(event2, resource)) };
1038
1052
  };
1039
1053
  var rankOf = (candidate) => {
1040
1054
  const source = candidate[ATTR_OTELHOOK_TARGET_SOURCE];
@@ -1139,7 +1153,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
1139
1153
  name = "session";
1140
1154
  kind = SpanKind.INTERNAL;
1141
1155
  attributes = {
1142
- ...withoutTarget(attributes, resource),
1156
+ ...withoutTarget(attributes, resource, anchor),
1143
1157
  ...strongestTarget([pickTarget(resolved.recovered), start === void 0 ? {} : targetAttributes(start)]),
1144
1158
  ...start?.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: start.agentName },
1145
1159
  ...start?.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: start.agentVersion },
@@ -1181,7 +1195,7 @@ var buildLifecycleSpan = (plan, resource, scope) => {
1181
1195
  kind = SpanKind.CLIENT;
1182
1196
  attributes = {
1183
1197
  // Target keys are re-chosen below as one unit, never mixed across edges.
1184
- ...withoutTarget(attributes, resource),
1198
+ ...withoutTarget(attributes, resource, anchor),
1185
1199
  [ATTR_GEN_AI_TOOL_NAME]: toolName,
1186
1200
  [ATTR_GEN_AI_TOOL_CALL_ID]: start?.toolCallId ?? end?.toolCallId ?? group.ref.scopeKey,
1187
1201
  ...start?.toolKind === void 0 ? {} : { [ATTR_OTELHOOK_TOOL_KIND]: start.toolKind },
@@ -2133,6 +2147,33 @@ var replayResource = (attributes, policy) => {
2133
2147
  }
2134
2148
  return resourceFromAttributes(safe);
2135
2149
  };
2150
+ var agreedContextAttributes = (events) => {
2151
+ const [first, ...rest] = events;
2152
+ if (first?.contextAttributes === void 0) {
2153
+ return {};
2154
+ }
2155
+ const agreed = { ...first.contextAttributes };
2156
+ for (const event2 of rest) {
2157
+ for (const key of Object.keys(agreed)) {
2158
+ if (event2.contextAttributes?.[key] !== agreed[key]) {
2159
+ delete agreed[key];
2160
+ }
2161
+ }
2162
+ }
2163
+ return agreed;
2164
+ };
2165
+ var resourceWithContext = (resource, context) => {
2166
+ const overrides = {};
2167
+ for (const [key, value] of Object.entries(context)) {
2168
+ if (Object.hasOwn(resource.attributes, key) && !isReservedResourceAttributeKey(key) && resource.attributes[key] !== value) {
2169
+ overrides[key] = value;
2170
+ }
2171
+ }
2172
+ if (Object.keys(overrides).length === 0) {
2173
+ return resource;
2174
+ }
2175
+ return resourceFromAttributes({ ...resource.attributes, ...overrides });
2176
+ };
2136
2177
 
2137
2178
  // src/telemetry/otlp-sink.ts
2138
2179
  var chunk = (items, size) => {
@@ -2217,10 +2258,10 @@ var createOtlpTraceSink = (options) => {
2217
2258
  const exportSpans = (spans) => new Promise((resolve) => {
2218
2259
  exporter.export([...spans], (result) => resolve(result));
2219
2260
  });
2220
- const toSpoolBatch = (spans) => ({
2261
+ const toSpoolBatch = (spans, batchResource) => ({
2221
2262
  providerId: options.providerId,
2222
2263
  installationId: options.installationId,
2223
- resourceAttributes: { ...resource.attributes },
2264
+ resourceAttributes: { ...batchResource.attributes },
2224
2265
  instrumentationScope: { name: scope.name, ...scope.version === void 0 ? {} : { version: scope.version } },
2225
2266
  spans: spans.map(serializeSpan),
2226
2267
  enqueuedAt: options.clock.now()
@@ -2250,8 +2291,9 @@ var createOtlpTraceSink = (options) => {
2250
2291
  return { accepted: 0, rejected: 0, errors: [] };
2251
2292
  }
2252
2293
  const resolved = await resolveCorrelations(events);
2294
+ const batchResource = resourceWithContext(resource, agreedContextAttributes(events));
2253
2295
  const spans = canonicalEventsToReadableSpans(events, {
2254
- resource,
2296
+ resource: batchResource,
2255
2297
  instrumentationScope: scope,
2256
2298
  correlations: resolved.correlations,
2257
2299
  ...resolved.available === void 0 ? {} : { correlationAvailable: resolved.available }
@@ -2277,7 +2319,7 @@ var createOtlpTraceSink = (options) => {
2277
2319
  health.recordFailure("telemetry-export-failure", batch.length, options.clock.now());
2278
2320
  const permanent = isPermanentExportFailure(result);
2279
2321
  if (options.spool !== void 0 && !permanent) {
2280
- const spoolResult = await options.spool.enqueue(toSpoolBatch(batch)).catch(() => ({
2322
+ const spoolResult = await options.spool.enqueue(toSpoolBatch(batch, batchResource)).catch(() => ({
2281
2323
  spooled: false,
2282
2324
  reason: "capacity-exceeded"
2283
2325
  }));
@@ -3048,10 +3090,10 @@ var createOtlpLogSink = (options) => {
3048
3090
  const exportRecords = (records) => new Promise((resolve) => {
3049
3091
  exporter.export([...records], (result) => resolve(result));
3050
3092
  });
3051
- const toSpoolBatch = (records) => ({
3093
+ const toSpoolBatch = (records, batchResource) => ({
3052
3094
  providerId: options.providerId,
3053
3095
  installationId: options.installationId,
3054
- resourceAttributes: { ...resource.attributes },
3096
+ resourceAttributes: { ...batchResource.attributes },
3055
3097
  instrumentationScope: {
3056
3098
  name: scope.name,
3057
3099
  ...scope.version === void 0 ? {} : { version: scope.version }
@@ -3086,8 +3128,9 @@ var createOtlpLogSink = (options) => {
3086
3128
  return { accepted: 0, rejected: 0, errors: [] };
3087
3129
  }
3088
3130
  const resolved = await resolveCorrelations(events);
3131
+ const batchResource = resourceWithContext(resource, agreedContextAttributes(events));
3089
3132
  const mapped = canonicalEventsToLogRecords(events, {
3090
- resource,
3133
+ resource: batchResource,
3091
3134
  instrumentationScope: scope,
3092
3135
  content,
3093
3136
  correlations: resolved.correlations,
@@ -3122,7 +3165,7 @@ var createOtlpLogSink = (options) => {
3122
3165
  health.recordFailure("telemetry-export-failure", batch.length, options.clock.now());
3123
3166
  const permanent = isPermanentExportFailure(result);
3124
3167
  if (options.spool !== void 0 && !permanent) {
3125
- const spoolResult = await options.spool.enqueue(toSpoolBatch(batch)).catch(() => ({
3168
+ const spoolResult = await options.spool.enqueue(toSpoolBatch(batch, batchResource)).catch(() => ({
3126
3169
  spooled: false,
3127
3170
  reason: "capacity-exceeded"
3128
3171
  }));
@@ -3407,6 +3450,7 @@ var resolveDestinationHeaders = (headers, environment) => {
3407
3450
  };
3408
3451
 
3409
3452
  // src/config/schema.ts
3453
+ import { isAbsolute } from "path";
3410
3454
  import { z as z14 } from "zod";
3411
3455
  var logsPolicySchema = z14.strictObject({
3412
3456
  enabled: z14.boolean(),
@@ -3508,13 +3552,19 @@ var providersPolicySchema = z14.strictObject({
3508
3552
  readTranscriptUsage: z14.boolean()
3509
3553
  }).optional()
3510
3554
  });
3555
+ var sessionContextPolicySchema = z14.strictObject({
3556
+ /** Absolute path of the context directory. */
3557
+ dir: z14.string().min(1).max(4096).refine((value) => isAbsolute(value), { message: "must be an absolute path" })
3558
+ });
3511
3559
  var otelHookConfigSchema = z14.strictObject({
3512
3560
  exporter: exporterPolicySchema,
3513
3561
  privacy: privacyPolicySchema,
3514
3562
  detection: detectionPolicySchema,
3515
3563
  diagnostics: diagnosticsPolicySchema,
3516
3564
  /** Optional so a hand-built configuration from before it existed stays valid. */
3517
- providers: providersPolicySchema.optional()
3565
+ providers: providersPolicySchema.optional(),
3566
+ /** Optional: absent means no session context is read. */
3567
+ sessionContext: sessionContextPolicySchema.optional()
3518
3568
  });
3519
3569
  var otelHookConfigPatchSchema = z14.strictObject({
3520
3570
  // `logs` is unwrapped and re-partialled for the same reason `privacy.limits` is:
@@ -3530,7 +3580,8 @@ var otelHookConfigPatchSchema = z14.strictObject({
3530
3580
  diagnostics: diagnosticsPolicySchema.partial().optional(),
3531
3581
  providers: z14.strictObject({
3532
3582
  claudeCode: z14.strictObject({ readTranscriptUsage: z14.boolean() }).partial().optional()
3533
- }).partial().optional()
3583
+ }).partial().optional(),
3584
+ sessionContext: sessionContextPolicySchema.partial().optional()
3534
3585
  });
3535
3586
  var DEFAULT_EXPORTER_POLICY = Object.freeze({
3536
3587
  enabled: true,
@@ -3659,6 +3710,9 @@ var ATTR_OTELHOOK_PROVIDER_ID2 = "otelhook.provider.id";
3659
3710
  var ATTR_OTELHOOK_OUTCOME3 = "otelhook.outcome";
3660
3711
  var ATTR_OTELHOOK_SESSION_KIND2 = "otelhook.session.kind";
3661
3712
  var commonAttributes = (event2, resource, includeSessionId) => ({
3713
+ // Session context first, so the metric's own attributes always win; and never
3714
+ // anything account-shaped, whatever the context says.
3715
+ ...event2.contextAttributes === void 0 ? {} : withoutAccountIdentity(event2.contextAttributes),
3662
3716
  [ATTR_OTELHOOK_PROVIDER_ID2]: event2.provenance.providerId,
3663
3717
  ...includeSessionId ? { [ATTR_SESSION_ID2]: resolveExportedSessionId(event2.sessionId, resource).sessionId } : {}
3664
3718
  });
@@ -3705,6 +3759,9 @@ var deriveMetricObservations = (input) => {
3705
3759
  if (recovered !== void 0) {
3706
3760
  return end.occurredAt - recovered.startMillis;
3707
3761
  }
3762
+ if (end.subagentId !== void 0) {
3763
+ return void 0;
3764
+ }
3708
3765
  const turn = lastPromptInBatch?.get(end.sessionId) ?? input.turnStart?.(end.sessionId);
3709
3766
  return turn === void 0 || turn > end.occurredAt ? void 0 : end.occurredAt - turn;
3710
3767
  };
@@ -4081,10 +4138,10 @@ var createOtlpMetricSink = (options) => {
4081
4138
  });
4082
4139
  }
4083
4140
  });
4084
- const toSpoolBatch = (points) => ({
4141
+ const toSpoolBatch = (points, batchResource) => ({
4085
4142
  providerId: options.providerId,
4086
4143
  installationId: options.installationId,
4087
- resourceAttributes: { ...resource.attributes },
4144
+ resourceAttributes: { ...batchResource.attributes },
4088
4145
  instrumentationScope: {
4089
4146
  name: scope.name,
4090
4147
  ...scope.version === void 0 ? {} : { version: scope.version }
@@ -4102,11 +4159,12 @@ var createOtlpMetricSink = (options) => {
4102
4159
  }
4103
4160
  return isPermanentExportFailure(result) ? "discard" : false;
4104
4161
  };
4105
- const exportPoints = async (points) => {
4162
+ const exportPoints = async (points, context) => {
4106
4163
  if (points.length === 0) {
4107
4164
  return { accepted: 0, rejected: 0, errors: [] };
4108
4165
  }
4109
- const result = await exportResourceMetrics(points, resource, scope);
4166
+ const batchResource = context === void 0 ? resource : resourceWithContext(resource, context);
4167
+ const result = await exportResourceMetrics(points, batchResource, scope);
4110
4168
  if (result.code === ExportResultCode3.SUCCESS) {
4111
4169
  health.recordSuccess(points.length, options.clock.now());
4112
4170
  return { accepted: points.length, rejected: 0, errors: [] };
@@ -4114,7 +4172,7 @@ var createOtlpMetricSink = (options) => {
4114
4172
  health.recordFailure("telemetry-export-failure", points.length, options.clock.now());
4115
4173
  const permanent = isPermanentExportFailure(result);
4116
4174
  if (options.spool !== void 0 && !permanent) {
4117
- const spooled = await options.spool.enqueue(toSpoolBatch(points)).catch(() => ({
4175
+ const spooled = await options.spool.enqueue(toSpoolBatch(points, batchResource)).catch(() => ({
4118
4176
  spooled: false,
4119
4177
  reason: "capacity-exceeded"
4120
4178
  }));