duckbug

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

duckbug-go

Go SDK for DuckBug errors, logs, and transactions.

This module follows the DuckBug SDK architecture from duckbug-sdk-spec, while using the real ingest contract from duckbug/backend:

  • POST /ingest/{projectID}:{key}/errors
  • POST /ingest/{projectID}:{key}/errors/batch
  • POST /ingest/{projectID}:{key}/logs
  • POST /ingest/{projectID}:{key}/logs/batch
  • POST /ingest/{projectID}:{key}/transactions

Compatibility

  • Go 1.25.8+ is the initial compatibility target.
  • CI validates the module on Go 1.25.8 and 1.26.1.
  • Releases are expected to be published via git tags in the v* format.

Install

go get github.com/duckbugio/duckbug-go

To install a tagged release:

go get github.com/duckbugio/duckbug-go@v0.1.0

Quick start

package main

import (
    duckbug "github.com/duckbugio/duckbug-go"
    "github.com/duckbugio/duckbug-go/pond"
)

func main() {
    duck := duckbug.NewDuck(duckbug.Config{
        Pond: pond.Ripple([]string{"password", "token"}),
        Providers: []duckbug.Provider{
            duckbug.NewDuckBugProvider("https://duckbug.io/api/ingest/<projectID>:<publicKey>"),
        },
    })

    duck.SetEnvironment("production")
    duck.SetRelease("checkout@1.2.3")

    duck.CaptureLog("warning", "Payment provider timeout", map[string]any{
        "provider": "stripe",
        "attempt":  2,
    })

    transaction := duck.StartTransaction("POST /checkout", "http.server")
    transaction.
        SetContext(map[string]any{"route": "/checkout"}).
        AddMeasurement("http.response.status_code", 200, "code").
        Finish("ok")
    duck.CaptureTransaction(transaction)

    if err := doWork(); err != nil {
        duck.Quack(err)
    }

    duck.Flush(nil)
}

Branded surface

  • Duck is the main runtime facade.
  • Quack(err) is the branded manual error capture API.
  • pond.Ripple(...) builds the context/sanitization subsystem.
  • StartTransaction(...) and CaptureTransaction(...) provide the performance/trace ingest surface.

Privacy defaults

  • Sensitive nested fields are masked with ***.
  • Sensitive header names are masked with ***.
  • Query/body/session/cookies/files/env are attached in the canonical event model and can be disabled in the DuckBug provider privacy options.
  • env capture is disabled by default in the first-party provider.

slog integration

logger := slog.New(duckbugslog.NewHandler(duck, slog.Default().Handler()))
logger.Info("checkout started", "requestId", "req-123")

net/http integration

handler := duckbughttp.Middleware(duck)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    duck.CaptureLogContext(r.Context(), "info", "request received", map[string]any{
        "path": r.URL.Path,
    })
    w.WriteHeader(http.StatusNoContent)
}))

Provider options

The first-party DuckBug provider supports:

  • batching with explicit Flush(...)
  • single-shot transactions ingest
  • bounded retry/backoff for network errors, 429, and 5xx
  • beforeSend mutation/drop hook
  • transport failure hook
  • privacy controls for request sections and env

Transactions

Transactions mirror the current DuckBug backend and PHP SDK shape:

  • required payload fields: traceId, spanId, transaction, op, startTime, endTime, duration
  • optional fields: eventId, parentSpanId, status, context, measurements, spans, release, environment, dist, platform, serverName, service, requestId, user, sdk, runtime, extra
  • duplicate transaction ingest is treated as idempotent success by the backend

Example:

tx := duck.StartTransaction("GET /checkout", "http.server")

span := tx.StartChild("db.query", "select order")
span.SetData(map[string]any{
    "sql": "select * from orders where id = ?",
})
span.Finish("ok")

tx.AddMeasurement("db.rows", 1, "")
tx.Finish("ok")

duck.CaptureTransaction(tx)

Current status

Implemented in this iteration:

  • core runtime for errors, logs, and transactions
  • branded Duck / Quack / pond.Ripple
  • first-party DuckBug provider
  • slog bridge
  • net/http middleware compatible with chi
  • schema copies and tests against the current payload contract for errors and logs
  • transaction payload tests aligned with duckbug/backend and duckbug-php

Release process

  • Push a semver-style tag like v0.1.0.
  • The release workflow re-runs module checks and creates a GitHub Release.
  • Consumers install the module through the standard Go module mechanism via go get.

Documentation

Index

Constants

View Source
const (
	EventTypeError       = corepkg.EventTypeError
	EventTypeLog         = corepkg.EventTypeLog
	EventTypeTransaction = corepkg.EventTypeTransaction

	LevelDebug = corepkg.LevelDebug
	LevelInfo  = corepkg.LevelInfo
	LevelWarn  = corepkg.LevelWarn
	LevelError = corepkg.LevelError
	LevelFatal = corepkg.LevelFatal
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchItemResult

type BatchItemResult = corepkg.BatchItemResult

type Config

type Config = corepkg.Config

type Duck

type Duck = corepkg.Duck

func NewDuck

func NewDuck(config Config) *Duck

type DuckBugBeforeSendFunc

type DuckBugBeforeSendFunc = duckbugprovider.BeforeSendFunc

type DuckBugHTTPTransport

type DuckBugHTTPTransport = duckbugprovider.HTTPTransport

func NewDuckBugHTTPTransport

func NewDuckBugHTTPTransport(config DuckBugHTTPTransportConfig) *DuckBugHTTPTransport

type DuckBugHTTPTransportConfig

type DuckBugHTTPTransportConfig = duckbugprovider.HTTPTransportConfig

type DuckBugPrivacyOptions

type DuckBugPrivacyOptions = duckbugprovider.PrivacyOptions

func DefaultDuckBugPrivacyOptions

func DefaultDuckBugPrivacyOptions() DuckBugPrivacyOptions

type DuckBugProvider

type DuckBugProvider = duckbugprovider.Provider

func NewDuckBugProvider

func NewDuckBugProvider(dsn string, options ...DuckBugProviderOption) *DuckBugProvider

func NewDuckBugProviderWithConfig

func NewDuckBugProviderWithConfig(config DuckBugProviderConfig) *DuckBugProvider

type DuckBugProviderConfig

type DuckBugProviderConfig = duckbugprovider.Config

type DuckBugProviderOption

type DuckBugProviderOption = duckbugprovider.Option

type DuckBugTransport

type DuckBugTransport = duckbugprovider.Transport

type Event

type Event = corepkg.Event

type EventType

type EventType = corepkg.EventType

type FailureInfo

type FailureInfo = corepkg.FailureInfo

type FlushableProvider

type FlushableProvider = corepkg.FlushableProvider

type Level

type Level = corepkg.Level

func NormalizeLevel

func NormalizeLevel(level any) Level

type Provider

type Provider = corepkg.Provider

type Span

type Span = corepkg.Span

type Transaction

type Transaction = corepkg.Transaction

type TransportResult

type TransportResult = corepkg.TransportResult

Directories

Path Synopsis
examples
basic command
integrations
providers

Jump to

Keyboard shortcuts

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