Giter VIP home page Giter VIP logo

go-tracing's Introduction

go-tracing

serves logs and prometheus metrics to help trace a function execution at runtime.

fabric-flogging

fabric-flogging is cloned from flogging of Hyperledger Fabric at https://github.com/hyperledger/fabric/tree/master/common/flogging

how to use

  1. Define tracing
var myTracer  = tracing.MustGetTracer("example_file")
  1. Count on function call

call StartFunction() at the beginning of the function call. For example

func myfunction(){
    myTracer.StartFunction("my_trace_number")
    // function logic
}
2022-12-22 13:43:09.339 +07 [example_file] myfunction -> INFO 026 [my_trace_number] StartFunction at 1671691389339
  1. Count on function end

call EndFunction() at the end of the function call. For example

func myfunction(){

    // function logic
    myTracer.EndFunction("my_trace_number")
}
2022-12-22 13:43:09.339 +07 [example_file] myfunction -> INFO 026 [my_trace_number] EndFunction at 1671691389339
  1. Trace function duration
  • option 1: call EndFunctionWithDurationSince() at the end of the function call. For example
func myfunction(){
    startTime := myTracer.StartFunction("my_trace_number")
    // function logic
    myTracer.EndFunctionWithDurationSince("my_trace_number", startTime)
}
  • option 2: call EndFunctionWithDurationSince() with defer at the beginning of function call. For example
func myfunction(){
    defer myTracer.EndFunctionWithDurationSince("my_trace_number", time.Now())
    // function logic
}

both options will have the same logging like this

2022-12-22 13:43:09.891 +07 [example_file] myfunction -> INFO 02f [my_trace_number] EndFunction at 1671691389891, duration=551ms

metrics

check URL:PORT/metrics to find prometheus metrics

go-tracing's People

Contributors

hnampk avatar nguyencongluat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.