Created
March 1, 2021 17:44
-
-
Save mpenick/2561d43486b92f48642f23f3cd0fd825 to your computer and use it in GitHub Desktop.
Minimal gocql tracing example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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