Skip to content

Commit

Permalink
clm callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
nr-swilloughby committed Dec 14, 2023
1 parent 02cae21 commit 8149d02
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ require (
google.golang.org/grpc v1.56.3
)

require (
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)

retract v3.22.0 // release process error corrected in v3.22.1

Expand Down
33 changes: 31 additions & 2 deletions v3/newrelic/code_level_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type traceOptSet struct {
DemandCLM bool
IgnoredPrefixes []string
PathPrefixes []string
LocationCallback func() *CodeLocation
}

//
Expand All @@ -106,12 +107,30 @@ type TraceOption func(*traceOptSet)
// This is probably a value previously obtained by calling
// ThisCodeLocation().
//
// Deprecated: This function requires the caller to do the work
// up-front to calculate the code location, which may be a waste
// of effort if code level metrics happens to be disabled. Instead,
// use the WithCodeLocationCallback function.
//
func WithCodeLocation(loc *CodeLocation) TraceOption {
return func(o *traceOptSet) {
o.LocationOverride = loc
}
}

//
// WithCodeLocationCallback adds a callback function which the agent
// will call if it needs to report the code location with an explicit
// value provided by the caller. This will only be called if code
// level metrics is enabled, saving unnecessary work if those metrics
// are not enabled.
//
func WithCodeLocationCallback(locf func() *CodeLocation) TraceOption {
return func(o *traceOptSet) {
o.LocationCallback = locf
}
}

//
// WithIgnoredPrefix indicates that the code location reported
// for Code Level Metrics should be the first function in the
Expand Down Expand Up @@ -385,6 +404,9 @@ func withPreparedOptions(newOptions *traceOptSet) TraceOption {
if newOptions.LocationOverride != nil {
o.LocationOverride = newOptions.LocationOverride
}
if newOptions.LocationCallback != nil {
o.LocationCallback = newOptions.LocationCallback
}
o.SuppressCLM = newOptions.SuppressCLM
o.DemandCLM = newOptions.DemandCLM
if newOptions.IgnoredPrefixes != nil {
Expand Down Expand Up @@ -542,9 +564,16 @@ func resolveCLMTraceOptions(options []TraceOption) *traceOptSet {

func reportCodeLevelMetrics(tOpts traceOptSet, run *appRun, setAttr func(string, string, interface{})) {
var location CodeLocation
var locationp *CodeLocation

if tOpts.LocationCallback != nil {
locationp = tOpts.LocationCallback()
} else {
locationp = tOpts.LocationOverride
}

if tOpts.LocationOverride != nil {
location = *tOpts.LocationOverride
if locationp != nil {
location = *locationp
} else {
pcs := make([]uintptr, 20)
depth := runtime.Callers(2, pcs)
Expand Down

0 comments on commit 8149d02

Please sign in to comment.