Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add util to tracing to get function name, and further COGS constants #355

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}