Skip to content

feat: add OTEL metrics and tracing to cert_webhook plugin#6

Merged
pcfreak30 merged 1 commit into
developfrom
feat/otel-metrics-tracing
Jun 25, 2026
Merged

feat: add OTEL metrics and tracing to cert_webhook plugin#6
pcfreak30 merged 1 commit into
developfrom
feat/otel-metrics-tracing

Conversation

@pcfreak30

@pcfreak30 pcfreak30 commented Jun 25, 2026

Copy link
Copy Markdown
Member

Changes

Adds OpenTelemetry metrics and distributed tracing to the cert_webhook Caddy plugin.

Metrics (4 counters)

  • cert_webhook_deliveries_total - webhook delivery success/failure (labels: domain, status, result)
  • cert_webhook_cert_events_total - cert events processed (labels: event_type, domain)
  • cert_webhook_throttled_total - events throttled by dedup (labels: domain, source)
  • cert_webhook_tls_get_cert_total - tls_get_certificate events (labels: domain, status)

Tracing

  • Spans on Handle, handleCertEvent, handleTLSGetCertificateEvent, deliverAsync
  • Error spans marked with codes.Error via endSpanWithError

Wiring

  • initMetrics() and initTracer() called in Provision() alongside existing setup
  • Metrics use nil guards so recording is a no-op if init fails
  • Test mocks updated to use mock.Anything for context args (span-wrapped contexts no longer match context.Background() exactly)

OTEL env vars

Set via standard OTEL environment variables on the Caddy container. No code changes needed.

Test results

43 tests pass, clean build.


Pull Request Description

This PR adds OpenTelemetry (OTEL) metrics and tracing to the cert_webhook Caddy plugin, providing observability into webhook delivery, certificate event processing, throttling, and TLS certificate request handling.

Metrics Added

Four new counters are registered under the cert_webhook meter:

  • cert_webhook_deliveries_total — Tracks webhook delivery attempts to the portal API, with attributes for domain, SSL status, and result (success/failure).
  • cert_webhook_cert_events_total — Tracks processed certificate events (obtained, renewed, expired), with attributes for event type and domain.
  • cert_webhook_throttled_total — Tracks events suppressed by the throttle/dedup mechanism, with attributes for domain and source (cert_event or tls_get_cert).
  • cert_webhook_tls_get_cert_total — Tracks tls_get_certificate events processed, with attributes for domain and SSL status.

Tracing Added

Spans are created for the following operations, with relevant attributes (domain, status, event type) and error recording on failure:

  • Event handling (cert_webhook.handle_event)
  • Certificate event processing (cert_webhook.handle_cert_event)
  • TLS get certificate event processing (cert_webhook.handle_tls_get_cert)
  • Webhook delivery (cert_webhook.deliver_webhook)

Integration Changes

  • Metrics and tracer are initialized during plugin provisioning in handler.go. Metric initialization failures are logged as warnings without blocking startup.
  • Context is now propagated through the event handling chain (HandlehandleCertEvent / handleTLSGetCertificateEvent) to support distributed tracing.
  • Webhook delivery in delivery.go now uses the traced context for the API call and records success/failure metrics.
  • Existing tests were updated to pass context.Background() to modified method signatures and to use mock.Anything for context arguments in mock expectations.
  • New test coverage validates metric recording correctness and nil-safety when metrics/tracer are uninitialized.

@kody-ai

This comment has been minimized.

Comment thread events.go Outdated
@kody-ai

kody-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

Metrics: 4 Prometheus counters (webhook_deliveries, cert_events, throttled,
tls_get_cert) registered via Caddy's metrics registry (ctx.GetMetricsRegistry).
Caddy bridges these to OTLP when metrics { otlp } is enabled in the Caddyfile.

Tracing: spans on Handle, handleCertEvent, handleTLSGetCertificateEvent, and
deliverAsync using otel.Tracer(), which Caddy's tracing directive configures
via the global tracer provider.

Record functions at all decision points: event processed, throttled, webhook
success/failure, tls_get_cert. initMetrics/initTracer called in Provision.
@pcfreak30 pcfreak30 force-pushed the feat/otel-metrics-tracing branch from 97ebc6e to ad57aa4 Compare June 25, 2026 22:38
@pcfreak30 pcfreak30 merged commit 58e6f2d into develop Jun 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant