docs/advanced-guide/custom-spans-in-tracing/page.md
GoFr's built-in tracing provides valuable insights into application's behavior. However, sometimes we might need
even more granular details about specific operations within your application. This is where custom spans can be used.
By adding custom spans in traces to our requests, we can:
To add a custom trace to a request, GoFr context provides Trace() method, which takes the name of the span as an argument
and returns a trace.Span.
func MyHandler(c context.Context) error {
span := c.Trace("my-custom-span")
defer span.Close()
// Do some work here
return nil
}
In this example, my-custom-span is the name of the custom span that is added to the request. The defer statement ensures that the span is closed even if an error occurs to ensure that the trace is properly recorded.
Check out the example of creating a custom span in GoFr: Visit GitHub