Last active
December 5, 2020 01:09
-
-
Save adityarama1210/0ef51134c779495cde97caaa14db310f to your computer and use it in GitHub Desktop.
function in main.go for elastic APM
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
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