From 8149d02d2fdb5f7bc46b5349b7adf9aaea5ca489 Mon Sep 17 00:00:00 2001 From: Steve Willoughby Date: Thu, 14 Dec 2023 07:34:46 -0800 Subject: [PATCH 1/3] clm callback function --- v3/go.mod | 7 +++++++ v3/newrelic/code_level_metrics.go | 33 +++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/v3/go.mod b/v3/go.mod index fda43a82c..1f501f0d7 100644 --- a/v3/go.mod +++ b/v3/go.mod @@ -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 diff --git a/v3/newrelic/code_level_metrics.go b/v3/newrelic/code_level_metrics.go index 561435e54..2a179c6c1 100644 --- a/v3/newrelic/code_level_metrics.go +++ b/v3/newrelic/code_level_metrics.go @@ -90,6 +90,7 @@ type traceOptSet struct { DemandCLM bool IgnoredPrefixes []string PathPrefixes []string + LocationCallback func() *CodeLocation } // @@ -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 @@ -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 { @@ -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) From 865dec7f1e3875b0a03eda96f6f7fa50a5656b97 Mon Sep 17 00:00:00 2001 From: Steve Willoughby Date: Thu, 14 Dec 2023 07:39:05 -0800 Subject: [PATCH 2/3] reverted go.mod --- v3/go.mod | 8 -------- 1 file changed, 8 deletions(-) diff --git a/v3/go.mod b/v3/go.mod index 1f501f0d7..e064d1ccf 100644 --- a/v3/go.mod +++ b/v3/go.mod @@ -7,14 +7,6 @@ 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 retract v3.25.0 // release process error corrected in v3.25.1 From 932f589c8129ee1d6b9236de7593dd5dc06f0d85 Mon Sep 17 00:00:00 2001 From: Steve Willoughby Date: Thu, 14 Dec 2023 07:41:49 -0800 Subject: [PATCH 3/3] additional documentation comment --- v3/newrelic/code_level_metrics.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/v3/newrelic/code_level_metrics.go b/v3/newrelic/code_level_metrics.go index 2a179c6c1..7fb9b4399 100644 --- a/v3/newrelic/code_level_metrics.go +++ b/v3/newrelic/code_level_metrics.go @@ -125,6 +125,13 @@ func WithCodeLocation(loc *CodeLocation) TraceOption { // level metrics is enabled, saving unnecessary work if those metrics // are not enabled. // +// If the callback function value passed here is nil, then no callback +// function will be used (same as if this function were never called). +// If the callback function itself returns nil instead of a pointer to +// a CodeLocation, then it is assumed the callback function was not able +// to determine the code location, and the CLM reporting code's normal +// method for determining the code location is used instead. +// func WithCodeLocationCallback(locf func() *CodeLocation) TraceOption { return func(o *traceOptSet) { o.LocationCallback = locf