Skip to content

Instantly share code, notes, and snippets.

@mpenick
Created March 1, 2021 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpenick/2561d43486b92f48642f23f3cd0fd825 to your computer and use it in GitHub Desktop.
Save mpenick/2561d43486b92f48642f23f3cd0fd825 to your computer and use it in GitHub Desktop.
Minimal gocql tracing example
package main
import (
"github.com/gocql/gocql"
"log"
)
type MyTracer struct { }
func (t *MyTracer) Trace(traceId []byte) {
// It's possible to query the `system_tracing` tables in here if the session is added to `MyTracer`; however care
// much be taken because the tracing tables are populated asynchronously.
uuid, _ := gocql.UUIDFromBytes(traceId)
log.Printf("Trace ID: %s\n", uuid)
}
// Minimal example of using tracing with gocql. The resulting tracing ID can be used to query `system_tracing` tables via:
//
// "SELECT * FROM system_traces.sessions WHERE session_id = ?"
// "SELECT * FROM system_traces.events WHERE session_id = ?"
//
// The entries for these table are loaded asynchronously and won't be available immediately.
func main() {
cluster := gocql.NewCluster("127.0.0.1")
session, err := cluster.CreateSession()
if err != nil {
log.Fatalf("Unable to create session %v", err)
}
session.SetTrace(&MyTracer{})
defer session.Close()
// Run queries
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment