Skip to content

Instantly share code, notes, and snippets.

@thamizhv
Created July 20, 2020 18:56
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 thamizhv/6caf10c7daed0e089addedeb0f97e9cf to your computer and use it in GitHub Desktop.
Save thamizhv/6caf10c7daed0e089addedeb0f97e9cf to your computer and use it in GitHub Desktop.
Print Elastic APM trace ID from new transaction
// from new transaction
func Foo(){
apmTx := apm.DefaultTracer.StartTransaction("transaction_name", "transaction_type")
fmt.Println(apmTx.TraceContext().Trace.String()) // prints TraceID
apmTx.End()
}
// from incoming http request
func FooHandler(w http.ResponseWriter, r *http.Request) {
apmTx := apm.TransactionFromContext(r.Context())
fmt.Println(apmTx.TraceContext().Trace.String()) // prints TraceID
apmTx.End()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment