counterspell

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 25 Imported by: 0

README

Counterspell

A lightweight, embedded observability tool for Go applications that provides OpenTelemetry tracing and logging capabilities with a local SQLite database backend and REST API for data querying.

What it is

  • Fast and easy to get started
  • Gives you observability UI with the greatest of ease
  • Embedded observability with otel, zerolog (uses sqlite)
  • Means no external dependencies, no xtra docker containers
  • Writes logs on a separate goroutine, so your app is not affected
  • Will add features for LLM ops soon!

Installation

go get github.com/revrost/counterspell

Quick Start

The simplest way to add Counterspell to your application:

func main() {
	// Example 1: Using Echo router
	log.Info().Msg("Starting Echo server with Counterspell...")
	e := echo.New()

	// Use echo
	e.Use(otelecho.Middleware("counterspell-example"))

	// Add Counterspell to Echo router
	if err := counterspell.AddToEcho(e,
		counterspell.WithAuthToken("my-secret-token"),
		counterspell.WithDBPath("counterspell_echo.db"),
	); err != nil {
		log.Fatal().Err(err).Msg("Failed to add Counterspell to Echo")
	}

	// Add your application routes
	e.GET("/hello", func(c echo.Context) error {
		log.Ctx(c.Request().Context()).Debug().Str("user", "demo").Msg("Hello from Echo with Counterspell!")
		log.Ctx(c.Request().Context()).Error().Msg("Hello from Echo with Counterspell!")
		return c.String(http.StatusOK, "Hello from Echo with Counterspell!")
	})

	log.Info().Msg("Echo server listening on :8080")
	log.Info().Msg("Counterspell UI available at: http://localhost:8080/counterspell/health")
	log.Info().Msg("Counterspell API available at: http://localhost:8080/counterspell/api/logs?secret=my-secret-token")
	if err := e.Start(":8080"); err != nil {
		log.Printf("Echo server stopped: %v", err)
	}
}

API Endpoints

All API endpoints require authentication via the Authorization: Bearer <token> header or auth query parameter.

License

MIT

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Support

  • GitHub Issues: Report bugs and request features
  • Documentation: See the docs directory for detailed guides
  • Examples: Check the examples directory for more usage patterns

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToEcho

func AddToEcho(e *echov4.Echo, opts ...Option) error

AddToEcho initializes Counterspell with the provided Echo v4 instance

func AddToEchoV5 added in v0.1.2

func AddToEchoV5(e *echov5.Echo, opts ...Option) error

AddToEchoV5 initializes Counterspell with the provided Echo v5 instance

func Install

func Install(e *echov4.Echo, opts ...Option) error

Install is deprecated. Use AddToEcho instead. This function is kept for backward compatibility.

Types

type Counterspell

type Counterspell struct {
	// contains filtered or unexported fields
}

Counterspell holds the internal state for the observability system

func AddToStdlib

func AddToStdlib(mux *http.ServeMux, opts ...Option) (*Counterspell, error)

AddToStdlib initializes Counterspell with the provided standard library ServeMux

type Option

type Option func(*config)

Option represents a configuration option for Counterspell

func WithAuthToken

func WithAuthToken(token string) Option

WithAuthToken sets the authentication token

func WithDBPath

func WithDBPath(path string) Option

WithDBPath sets the database path

func WithServiceName

func WithServiceName(name string) Option

WithServiceName sets the service name

func WithServiceVersion

func WithServiceVersion(version string) Option

WithServiceVersion sets the service version

Directories

Path Synopsis
cmd
examples
internal
db

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL