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/atzap
    
  2. Set up tracer and configure log exporter

    copy
    icon/buttons/copy
    import (
        "go.atatus.com/agent"
        "go.atatus.com/agent/module/atzap"
    
        "go.uber.org/zap"
    )
    // atzap.Core.WrapCore will wrap the core created by zap.NewExample
    // such that logs are also sent to the atzap.Core.
    //
    // atzap.Core will send "error", "panic", and "fatal" level log
    // messages to Atatus APM.
    
    var logger = zap.NewExample(zap.WrapCore((&atzap.Core{}).WrapCore))
    
    func handleRequest(w http.ResponseWriter, req *http.Request) {
        // atzap.TraceContext extracts the transaction and span (if any)
        // from the given context, and returns zap.Fields containing the
        // trace, transaction, and span IDs.
        traceContextFields := atzap.TraceContext(req.Context())
        logger.With(traceContextFields...).Debug("handling request")
    
        // Output:
        // {"level":"debug","msg":"handling request","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