From 178f30ea78a8cb5043a481112053c14a2d38888c Mon Sep 17 00:00:00 2001 From: Hamid Ramazani Date: Mon, 12 Dec 2022 10:08:05 -0800 Subject: [PATCH] add util to tracing to get function name, and further COGS constants --- tracing/cogs/cogs.go | 9 ++++++--- tracing/util.go | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tracing/util.go diff --git a/tracing/cogs/cogs.go b/tracing/cogs/cogs.go index 21a66ced..a0e9f798 100644 --- a/tracing/cogs/cogs.go +++ b/tracing/cogs/cogs.go @@ -2,7 +2,10 @@ package cogs // const values used in setting span attributes for COGS: Cost Of Goods Sold. const ( - CostOfGoodsKey = "cogs" - CostOfGoodsMethodKey = "cogs.method" - CostOfGoodsAccountID = "cogs.accountID" + CostOfGoodsKey = "cogs" + CostOfGoodsMethodKey = "cogs.method" + CostOfGoodsAccountID = "cogs.accountID" + CostOfGoodsRDS = "cogs.rds" + CostOfGoodS3 = "cogs.s3" + CostOfGoodElasticSearch = "cogs.elasticsearch" ) diff --git a/tracing/util.go b/tracing/util.go new file mode 100644 index 00000000..6831ed5d --- /dev/null +++ b/tracing/util.go @@ -0,0 +1,21 @@ +package tracing + +import ( + "runtime" +) + +// ThisFunction returns calling function name +func ThisFunction() string { + pc := make([]uintptr, 32) + runtime.Callers(2, pc) + return runtime.FuncForPC(pc[0]).Name() +} + +// Trace returns calling function file name, line number and name +func Trace() (file string, line int, name string) { + pc := make([]uintptr, 32) + runtime.Callers(2, pc) + f := runtime.FuncForPC(pc[0]) + file, line = f.FileLine(pc[0]) + return file, line, f.Name() +}