Skip to content

feat(observability): add OpenTelemetry tracing and metrics middleware…#42

Merged
hyp3rd merged 1 commit intomainfrom
feat/observability
Aug 21, 2025
Merged

feat(observability): add OpenTelemetry tracing and metrics middleware…#42
hyp3rd merged 1 commit intomainfrom
feat/observability

Conversation

@hyp3rd
Copy link
Copy Markdown
Owner

@hyp3rd hyp3rd commented Aug 21, 2025

… with docs and example

middleware: introduce OTelTracingMiddleware that wraps all Service methods with spans and attributes (e.g., method names, key.len, hit, counts, expiration.ms) and records errors
middleware: add OTelMetricsMiddleware with counter (hypercache.calls) and duration histogram (hypercache.duration.ms), tagging method, key.len, hit, item/key counts
examples: add otel.go using noop MeterProvider/TracerProvider and ApplyMiddleware; defers svc.Stop() for clean shutdown
docs: README Observability section with wiring snippet; examples README links the new example
deps: add go.opentelemetry.io/otel, otel/metric, and otel/trace to go.mod/go.sum

No breaking changes; behavior unchanged unless middleware is applied.

… with docs and example

middleware: introduce OTelTracingMiddleware that wraps all Service methods with spans and attributes (e.g., method names, key.len, hit, counts, expiration.ms) and records errors
middleware: add OTelMetricsMiddleware with counter (hypercache.calls) and duration histogram (hypercache.duration.ms), tagging method, key.len, hit, item/key counts
examples: add otel.go using noop MeterProvider/TracerProvider and ApplyMiddleware; defers svc.Stop() for clean shutdown
docs: README Observability section with wiring snippet; examples README links the new example
deps: add go.opentelemetry.io/otel, otel/metric, and otel/trace to go.mod/go.sum

No breaking changes; behavior unchanged unless middleware is applied.
Copilot AI review requested due to automatic review settings August 21, 2025 09:21
@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented Aug 21, 2025

Running Code Quality on PRs by uploading data to Trunk will soon be removed. You can still run checks on your PRs using trunk-action - see the migration guide for more information.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds OpenTelemetry observability support to HyperCache by introducing middleware for tracing and metrics collection. The implementation provides comprehensive instrumentation without breaking existing functionality.

Key changes:

  • Added OTelTracingMiddleware to wrap service methods with OpenTelemetry spans and attributes
  • Added OTelMetricsMiddleware to emit call counters and duration histograms
  • Included a complete example demonstrating usage with noop providers

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/middleware/otel_tracing.go Implements tracing middleware with spans for all service methods and configurable attributes
pkg/middleware/otel_metrics.go Implements metrics middleware with call counters and duration histograms
go.mod Adds OpenTelemetry dependencies (otel, metric, trace)
__examples/observability/otel.go Provides usage example with noop providers and middleware composition
__examples/README.md Links to the new observability example
README.md Documents observability features with wiring snippet

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

// Get implements Service.Get with tracing.
func (mw OTelTracingMiddleware) Get(ctx context.Context, key string) (any, bool) {
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Receiver should be a pointer (*OTelTracingMiddleware) for consistency with the other methods and to avoid potential performance issues with large structs.

Suggested change
func (mw OTelTracingMiddleware) Get(ctx context.Context, key string) (any, bool) {
func (mw *OTelTracingMiddleware) Get(ctx context.Context, key string) (any, bool) {

Copilot uses AI. Check for mistakes.
}

// Set implements Service.Set with tracing.
func (mw OTelTracingMiddleware) Set(ctx context.Context, key string, value any, expiration time.Duration) error {
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Receiver should be a pointer (*OTelTracingMiddleware) for consistency with the other methods and to avoid potential performance issues with large structs.

Suggested change
func (mw OTelTracingMiddleware) Set(ctx context.Context, key string, value any, expiration time.Duration) error {
func (mw *OTelTracingMiddleware) Set(ctx context.Context, key string, value any, expiration time.Duration) error {

Copilot uses AI. Check for mistakes.
@hyp3rd hyp3rd merged commit 82bed8d into main Aug 21, 2025
1 of 3 checks passed
@hyp3rd hyp3rd deleted the feat/observability branch August 21, 2025 09:25
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.

2 participants