Skip to content

Commit

Permalink
Merge pull request #355 from hramazani/cogs-add-utils-v0.27.1
Browse files Browse the repository at this point in the history
add util to tracing to get function name, and further COGS constants
  • Loading branch information
hramazani committed Dec 12, 2022
2 parents a9c055e + 178f30e commit 562d170
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tracing/cogs/cogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
21 changes: 21 additions & 0 deletions tracing/util.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 562d170

Please sign in to comment.