Installation steps

  1. Install Atatus Go Agent and logging module

    copy
    icon/buttons/copy
    go get go.atatus.com/agent
    go get go.atatus.com/agent/module/atlogrus
    
  2. Set up tracer and configure log exporter

    copy
    icon/buttons/copy
    import (
        "github.com/sirupsen/logrus"
    
        "go.atatus.com/agent"
        "go.atatus.com/agent/module/atlogrus"
    )
    
    func main() {
        // atlogrus.Hook will send "error", "panic", and "fatal" level log messages to Atatus apm.
        logrus.AddHook(&atlogrus.Hook{})
    }
    
    func handleRequest(w http.ResponseWriter, req *http.Request) {
        // atlogrus.TraceContext extracts the transaction and span (if any) from the given context,
        // and returns logrus.Fields containing the trace, transaction, and span IDs.
        traceContextFields := atlogrus.TraceContext(req.Context())
        logrus.WithFields(traceContextFields).Debug("handling request")
    
        // Output:
        // {"level":"debug","msg":"handling request","time":"1970-01-01T00:00:00Z","trace.id":"67829ae467e896fb2b87ec2de50f6c0e","transaction.id":"67829ae467e896fb"}
    }
    
  3. Clean Up Dependencies

    copy
    icon/buttons/copy

    go mod tidy
    
  4. Run the Application

    copy
    icon/buttons/copy

    go run main.go