SDKs

Go SDK

Install the Logdash Go SDK, send your first log and your first metric.

Install the package, add your ingest key and the first log lands in the dashboard within a second. Everything below is copied from the Go SDK README.

Install

go get github.com/logdash-io/go-sdk/logdash

Initialise

Copy the ingest key from your domain's settings in Logdash and keep it in an environment variable. The key identifies the domain the data lands in, and app names the program that sends, such as api or worker. See Apps.

import (
	"os"

	"github.com/logdash-io/go-sdk/logdash"
)

ld := logdash.New(
	logdash.WithAPIKey(os.Getenv("LOGDASH_API_KEY")),
	logdash.WithApp("api"),
)

Send a log

package main

import (
	"context"
	"os"
	"time"

	"github.com/logdash-io/go-sdk/logdash"
)

func main() {
	ld := logdash.New(logdash.WithAPIKey(os.Getenv("LOGDASH_API_KEY")))
	logger := ld.Logger

	logger.Info("Application started successfully")
	logger.Error("An unexpected error occurred")
	logger.Warn("Low disk space warning")

	// Every level has an ...F() counterpart, like fmt.Printf.
	logger.InfoF("Processing %v of %v item", 1, 10)

	// Shutdown waits for every enqueued log, metric and event to flush.
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()
	ld.Shutdown(ctx)
}

Send a metric

Metrics are named numbers. Set one to an absolute value or mutate it by a delta, and Logdash charts the history.

package main

import (
	"context"
	"os"
	"time"

	"github.com/logdash-io/go-sdk/logdash"
)

func main() {
	ld := logdash.New(logdash.WithAPIKey(os.Getenv("LOGDASH_API_KEY")))
	metrics := ld.Metrics

	// to set absolute value
	metrics.Set("users", 0)

	// or increment / decrement by
	metrics.Mutate("users", 1)

	// Shutdown waits for every enqueued log, metric and event to flush.
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()
	ld.Shutdown(ctx)
}

Send an event

Events go to web analytics of the domain, next to the custom events of your website, with the same rules for names and properties.

ld := logdash.New(
	logdash.WithAPIKey(os.Getenv("LOGDASH_API_KEY")),
)

ld.Track("agent_run",
	map[string]any{"agent": "support", "steps": 4, "success": true},
	// the signed-in user's internal ID, never an email address
	logdash.WithUserID("42"),
)

Flush before exit

The SDK sends in the background. In a short-lived process, such as a cron job, a CLI or a serverless function, send what is still queued before the process exits.

// Shutdown waits for every enqueued log, metric and event to flush.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ld.Shutdown(ctx)

Works with

  • net/http
  • log/slog
  • Gin
  • Echo
  • Fiber

FAQ

Can I keep using log/slog?
Yes. Wrap the logger with logdash.NewSlogTextHandler(ld.Logger, slog.HandlerOptions{}) and pass it to slog.New. Error maps to Error, Warn to Warn, Info to Info, Debug to Debug and anything below Debug to Silly.
How do I flush before the process exits?
Call ld.Shutdown(ctx) with a context deadline. It blocks until every queued log, metric and event has been sent or the context expires.
Is there a printf-style logging call?
Yes. Every level has an ...F() counterpart, so logger.InfoF("Processing %v of %v item", i+1, items) works the way fmt.Printf does.

Copied from the go-sdk README at 8b10bef on 2026-11-09.