Skip to content

Commit

Permalink
Added Noop observability implementation for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xBlaz3kx committed Jul 29, 2024
1 parent c35042f commit bcfee17
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions observability/noop_observability.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package observability

import (
"context"
"time"

"github.com/GLCharge/otelzap"
"github.com/gin-gonic/gin"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
)

func NewNoopObservability() Observability {
return &noopObservability{}
}

type noopObservability struct {
}

func (n *noopObservability) Shutdown(ctx context.Context) {
}

func (n *noopObservability) Span(ctx context.Context, spanName string, fields ...zap.Field) (context.Context, func()) {
return ctx, func() {}
}

func (n *noopObservability) LogSpan(ctx context.Context, spanName string, fields ...zap.Field) (context.Context, func(), otelzap.LoggerWithCtx) {
return ctx, func() {}, otelzap.Ctx(ctx)
}

func (n *noopObservability) LogSpanWithTimeout(ctx context.Context, spanName string, timeout time.Duration, fields ...zap.Field) (context.Context, func(), otelzap.LoggerWithCtx) {
return ctx, func() {}, otelzap.Ctx(ctx)
}

func (n *noopObservability) Log() *otelzap.Logger {
return otelzap.L()
}

func (n *noopObservability) Metrics() *Metrics {
return &Metrics{}
}

func (n *noopObservability) SetupHttpMiddleware(router *gin.Engine) {
}

func (n *noopObservability) WithSpanKind(spanKind trace.SpanKind) *Impl {
return &Impl{}
}

0 comments on commit bcfee17

Please sign in to comment.