autotel 2.22.0 → 2.23.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 (110) hide show
  1. package/README.md +112 -6
  2. package/dist/auto.cjs +3 -3
  3. package/dist/auto.js +2 -2
  4. package/dist/{chunk-EWH2542B.js → chunk-3AMR5XLZ.js} +3 -3
  5. package/dist/{chunk-EWH2542B.js.map → chunk-3AMR5XLZ.js.map} +1 -1
  6. package/dist/chunk-3QXBFGKP.js +344 -0
  7. package/dist/chunk-3QXBFGKP.js.map +1 -0
  8. package/dist/{chunk-VQFF2WMP.cjs → chunk-3ZFDJJWZ.cjs} +37 -29
  9. package/dist/chunk-3ZFDJJWZ.cjs.map +1 -0
  10. package/dist/{chunk-CQC6RVLR.cjs → chunk-4RZ4JUBY.cjs} +5 -5
  11. package/dist/{chunk-CQC6RVLR.cjs.map → chunk-4RZ4JUBY.cjs.map} +1 -1
  12. package/dist/{chunk-PAVYKPCQ.js → chunk-5XUEHX7J.js} +3 -3
  13. package/dist/{chunk-PAVYKPCQ.js.map → chunk-5XUEHX7J.js.map} +1 -1
  14. package/dist/chunk-6S5RUKU3.cjs +347 -0
  15. package/dist/chunk-6S5RUKU3.cjs.map +1 -0
  16. package/dist/{chunk-BS757SL2.js → chunk-724XLWR3.js} +9 -4
  17. package/dist/chunk-724XLWR3.js.map +1 -0
  18. package/dist/chunk-7EQ4G4SI.cjs +146 -0
  19. package/dist/chunk-7EQ4G4SI.cjs.map +1 -0
  20. package/dist/{chunk-CQP5SQT4.cjs → chunk-AXFWWJF3.cjs} +7 -7
  21. package/dist/{chunk-CQP5SQT4.cjs.map → chunk-AXFWWJF3.cjs.map} +1 -1
  22. package/dist/{chunk-7NH625MS.cjs → chunk-BSZP4URK.cjs} +5 -5
  23. package/dist/{chunk-7NH625MS.cjs.map → chunk-BSZP4URK.cjs.map} +1 -1
  24. package/dist/{chunk-GZFH6P5U.js → chunk-GY4CRZSV.js} +14 -6
  25. package/dist/chunk-GY4CRZSV.js.map +1 -0
  26. package/dist/{chunk-QKUGUDXJ.cjs → chunk-HSEIUH7F.cjs} +10 -5
  27. package/dist/chunk-HSEIUH7F.cjs.map +1 -0
  28. package/dist/{chunk-DTW3WB7Z.js → chunk-IPKXURBW.js} +3 -3
  29. package/dist/{chunk-DTW3WB7Z.js.map → chunk-IPKXURBW.js.map} +1 -1
  30. package/dist/chunk-J7VGRIAJ.js +64 -0
  31. package/dist/chunk-J7VGRIAJ.js.map +1 -0
  32. package/dist/chunk-KFOHQK7X.js +144 -0
  33. package/dist/chunk-KFOHQK7X.js.map +1 -0
  34. package/dist/{chunk-4UYR46UP.cjs → chunk-MSUHW2I4.cjs} +13 -13
  35. package/dist/{chunk-4UYR46UP.cjs.map → chunk-MSUHW2I4.cjs.map} +1 -1
  36. package/dist/chunk-T4B5LB6E.cjs +66 -0
  37. package/dist/chunk-T4B5LB6E.cjs.map +1 -0
  38. package/dist/{chunk-QHT4MUED.js → chunk-WCIIFRGL.js} +3 -3
  39. package/dist/{chunk-QHT4MUED.js.map → chunk-WCIIFRGL.js.map} +1 -1
  40. package/dist/decorators.cjs +3 -3
  41. package/dist/decorators.js +3 -3
  42. package/dist/drain-pipeline.cjs +13 -0
  43. package/dist/drain-pipeline.cjs.map +1 -0
  44. package/dist/drain-pipeline.d.cts +37 -0
  45. package/dist/drain-pipeline.d.ts +37 -0
  46. package/dist/drain-pipeline.js +4 -0
  47. package/dist/drain-pipeline.js.map +1 -0
  48. package/dist/event.cjs +6 -6
  49. package/dist/event.js +3 -3
  50. package/dist/functional.cjs +10 -10
  51. package/dist/functional.js +3 -3
  52. package/dist/index.cjs +256 -41
  53. package/dist/index.cjs.map +1 -1
  54. package/dist/index.d.cts +72 -3
  55. package/dist/index.d.ts +72 -3
  56. package/dist/index.js +210 -11
  57. package/dist/index.js.map +1 -1
  58. package/dist/{init-BMiXSJNM.d.cts → init-BC5aN8bh.d.cts} +18 -0
  59. package/dist/{init-ByRbNTRo.d.ts → init-_FG4IbhF.d.ts} +18 -0
  60. package/dist/instrumentation.cjs +9 -9
  61. package/dist/instrumentation.js +2 -2
  62. package/dist/messaging.cjs +7 -7
  63. package/dist/messaging.js +4 -4
  64. package/dist/parse-error.cjs +13 -0
  65. package/dist/parse-error.cjs.map +1 -0
  66. package/dist/parse-error.d.cts +13 -0
  67. package/dist/parse-error.d.ts +13 -0
  68. package/dist/parse-error.js +4 -0
  69. package/dist/parse-error.js.map +1 -0
  70. package/dist/processors.cjs +2 -2
  71. package/dist/processors.d.cts +40 -4
  72. package/dist/processors.d.ts +40 -4
  73. package/dist/processors.js +1 -1
  74. package/dist/semantic-helpers.cjs +8 -8
  75. package/dist/semantic-helpers.js +4 -4
  76. package/dist/webhook.cjs +4 -4
  77. package/dist/webhook.js +3 -3
  78. package/dist/workflow-distributed.cjs +5 -5
  79. package/dist/workflow-distributed.js +3 -3
  80. package/dist/workflow.cjs +8 -8
  81. package/dist/workflow.js +4 -4
  82. package/dist/yaml-config.d.cts +2 -1
  83. package/dist/yaml-config.d.ts +2 -1
  84. package/package.json +11 -1
  85. package/src/drain-pipeline.test.ts +68 -0
  86. package/src/drain-pipeline.ts +199 -0
  87. package/src/flatten-attributes.test.ts +76 -0
  88. package/src/flatten-attributes.ts +80 -0
  89. package/src/functional.test.ts +63 -0
  90. package/src/functional.ts +11 -3
  91. package/src/index.ts +33 -0
  92. package/src/init.ts +22 -0
  93. package/src/parse-error.test.ts +73 -0
  94. package/src/parse-error.ts +112 -0
  95. package/src/pretty-log-formatter.test.ts +123 -0
  96. package/src/pretty-log-formatter.ts +210 -0
  97. package/src/processors/canonical-log-line-processor.test.ts +81 -25
  98. package/src/processors/canonical-log-line-processor.ts +130 -42
  99. package/src/request-logger.test.ts +124 -0
  100. package/src/request-logger.ts +140 -0
  101. package/src/structured-error.test.ts +76 -0
  102. package/src/structured-error.ts +86 -0
  103. package/dist/chunk-2RQDNGV3.js +0 -126
  104. package/dist/chunk-2RQDNGV3.js.map +0 -1
  105. package/dist/chunk-BS757SL2.js.map +0 -1
  106. package/dist/chunk-GZFH6P5U.js.map +0 -1
  107. package/dist/chunk-ONK2Y22L.cjs +0 -128
  108. package/dist/chunk-ONK2Y22L.cjs.map +0 -1
  109. package/dist/chunk-QKUGUDXJ.cjs.map +0 -1
  110. package/dist/chunk-VQFF2WMP.cjs.map +0 -1
package/README.md CHANGED
@@ -76,6 +76,9 @@ Replace `NODE_OPTIONS` and 30+ lines of SDK boilerplate with `init()`, wrap func
76
76
  - [What You Get](#what-you-get)
77
77
  - [Query Examples](#query-examples)
78
78
  - [Configuration Options](#configuration-options)
79
+ - [Request Logger DX](#request-logger-dx)
80
+ - [Drain Pipeline (Batch + Retry + Flush)](#drain-pipeline-batch--retry--flush)
81
+ - [parseError (Frontend/API Consumers)](#parseerror-frontendapi-consumers)
79
82
  - [Auto Instrumentation \& Advanced Configuration](#auto-instrumentation--advanced-configuration)
80
83
  - [⚠️ autoInstrumentations vs. Manual Instrumentations](#️-autoinstrumentations-vs-manual-instrumentations)
81
84
  - [Option A: Auto-instrumentations only (all defaults)](#option-a-auto-instrumentations-only-all-defaults)
@@ -1504,7 +1507,7 @@ export const processCheckout = trace((ctx) => async (order: Order) => {
1504
1507
 
1505
1508
  When a span ends, a canonical log line is automatically emitted with:
1506
1509
 
1507
- - **Core fields**: `operation`, `traceId`, `spanId`, `correlationId`, `duration_ms`, `status_code`
1510
+ - **Core fields**: `operation`, `traceId`, `spanId`, `correlationId`, `duration_ms`, `duration`, `status_code`
1508
1511
  - **ALL span attributes**: Every attribute you set with `ctx.setAttribute()`
1509
1512
  - **Resource attributes**: `service.name`, `service.version`, `deployment.environment`
1510
1513
  - **Timestamp**: ISO 8601 format
@@ -1520,6 +1523,7 @@ When a span ends, a canonical log line is automatically emitted with:
1520
1523
  "spanId": "00f067aa0ba902b7",
1521
1524
  "correlationId": "4bf92f3577b34da",
1522
1525
  "duration_ms": 124.7,
1526
+ "duration": "125ms",
1523
1527
  "status_code": 1,
1524
1528
  "user.id": "user-123",
1525
1529
  "user.subscription": "premium",
@@ -1561,17 +1565,119 @@ init({
1561
1565
  service: 'my-app',
1562
1566
  canonicalLogLines: {
1563
1567
  enabled: true,
1564
- rootSpansOnly: true, // Only log root spans (one per request)
1565
- minLevel: 'info', // Minimum log level ('debug' | 'info' | 'warn' | 'error')
1566
- logger: pino(), // Custom logger (defaults to OTel Logs API)
1568
+ rootSpansOnly: true,
1569
+ minLevel: 'info',
1570
+ logger: pino(),
1571
+ pretty: true, // tree-formatted console output (defaults to NODE_ENV=development)
1572
+ keep: [{ status: 500 }, { durationMs: 1000 }], // declarative tail sampling
1573
+ shouldEmit: ({ event }) => {
1574
+ // or use a custom predicate (overrides keep)
1575
+ const isError = Number(event.status_code) === 2;
1576
+ const isSlow = Number(event.duration_ms ?? 0) >= 1000;
1577
+ return isError || isSlow || Math.random() < 0.1;
1578
+ },
1579
+ drain: async ({ event }) => {
1580
+ await fetch('https://logs.example.com/ingest', {
1581
+ method: 'POST',
1582
+ body: JSON.stringify(event),
1583
+ });
1584
+ },
1567
1585
  messageFormat: (span) => {
1568
- // Custom message format
1569
1586
  const status = span.status.code === 2 ? 'ERROR' : 'SUCCESS';
1570
1587
  return `${span.name} [${status}]`;
1571
1588
  },
1572
- includeResourceAttributes: true, // Include service.name, service.version, etc.
1589
+ includeResourceAttributes: true,
1590
+ },
1591
+ });
1592
+ ```
1593
+
1594
+ ### Request Logger DX
1595
+
1596
+ For teams that prefer `log.set({...})` ergonomics, you can use `getRequestLogger()`.
1597
+ It writes directly to span attributes/events, so canonical log lines still emit one
1598
+ wide event per request.
1599
+
1600
+ ```typescript
1601
+ import { trace, getRequestLogger, createStructuredError } from 'autotel';
1602
+
1603
+ export const checkout = trace((ctx) => async (order: Order) => {
1604
+ const log = getRequestLogger(ctx);
1605
+
1606
+ log.set({ user: { id: order.userId, plan: order.plan } });
1607
+ log.set({
1608
+ cart: { total_cents: order.totalCents, item_count: order.items.length },
1609
+ });
1610
+
1611
+ try {
1612
+ await processPayment(order);
1613
+ } catch (cause) {
1614
+ log.error(
1615
+ createStructuredError({
1616
+ message: 'Payment failed',
1617
+ why: 'Card declined by issuer',
1618
+ fix: 'Try another payment method',
1619
+ link: 'https://docs.example.com/errors/payment-declined',
1620
+ cause,
1621
+ }),
1622
+ { step: 'payment' },
1623
+ );
1624
+ throw cause;
1625
+ }
1626
+ });
1627
+ ```
1628
+
1629
+ You also get:
1630
+
1631
+ - `log.getContext()` to inspect the accumulated request context.
1632
+ - `log.emitNow(overrides?)` to capture an immediate snapshot (adds a span event
1633
+ and returns `{ timestamp, traceId, spanId, correlationId, context }`).
1634
+
1635
+ ### Drain Pipeline (Batch + Retry + Flush)
1636
+
1637
+ If you want batching/retry behavior for canonical drains, wrap `drain`
1638
+ with `createDrainPipeline()` style logging:
1639
+
1640
+ ```typescript
1641
+ import { createDrainPipeline, init } from 'autotel';
1642
+
1643
+ const pipeline = createDrainPipeline({
1644
+ batch: { size: 50, intervalMs: 2000 },
1645
+ retry: { maxAttempts: 3, backoff: 'exponential' },
1646
+ maxBufferSize: 1000,
1647
+ });
1648
+
1649
+ const drain = pipeline(async (batch) => {
1650
+ await fetch('https://logs.example.com/ingest', {
1651
+ method: 'POST',
1652
+ body: JSON.stringify(batch.map((ctx) => ctx.event)),
1653
+ });
1654
+ });
1655
+
1656
+ init({
1657
+ service: 'my-app',
1658
+ canonicalLogLines: {
1659
+ enabled: true,
1660
+ rootSpansOnly: true,
1661
+ drain,
1573
1662
  },
1574
1663
  });
1664
+
1665
+ await drain.flush();
1666
+ ```
1667
+
1668
+ ### parseError (Frontend/API Consumers)
1669
+
1670
+ Use `parseError()` to normalize unknown caught errors into a stable shape:
1671
+
1672
+ ```typescript
1673
+ import { parseError } from 'autotel';
1674
+
1675
+ try {
1676
+ await api.checkout(order);
1677
+ } catch (error) {
1678
+ const parsed = parseError(error);
1679
+ showError(parsed.message, parsed.why, parsed.fix);
1680
+ }
1575
1681
  ```
1576
1682
 
1577
1683
  ## Auto Instrumentation & Advanced Configuration
package/dist/auto.cjs CHANGED
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var chunkQKUGUDXJ_cjs = require('./chunk-QKUGUDXJ.cjs');
3
+ var chunkHSEIUH7F_cjs = require('./chunk-HSEIUH7F.cjs');
4
4
  var chunk6YIDHH2S_cjs = require('./chunk-6YIDHH2S.cjs');
5
5
  require('./chunk-GVLK7YUU.cjs');
6
6
  require('./chunk-ZNMBW67B.cjs');
7
7
  require('./chunk-IOYFAFHJ.cjs');
8
8
  require('./chunk-ELW34S4C.cjs');
9
9
  require('./chunk-CU6IDACR.cjs');
10
- require('./chunk-ONK2Y22L.cjs');
10
+ require('./chunk-6S5RUKU3.cjs');
11
11
  require('./chunk-YS6C2YJE.cjs');
12
12
  require('./chunk-BGVKKL2N.cjs');
13
13
  require('./chunk-AZ24DJAG.cjs');
@@ -23,7 +23,7 @@ module$1.register("import-in-the-middle/hook.mjs", (typeof document === 'undefin
23
23
  var yamlConfig = chunk6YIDHH2S_cjs.loadYamlConfig();
24
24
  var autoInstrumentationsEnv = process.env.AUTOTEL_INTEGRATIONS;
25
25
  var autoInstrumentations = autoInstrumentationsEnv === "true" ? true : autoInstrumentationsEnv ? autoInstrumentationsEnv.split(",").map((s) => s.trim()) : yamlConfig?.autoInstrumentations ?? ["http", "express"];
26
- chunkQKUGUDXJ_cjs.init({
26
+ chunkHSEIUH7F_cjs.init({
27
27
  service: yamlConfig?.service ?? process.env.OTEL_SERVICE_NAME ?? "unknown-service",
28
28
  debug: yamlConfig?.debug ?? process.env.AUTOTEL_DEBUG === "true",
29
29
  autoInstrumentations
package/dist/auto.js CHANGED
@@ -1,11 +1,11 @@
1
- import { init } from './chunk-BS757SL2.js';
1
+ import { init } from './chunk-724XLWR3.js';
2
2
  import { loadYamlConfig } from './chunk-YTGF4L2C.js';
3
3
  import './chunk-X4RMFFMR.js';
4
4
  import './chunk-WGWSHJ2N.js';
5
5
  import './chunk-GYR5K654.js';
6
6
  import './chunk-SNINLBEE.js';
7
7
  import './chunk-6UQRVUN3.js';
8
- import './chunk-2RQDNGV3.js';
8
+ import './chunk-3QXBFGKP.js';
9
9
  import './chunk-33WTKH7X.js';
10
10
  import './chunk-XND7WBVX.js';
11
11
  import './chunk-B33XPEKY.js';
@@ -1,4 +1,4 @@
1
- import { trace } from './chunk-GZFH6P5U.js';
1
+ import { trace } from './chunk-GY4CRZSV.js';
2
2
  import { extractLinksFromBatch, createLinkFromHeaders } from './chunk-XND7WBVX.js';
3
3
  import { SpanKind, propagation, context } from '@opentelemetry/api';
4
4
 
@@ -790,5 +790,5 @@ function clearOrderingState() {
790
790
  }
791
791
 
792
792
  export { clearOrderingState, traceConsumer, traceProducer };
793
- //# sourceMappingURL=chunk-EWH2542B.js.map
794
- //# sourceMappingURL=chunk-EWH2542B.js.map
793
+ //# sourceMappingURL=chunk-3AMR5XLZ.js.map
794
+ //# sourceMappingURL=chunk-3AMR5XLZ.js.map