hono-webhooks 0.4.1 → 0.5.1
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 +32 -5
- package/dist/cli.js +5167 -5021
- package/dist/otel.d.ts +51 -2
- package/dist/otel.js +47 -9
- package/package.json +2 -2
- package/src/cli-commands.ts +181 -167
- package/src/cli.ts +1 -3
- package/src/otel.ts +90 -9
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)
|
|
565
|
-
|
|
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
|
-
//
|
|
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
|
-
- `
|
|
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.
|
|
@@ -702,6 +721,8 @@ Options for test:
|
|
|
702
721
|
-e, --secret-env <name> Environment variable holding the signing secret
|
|
703
722
|
```
|
|
704
723
|
|
|
724
|
+
`hono-webhooks <module> <command> --help` prints the options of one command.
|
|
725
|
+
|
|
705
726
|
`<module>` exports either a `createWebhooks()` app or an array of webhooks, as
|
|
706
727
|
default or as any named export. With an array, the CLI builds the app itself,
|
|
707
728
|
so it can point straight at the file that lists your webhooks.
|
|
@@ -757,6 +778,7 @@ import {
|
|
|
757
778
|
|
|
758
779
|
import {
|
|
759
780
|
otelWebhooks, // (options?) => { around, onEvent } with spans and metrics
|
|
781
|
+
webhookMetrics, // the two metric definitions, as data
|
|
760
782
|
UNMATCHED_ROUTE // '__unmatched__', the route label for 404s
|
|
761
783
|
} from 'hono-webhooks/otel'
|
|
762
784
|
|
|
@@ -781,7 +803,12 @@ import type {
|
|
|
781
803
|
StandardSchemaV1
|
|
782
804
|
} from 'hono-webhooks'
|
|
783
805
|
|
|
784
|
-
import type {
|
|
806
|
+
import type {
|
|
807
|
+
OtelWebhooksOptions,
|
|
808
|
+
WebhookCall,
|
|
809
|
+
WebhookLogger,
|
|
810
|
+
WebhookMetricDefinition
|
|
811
|
+
} from 'hono-webhooks/otel'
|
|
785
812
|
```
|
|
786
813
|
|
|
787
814
|
Use `Webhook` to type a list: `const all: Webhook<AppEnv>[] = [a, b]`.
|