@osfactory/otel-hook 0.1.3 → 0.3.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 (45) hide show
  1. package/dist/{adapter-DIgRACtL.d.ts → adapter-DXpNtnaf.d.ts} +2 -2
  2. package/dist/cli.js +442 -134
  3. package/dist/cli.js.map +1 -1
  4. package/dist/config.d.ts +2 -2
  5. package/dist/config.js +5 -1
  6. package/dist/config.js.map +1 -1
  7. package/dist/{content-CoB7aNP1.d.ts → content-M9xIKG7h.d.ts} +8 -1
  8. package/dist/{hook-CGpo-vks.d.ts → hook-_mlO3akA.d.ts} +3 -3
  9. package/dist/index.d.ts +10 -10
  10. package/dist/index.js +443 -134
  11. package/dist/index.js.map +1 -1
  12. package/dist/install.d.ts +5 -5
  13. package/dist/install.js +33 -0
  14. package/dist/install.js.map +1 -1
  15. package/dist/integration.d.ts +8 -8
  16. package/dist/integration.js +115 -39
  17. package/dist/integration.js.map +1 -1
  18. package/dist/lifecycle.d.ts +1 -1
  19. package/dist/lifecycle.js +5 -3
  20. package/dist/lifecycle.js.map +1 -1
  21. package/dist/model.d.ts +1 -1
  22. package/dist/model.js +2 -0
  23. package/dist/model.js.map +1 -1
  24. package/dist/{otlp-log-sink-CeIFDDpn.d.ts → otlp-log-sink-DTSa0KRF.d.ts} +2 -2
  25. package/dist/{payload-CHr53E_v.d.ts → payload-BWV5-4n3.d.ts} +1 -1
  26. package/dist/{policy-D1CrlYn3.d.ts → policy-CimmCfRp.d.ts} +1 -1
  27. package/dist/privacy.d.ts +4 -4
  28. package/dist/privacy.js +11 -0
  29. package/dist/privacy.js.map +1 -1
  30. package/dist/providers.d.ts +8 -8
  31. package/dist/providers.js +322 -94
  32. package/dist/providers.js.map +1 -1
  33. package/dist/{registry-BzYmC9OC.d.ts → registry-Dqr3VNmT.d.ts} +1 -1
  34. package/dist/runtime.d.ts +6 -6
  35. package/dist/runtime.js +13 -1
  36. package/dist/runtime.js.map +1 -1
  37. package/dist/{semconv-Baoz-0OI.d.ts → semconv-CIU-2kGO.d.ts} +1 -0
  38. package/dist/{service-j4jEO6cZ.d.ts → service-CbI9CObT.d.ts} +8 -2
  39. package/dist/telemetry.d.ts +5 -5
  40. package/dist/telemetry.js +102 -38
  41. package/dist/telemetry.js.map +1 -1
  42. package/dist/testing.d.ts +6 -6
  43. package/dist/testing.js +338 -95
  44. package/dist/testing.js.map +1 -1
  45. package/package.json +1 -1
@@ -164,6 +164,7 @@ type SemanticMappingOptions = {
164
164
  type EventTraceIdentity = {
165
165
  readonly traceId: string;
166
166
  readonly spanId: string;
167
+ readonly parentSpanId?: string;
167
168
  };
168
169
  /**
169
170
  * Resolve the trace and span identity of every event in one batch.
@@ -1,6 +1,6 @@
1
- import { c as ContentKind, d as ContentRole, b as ContentFact } from './content-CoB7aNP1.js';
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-D1CrlYn3.js';
3
+ import { f as PrivacyPolicy } from './policy-CimmCfRp.js';
4
4
 
5
5
  type SanitizedValue = string | number | boolean | null | readonly SanitizedValue[] | {
6
6
  readonly [key: string]: SanitizedValue;
@@ -50,6 +50,12 @@ interface PrivacyService {
50
50
  /** Opaque namespaced handle suitable for a workspace or resource id. */
51
51
  deriveOpaqueId(namespace: string, value: string): string;
52
52
  describeContent(input: DescribeContentInput): ContentFact;
53
+ /**
54
+ * A content fact for a kind the event can carry when the provider sent no
55
+ * text. Distinct from describing an empty string: there is nothing to
56
+ * disclose under any content mode, so the fact is always omitted.
57
+ */
58
+ describeUnavailableContent(input: Omit<DescribeContentInput, "text">): ContentFact;
53
59
  describeStructured(input: DescribeStructuredInput): ContentFact;
54
60
  isSecretKey(key: string): boolean;
55
61
  sanitizeStructured(value: unknown): SanitizeResult;
@@ -1,7 +1,7 @@
1
- import { b as SpanCorrelationResolver } from './semconv-Baoz-0OI.js';
2
- export { D as DEFAULT_INSTRUMENTATION_SCOPE, E as EventTraceIdentity, M as MAX_RECOVERED_START_ATTRIBUTES, S as SemanticMappingOptions, a as SpanCorrelation, c as SpanDisposition, d as SpanFamily, e as SpanOrphanClassification, f as SpanPairing, g as SpanScopeRef, h as canonicalEventTraceIdentities, i as canonicalEventsToReadableSpans, p as parentScopeRefOf, s as spanScopeRefOf, j as startOnlySpanAttributes } from './semconv-Baoz-0OI.js';
3
- import { o as OtlpTelemetrySink, n as OtlpLogTelemetrySink } from './otlp-log-sink-CeIFDDpn.js';
4
- export { C as ContentWithholdingReason, D as DurableLogSpool, a as DurableLogSpoolOptions, b as DurableSpool, c as DurableSpoolOptions, L as LOG_MAPPING_VERSION, d as LOG_SIGNALS, e as LogContentPolicy, f as LogMappingOptions, g as LogMappingResult, h as LogSignal, i as LogSpoolBatch, j as LogsDeliverability, M as MAX_LOG_BODY_CHARACTERS, k as MAX_LOG_RECORDS_PER_BATCH, l as MAX_LOG_RECORDS_PER_EVENT, m as MCP_TOOL_NAME_PATTERN, N as NO_LOG_CONTENT, O as OtlpLogSinkOptions, p as OtlpTraceSinkOptions, S as SerializedLogRecord, q as SerializedSpan, r as SpoolBatch, s as SpoolDrainResult, t as SpoolEnqueueResult, u as canonicalEventsToLogRecords, v as createFileDurableLogSpool, w as createFileDurableSpool, x as createOtlpLogSink, y as createOtlpTraceSink, z as describeLogsDeliverability, A as logSignalOf, B as logSignalsForLifecycleEvents, E as resolveLogsEndpoint } from './otlp-log-sink-CeIFDDpn.js';
1
+ import { b as SpanCorrelationResolver } from './semconv-CIU-2kGO.js';
2
+ export { D as DEFAULT_INSTRUMENTATION_SCOPE, E as EventTraceIdentity, M as MAX_RECOVERED_START_ATTRIBUTES, S as SemanticMappingOptions, a as SpanCorrelation, c as SpanDisposition, d as SpanFamily, e as SpanOrphanClassification, f as SpanPairing, g as SpanScopeRef, h as canonicalEventTraceIdentities, i as canonicalEventsToReadableSpans, p as parentScopeRefOf, s as spanScopeRefOf, j as startOnlySpanAttributes } from './semconv-CIU-2kGO.js';
3
+ import { o as OtlpTelemetrySink, n as OtlpLogTelemetrySink } from './otlp-log-sink-DTSa0KRF.js';
4
+ export { C as ContentWithholdingReason, D as DurableLogSpool, a as DurableLogSpoolOptions, b as DurableSpool, c as DurableSpoolOptions, L as LOG_MAPPING_VERSION, d as LOG_SIGNALS, e as LogContentPolicy, f as LogMappingOptions, g as LogMappingResult, h as LogSignal, i as LogSpoolBatch, j as LogsDeliverability, M as MAX_LOG_BODY_CHARACTERS, k as MAX_LOG_RECORDS_PER_BATCH, l as MAX_LOG_RECORDS_PER_EVENT, m as MCP_TOOL_NAME_PATTERN, N as NO_LOG_CONTENT, O as OtlpLogSinkOptions, p as OtlpTraceSinkOptions, S as SerializedLogRecord, q as SerializedSpan, r as SpoolBatch, s as SpoolDrainResult, t as SpoolEnqueueResult, u as canonicalEventsToLogRecords, v as createFileDurableLogSpool, w as createFileDurableSpool, x as createOtlpLogSink, y as createOtlpTraceSink, z as describeLogsDeliverability, A as logSignalOf, B as logSignalsForLifecycleEvents, E as resolveLogsEndpoint } from './otlp-log-sink-DTSa0KRF.js';
5
5
  import { DeliveryHealthSnapshot } from './diagnostics.js';
6
6
  import { f as TelemetrySink } from './ports-Q8x0ODhs.js';
7
7
  import '@opentelemetry/api';
@@ -13,7 +13,7 @@ import 'zod';
13
13
  import './schema-Cn0-xz8L.js';
14
14
  import './keys-Dej5bN3L.js';
15
15
  import '@opentelemetry/sdk-logs';
16
- import './content-CoB7aNP1.js';
16
+ import './content-M9xIKG7h.js';
17
17
  import './primitives-CJ8-rn-f.js';
18
18
  import './taxonomy-DwhTtuWd.js';
19
19
  import './errors.js';
package/dist/telemetry.js CHANGED
@@ -34,12 +34,65 @@ import {
34
34
  ATTR_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS,
35
35
  ATTR_GEN_AI_USAGE_INPUT_TOKENS,
36
36
  ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,
37
- ATTR_GEN_AI_USAGE_REASONING_OUTPUT_TOKENS,
38
- ATTR_SESSION_ID
37
+ ATTR_GEN_AI_USAGE_REASONING_OUTPUT_TOKENS
39
38
  } from "@opentelemetry/semantic-conventions/incubating";
40
39
 
41
40
  // src/version.ts
42
- var VERSION = "0.1.3";
41
+ var VERSION = "0.3.0";
42
+
43
+ // src/telemetry/export-identity.ts
44
+ import { ATTR_SESSION_ID } from "@opentelemetry/semantic-conventions/incubating";
45
+ var ATTR_TRACE_ID = "trace_id";
46
+ var ATTR_SPAN_ID = "span_id";
47
+ var ATTR_PARENT_SPAN_ID = "parent_span_id";
48
+ var ATTR_OTELHOOK_SESSION_ID = "otelhook.session.id";
49
+ var ATTR_GEN_AI_CONVERSATION_ID = "gen_ai.conversation.id";
50
+ var TRACE_ID_HEX_PATTERN = /^[0-9a-f]{32}$/;
51
+ var SPAN_ID_HEX_PATTERN = /^[0-9a-f]{16}$/;
52
+ var ATTR_OTELHOOK_INVOCATION_ID = "otelhook.invocation.id";
53
+ var ATTR_OTELHOOK_PROVIDER_ID = "otelhook.provider.id";
54
+ var ATTR_OTELHOOK_PROVIDER_VERSION = "otelhook.provider.version";
55
+ var ATTR_OTELHOOK_WORKSPACE_ID = "otelhook.workspace.id";
56
+ var HAR_SESSION_KEY = "har.session_key";
57
+ var isPrimitiveAttribute = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean";
58
+ var passthroughHarAttributes = (resource) => {
59
+ const attributes = {};
60
+ for (const [key, value] of Object.entries(resource.attributes)) {
61
+ if (key.startsWith("har.") && isPrimitiveAttribute(value)) {
62
+ attributes[key] = value;
63
+ }
64
+ }
65
+ return attributes;
66
+ };
67
+ var resolveExportedSessionId = (eventSessionId, resource) => {
68
+ const har = resource.attributes[HAR_SESSION_KEY];
69
+ if (typeof har === "string") {
70
+ const trimmed = har.trim();
71
+ if (trimmed.length > 0) {
72
+ return { sessionId: trimmed, providerSessionId: eventSessionId };
73
+ }
74
+ }
75
+ return { sessionId: eventSessionId, providerSessionId: eventSessionId };
76
+ };
77
+ var hexTraceAttributes = (ids) => ({
78
+ ...TRACE_ID_HEX_PATTERN.test(ids.traceId) ? { [ATTR_TRACE_ID]: ids.traceId } : {},
79
+ ...SPAN_ID_HEX_PATTERN.test(ids.spanId) ? { [ATTR_SPAN_ID]: ids.spanId } : {},
80
+ ...ids.parentSpanId !== void 0 && SPAN_ID_HEX_PATTERN.test(ids.parentSpanId) ? { [ATTR_PARENT_SPAN_ID]: ids.parentSpanId } : {}
81
+ });
82
+ var exportIdentityAttributes = (event, resource, ids) => {
83
+ const { sessionId, providerSessionId } = resolveExportedSessionId(event.sessionId, resource);
84
+ return {
85
+ [ATTR_SESSION_ID]: sessionId,
86
+ [ATTR_OTELHOOK_SESSION_ID]: providerSessionId,
87
+ [ATTR_GEN_AI_CONVERSATION_ID]: providerSessionId,
88
+ [ATTR_OTELHOOK_INVOCATION_ID]: event.invocationId,
89
+ [ATTR_OTELHOOK_PROVIDER_ID]: event.provenance.providerId,
90
+ ...event.provenance.providerVersion === void 0 ? {} : { [ATTR_OTELHOOK_PROVIDER_VERSION]: event.provenance.providerVersion },
91
+ [ATTR_OTELHOOK_WORKSPACE_ID]: event.workspace.workspaceId,
92
+ ...passthroughHarAttributes(resource),
93
+ ...hexTraceAttributes(ids)
94
+ };
95
+ };
43
96
 
44
97
  // src/telemetry/semconv.ts
45
98
  var SCOPE_NAME = "@osfactory/otel-hook";
@@ -47,10 +100,6 @@ var DEFAULT_INSTRUMENTATION_SCOPE = Object.freeze({
47
100
  name: SCOPE_NAME,
48
101
  version: VERSION
49
102
  });
50
- var ATTR_OTELHOOK_INVOCATION_ID = "otelhook.invocation.id";
51
- var ATTR_OTELHOOK_PROVIDER_ID = "otelhook.provider.id";
52
- var ATTR_OTELHOOK_PROVIDER_VERSION = "otelhook.provider.version";
53
- var ATTR_OTELHOOK_WORKSPACE_ID = "otelhook.workspace.id";
54
103
  var ATTR_OTELHOOK_SPAN_PAIRED = "otelhook.span.paired";
55
104
  var ATTR_OTELHOOK_SPAN_PAIRING = "otelhook.span.pairing";
56
105
  var ATTR_OTELHOOK_SPAN_ORPHAN = "otelhook.span.orphan";
@@ -148,13 +197,7 @@ var outcomeStatus = (outcome) => {
148
197
  }
149
198
  return { code: SpanStatusCode.ERROR, message: outcome };
150
199
  };
151
- var identityAttributes = (event) => ({
152
- [ATTR_SESSION_ID]: event.sessionId,
153
- [ATTR_OTELHOOK_INVOCATION_ID]: event.invocationId,
154
- [ATTR_OTELHOOK_PROVIDER_ID]: event.provenance.providerId,
155
- ...event.provenance.providerVersion === void 0 ? {} : { [ATTR_OTELHOOK_PROVIDER_VERSION]: event.provenance.providerVersion },
156
- [ATTR_OTELHOOK_WORKSPACE_ID]: event.workspace.workspaceId
157
- });
200
+ var identityAttributes = (event, resource, ids) => exportIdentityAttributes(event, resource, ids);
158
201
  var usageAttributes = (usage, resetDetected) => {
159
202
  if (usage === void 0) {
160
203
  return {};
@@ -238,7 +281,11 @@ var buildLifecycleSpan = (plan, resource, scope) => {
238
281
  let kind = SpanKind.INTERNAL;
239
282
  let status = { code: SpanStatusCode.UNSET };
240
283
  let attributes = {
241
- ...identityAttributes(anchor),
284
+ ...identityAttributes(anchor, resource, {
285
+ traceId,
286
+ spanId,
287
+ ...parentSpanId === void 0 ? {} : { parentSpanId }
288
+ }),
242
289
  ...resolved.recovered,
243
290
  [ATTR_OTELHOOK_SPAN_PAIRED]: resolved.pairing !== "unpaired",
244
291
  [ATTR_OTELHOOK_SPAN_PAIRING]: resolved.pairing,
@@ -333,7 +380,15 @@ var buildStandaloneSpan = (event, resource, scope) => {
333
380
  const traceId = deriveTraceId(providerId, event.sessionId);
334
381
  const spanId = deriveStandaloneSpanId(providerId, event.sessionId, event.type, event.eventId);
335
382
  const parent = parentScopeRefOf(event);
336
- let attributes = { ...identityAttributes(event), [ATTR_OTELHOOK_SPAN_PAIRED]: true };
383
+ const parentSpanId = parent === void 0 ? void 0 : deriveSpanId(providerId, event.sessionId, parent);
384
+ let attributes = {
385
+ ...identityAttributes(event, resource, {
386
+ traceId,
387
+ spanId,
388
+ ...parentSpanId === void 0 ? {} : { parentSpanId }
389
+ }),
390
+ [ATTR_OTELHOOK_SPAN_PAIRED]: true
391
+ };
337
392
  let status = { code: SpanStatusCode.UNSET };
338
393
  let name = event.type;
339
394
  switch (event.type) {
@@ -371,7 +426,7 @@ var buildStandaloneSpan = (event, resource, scope) => {
371
426
  status,
372
427
  traceId,
373
428
  spanId,
374
- ...parent === void 0 ? {} : { parentSpanId: deriveSpanId(providerId, event.sessionId, parent) },
429
+ ...parentSpanId === void 0 ? {} : { parentSpanId },
375
430
  resource,
376
431
  instrumentationScope: scope
377
432
  });
@@ -470,13 +525,20 @@ var canonicalEventTraceIdentities = (events, options = {}) => {
470
525
  const groupKey = layout.groupOf.get(event.eventId);
471
526
  const plan = groupKey === void 0 ? void 0 : plans.get(groupKey);
472
527
  if (plan === void 0) {
528
+ const parent2 = parentScopeRefOf(event);
473
529
  identities.set(event.eventId, {
474
530
  traceId: deriveTraceId(providerId, event.sessionId),
475
- spanId: deriveStandaloneSpanId(providerId, event.sessionId, event.type, event.eventId)
531
+ spanId: deriveStandaloneSpanId(providerId, event.sessionId, event.type, event.eventId),
532
+ ...parent2 === void 0 ? {} : { parentSpanId: deriveSpanId(providerId, event.sessionId, parent2) }
476
533
  });
477
534
  continue;
478
535
  }
479
- identities.set(event.eventId, { traceId: plan.traceId, spanId: plan.spanId });
536
+ const parent = plan.correlation?.parent ?? parentScopeRefOf(event);
537
+ identities.set(event.eventId, {
538
+ traceId: plan.traceId,
539
+ spanId: plan.spanId,
540
+ ...parent === void 0 ? {} : { parentSpanId: deriveSpanId(providerId, event.sessionId, parent) }
541
+ });
480
542
  }
481
543
  return identities;
482
544
  };
@@ -1448,9 +1510,10 @@ import {
1448
1510
  ATTR_GEN_AI_SYSTEM as ATTR_GEN_AI_SYSTEM2,
1449
1511
  ATTR_GEN_AI_TOOL_CALL_ID as ATTR_GEN_AI_TOOL_CALL_ID2,
1450
1512
  ATTR_GEN_AI_TOOL_NAME as ATTR_GEN_AI_TOOL_NAME2,
1513
+ ATTR_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS as ATTR_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS2,
1514
+ ATTR_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS as ATTR_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS2,
1451
1515
  ATTR_GEN_AI_USAGE_INPUT_TOKENS as ATTR_GEN_AI_USAGE_INPUT_TOKENS2,
1452
- ATTR_GEN_AI_USAGE_OUTPUT_TOKENS as ATTR_GEN_AI_USAGE_OUTPUT_TOKENS2,
1453
- ATTR_SESSION_ID as ATTR_SESSION_ID2
1516
+ ATTR_GEN_AI_USAGE_OUTPUT_TOKENS as ATTR_GEN_AI_USAGE_OUTPUT_TOKENS2
1454
1517
  } from "@opentelemetry/semantic-conventions/incubating";
1455
1518
  var LOG_MAPPING_VERSION = 1;
1456
1519
  var LOG_SIGNALS = [
@@ -1470,10 +1533,6 @@ var MCP_TOOL_NAME_PATTERN = /^mcp__/i;
1470
1533
  var MAX_LOG_RECORDS_PER_EVENT = 64;
1471
1534
  var MAX_LOG_RECORDS_PER_BATCH = 2048;
1472
1535
  var MAX_LOG_BODY_CHARACTERS = 8192;
1473
- var ATTR_OTELHOOK_INVOCATION_ID2 = "otelhook.invocation.id";
1474
- var ATTR_OTELHOOK_PROVIDER_ID2 = "otelhook.provider.id";
1475
- var ATTR_OTELHOOK_PROVIDER_VERSION2 = "otelhook.provider.version";
1476
- var ATTR_OTELHOOK_WORKSPACE_ID2 = "otelhook.workspace.id";
1477
1536
  var ATTR_OTELHOOK_EVENT_TYPE = "otelhook.event.type";
1478
1537
  var ATTR_OTELHOOK_EVENT_ID = "otelhook.event.id";
1479
1538
  var ATTR_OTELHOOK_EVENT_SEQUENCE = "otelhook.event.sequence";
@@ -1625,13 +1684,7 @@ var SEVERITY_TEXT = Object.freeze({
1625
1684
  [SeverityNumber.WARN]: "WARN",
1626
1685
  [SeverityNumber.ERROR]: "ERROR"
1627
1686
  });
1628
- var identityAttributes2 = (event) => ({
1629
- [ATTR_SESSION_ID2]: event.sessionId,
1630
- [ATTR_OTELHOOK_INVOCATION_ID2]: event.invocationId,
1631
- [ATTR_OTELHOOK_PROVIDER_ID2]: event.provenance.providerId,
1632
- ...event.provenance.providerVersion === void 0 ? {} : { [ATTR_OTELHOOK_PROVIDER_VERSION2]: event.provenance.providerVersion },
1633
- [ATTR_OTELHOOK_WORKSPACE_ID2]: event.workspace.workspaceId
1634
- });
1687
+ var identityAttributes2 = (event, resource, ids) => exportIdentityAttributes(event, resource, ids);
1635
1688
  var eventAttributes = (event) => {
1636
1689
  switch (event.type) {
1637
1690
  case "session.start":
@@ -1712,7 +1765,9 @@ var eventAttributes = (event) => {
1712
1765
  };
1713
1766
  var usageAttributes2 = (usage) => usage === void 0 ? {} : {
1714
1767
  [ATTR_GEN_AI_USAGE_INPUT_TOKENS2]: usage.inputTokens,
1715
- [ATTR_GEN_AI_USAGE_OUTPUT_TOKENS2]: usage.outputTokens
1768
+ [ATTR_GEN_AI_USAGE_OUTPUT_TOKENS2]: usage.outputTokens,
1769
+ [ATTR_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS2]: usage.cachedInputTokens,
1770
+ [ATTR_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS2]: usage.cacheCreationInputTokens
1716
1771
  };
1717
1772
  var contentFactsOf = (event) => {
1718
1773
  switch (event.type) {
@@ -1733,6 +1788,9 @@ var contentFactsOf = (event) => {
1733
1788
  }
1734
1789
  };
1735
1790
  var discloseBody = (fact, policy) => {
1791
+ if (fact.text === void 0 && fact.characterLength === 0) {
1792
+ return { metadataOnly: true };
1793
+ }
1736
1794
  if (fact.text === void 0) {
1737
1795
  return { withheld: "privacy-policy" };
1738
1796
  }
@@ -1748,14 +1806,14 @@ var discloseBody = (fact, policy) => {
1748
1806
  var contentAttributes = (fact, body) => ({
1749
1807
  [ATTR_CONTENT_KIND]: fact.kind,
1750
1808
  ...fact.role === void 0 ? {} : { [ATTR_CONTENT_ROLE]: fact.role },
1751
- [ATTR_CONTENT_DISCLOSURE]: fact.disclosure,
1809
+ [ATTR_CONTENT_DISCLOSURE]: "metadataOnly" in body ? "metadata_only" : fact.disclosure,
1752
1810
  [ATTR_CONTENT_CHARACTER_LENGTH]: fact.characterLength,
1753
1811
  [ATTR_CONTENT_BYTE_LENGTH]: fact.byteLength,
1754
1812
  [ATTR_CONTENT_HASH]: fact.contentHash,
1755
1813
  [ATTR_CONTENT_TRUNCATED]: fact.truncated,
1756
1814
  [ATTR_CONTENT_SECRETS_REDACTED]: fact.secretsRedacted,
1757
1815
  ...fact.label === void 0 ? {} : { [ATTR_CONTENT_LABEL]: fact.label },
1758
- ..."withheld" in body ? { [ATTR_CONTENT_WITHHELD]: body.withheld } : { [ATTR_CONTENT_BODY_TRUNCATED]: body.truncated }
1816
+ ..."withheld" in body ? { [ATTR_CONTENT_WITHHELD]: body.withheld } : "metadataOnly" in body ? {} : { [ATTR_CONTENT_BODY_TRUNCATED]: body.truncated }
1759
1817
  });
1760
1818
  var buildRecord = (input) => {
1761
1819
  const severityNumber = severityFor(input.event);
@@ -1775,7 +1833,11 @@ var buildRecord = (input) => {
1775
1833
  resource: input.resource,
1776
1834
  instrumentationScope: input.scope,
1777
1835
  attributes: {
1778
- ...identityAttributes2(input.event),
1836
+ ...identityAttributes2(input.event, input.resource, {
1837
+ traceId: input.spanContext.traceId,
1838
+ spanId: input.spanContext.spanId,
1839
+ ...input.parentSpanId === void 0 ? {} : { parentSpanId: input.parentSpanId }
1840
+ }),
1779
1841
  [ATTR_OTELHOOK_EVENT_TYPE]: input.event.type,
1780
1842
  [ATTR_OTELHOOK_EVENT_ID]: input.event.eventId,
1781
1843
  [ATTR_OTELHOOK_EVENT_SEQUENCE]: input.event.sequence,
@@ -1817,8 +1879,9 @@ var canonicalEventsToLogRecords = (events, options) => {
1817
1879
  buildRecord({
1818
1880
  event,
1819
1881
  signal: logSignalOf(event),
1820
- attributes: shared,
1882
+ attributes: event.type === "generation.end" ? { ...shared, [ATTR_CONTENT_KIND]: "response", [ATTR_CONTENT_DISCLOSURE]: "metadata_only" } : shared,
1821
1883
  spanContext,
1884
+ ...identity.parentSpanId === void 0 ? {} : { parentSpanId: identity.parentSpanId },
1822
1885
  resource: options.resource,
1823
1886
  scope
1824
1887
  })
@@ -1838,8 +1901,9 @@ var canonicalEventsToLogRecords = (events, options) => {
1838
1901
  event,
1839
1902
  signal: logSignalOf(event, fact.kind),
1840
1903
  attributes: { ...shared, ...contentAttributes(fact, body) },
1841
- ..."withheld" in body ? {} : { body: body.text },
1904
+ ..."text" in body ? { body: body.text } : {},
1842
1905
  spanContext,
1906
+ ...identity.parentSpanId === void 0 ? {} : { parentSpanId: identity.parentSpanId },
1843
1907
  resource: options.resource,
1844
1908
  scope
1845
1909
  })