Skip to content
Event Tracking

Event Tracking

What is an Event?

An event is a record of a single, meaningful name that occurred in your application — typically tied to an HTTP request. Think of it as answering the question: “who did what, when, and how?”

Events are the highest-volume primitive. You would create one for every significant operation your application handles: a user logging in, a file being uploaded, an order being placed, a webhook being received.

Examples:

nameTrigger
user.loginA user authenticates successfully
invoice.createdA new invoice is generated
password.resetA password reset is completed
api_key.revokedAn API key is deleted
export.requestedA user requests a data export

Each event carries the HTTP context (method, status, endpoint), the client’s IP and user agent, and any arbitrary metadata you attach — making it straightforward to reconstruct exactly what happened during a given request.


Fields

Captures HTTP activity across your application. Each event records:

  • name name (e.g. user.login, invoice.created)
  • HTTP method, status code, and endpoint
  • Client IP address and user agent
  • Geolocation derived from IP
  • User identity (username / user ID)
  • Arbitrary JSON metadata

Useful for tracking every meaningful intername a user or service has with your system.

package main

import (
	"log"
	"net/http"
	"os"

	_ "github.com/joho/godotenv/autoload"

	logtrace "github.com/logtracehq/logtrace-go"
)

func main() {
	client, err := logtrace.New(os.Getenv("API_KEY"))
	if err != nil {
		log.Fatalf("Failed to create LogTrace client: %v", err)
	}

	mux := http.NewServeMux()
	mux.HandleFunc("/run", func(w http.ResponseWriter, r *http.Request) {
		lc := logtrace.FromContext(r.Context(), client)

		_, err := lc.CreateEvent(r.Context(), &logtrace.CreateEventRequest{
			Name: "user.login",
			UserID:     "12345",
			UserName:   "jane_doe",
			Type:       "user event",
			Metadata: logtrace.Metadata{
				"name":      "login",
				"type":        "user",
				"description": "User logged in successfully",
			},
		})
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}

		w.WriteHeader(http.StatusOK)
		w.Write([]byte("done"))
	})

	log.Fatal(http.ListenAndServe(":5000", logtrace.Logger(client)(mux)))
}