hono-webhooks 0.4.0 → 0.5.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.
package/README.md CHANGED
@@ -560,12 +560,15 @@ import { otelWebhooks } from 'hono-webhooks/otel'
560
560
  createWebhooks(webhooks, {
561
561
  ...otelWebhooks({
562
562
  ignoreRoutes: ['/health'],
563
+ // one `webhook.completed` log per request, with the request's span
564
+ logger: (span) => createLogger({ span }),
563
565
  onWebhookCall(call, event) {
564
- // `call` is summarizeEvent(event); the request's span is active here
565
- logger.info('webhook.completed', { route: call.route, status: call.status })
566
+ // `call` is summarizeEvent(event) plus `level` and `outcome`;
567
+ // the request's span is active here
568
+ storeCall(call)
566
569
  }
567
570
  }),
568
- // onWebhookCall logs errors with the route and span
571
+ // the completion log carries the error type
569
572
  logErrors: false
570
573
  })
571
574
  ```
@@ -578,7 +581,23 @@ createWebhooks(webhooks, {
578
581
  - **Metrics** `webhook_request_total` (counter) and
579
582
  `webhook_request_duration_ms` (histogram, ms), both by `route` (the pattern,
580
583
  `__unmatched__` for a 404) and `status` (`success` below 400, else `failed`).
581
- - `ignoreRoutes` skips metrics only; the span and `onWebhookCall` still run.
584
+ - **Log** `webhook.completed`, when `logger` is set, at `error` for 5xx,
585
+ `warn` for 4xx and `info` otherwise, with `route`, `method`, `status_code`,
586
+ `duration_ms`, `status` (`success`, `failed` or `validation_failed`) and
587
+ `error_type`. `logger` gets the request's span and returns anything with
588
+ `info`, `warn` and `error` methods taking `(message, fields)`, so
589
+ `logger: () => console` works. 404s and `ignoreRoutes` are not logged.
590
+ - `ignoreRoutes` skips metrics and the log; the span and `onWebhookCall` still
591
+ run.
592
+ - `webhookMetrics` describes both metrics (`name`, `kind`, `unit`,
593
+ `description` and `attributes`, where each attribute maps to its values or
594
+ `'string'`), so a metric catalog can list them:
595
+
596
+ ```ts
597
+ import { webhookMetrics } from 'hono-webhooks/otel'
598
+
599
+ export const otelMetrics = [...appMetrics, ...webhookMetrics]
600
+ ```
582
601
  - `tracer` and `meter` default to `trace.getTracer('webhooks')` and
583
602
  `metrics.getMeter('webhooks')`. The meter is resolved on the first request,
584
603
  so registering the SDK after import works.
@@ -757,6 +776,7 @@ import {
757
776
 
758
777
  import {
759
778
  otelWebhooks, // (options?) => { around, onEvent } with spans and metrics
779
+ webhookMetrics, // the two metric definitions, as data
760
780
  UNMATCHED_ROUTE // '__unmatched__', the route label for 404s
761
781
  } from 'hono-webhooks/otel'
762
782
 
@@ -781,7 +801,12 @@ import type {
781
801
  StandardSchemaV1
782
802
  } from 'hono-webhooks'
783
803
 
784
- import type { OtelWebhooksOptions } from 'hono-webhooks/otel'
804
+ import type {
805
+ OtelWebhooksOptions,
806
+ WebhookCall,
807
+ WebhookLogger,
808
+ WebhookMetricDefinition
809
+ } from 'hono-webhooks/otel'
785
810
  ```
786
811
 
787
812
  Use `Webhook` to type a list: `const all: Webhook<AppEnv>[] = [a, b]`.
@@ -0,0 +1 @@
1
+ export declare const cli: import("hanzio/cli").Cli;