Skip to content

Instantly share code, notes, and snippets.

@adityarama1210
Last active December 5, 2020 01:09
Show Gist options
  • Save adityarama1210/0ef51134c779495cde97caaa14db310f to your computer and use it in GitHub Desktop.
Save adityarama1210/0ef51134c779495cde97caaa14db310f to your computer and use it in GitHub Desktop.
function in main.go for elastic APM
func processingRequest(ctx context.Context) {
span, ctx := apm.StartSpan(ctx, "processingRequest", "custom")
defer span.End()
doSomething(ctx)
// time sleep simulate some processing time
time.Sleep(15 * time.Millisecond)
return
}
func doSomething(ctx context.Context) {
span, ctx := apm.StartSpan(ctx, "doSomething", "custom")
defer span.End()
// time sleep simulate some processing time
time.Sleep(20 * time.Millisecond)
return
}
func getTodoFromAPI(ctx context.Context) (map[string]interface{}, error) {
span, ctx := apm.StartSpan(ctx, "getTodoFromAPI", "custom")
defer span.End()
var result map[string]interface{}
resp, err := http.Get("https://jsonplaceholder.typicode.com/todos/1")
if err != nil {
return result, err
}
defer resp.Body.Close()
err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
return result, err
}
return result, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment