Skip to content

Commit

Permalink
added mutex guards around appRun for code level metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nr-swilloughby committed Sep 4, 2024
1 parent b838457 commit 97c6313
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
9 changes: 8 additions & 1 deletion v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ module github.com/newrelic/go-agent/v3
go 1.20

require (
google.golang.org/protobuf v1.5.3
github.com/golang/protobuf v1.5.3
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
8 changes: 6 additions & 2 deletions v3/newrelic/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ type Application struct {
/*
// IsAIMonitoringEnabled returns true if monitoring for the specified mode of the named integration is enabled.
func (app *Application) IsAIMonitoringEnabled(integration string, streaming bool) bool {
if app == nil || app.app == nil || app.app.run == nil {
if app == nil || app.app == nil {
return false
}
run, _ := app.app.getState()
if run == nil {
return false
}
aiconf := app.app.run.Config.AIMonitoring
aiconf := run.Config.AIMonitoring
if !aiconf.Enabled {
return false
}
Expand Down
34 changes: 20 additions & 14 deletions v3/newrelic/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ func WrapHandle(app *Application, pattern string, handler http.Handler, options
var tOptions *traceOptSet
var txnOptionList []TraceOption

if app.app != nil && app.app.run != nil && app.app.run.Config.CodeLevelMetrics.Enabled {
tOptions = resolveCLMTraceOptions(options)
if tOptions != nil && !tOptions.SuppressCLM && (tOptions.DemandCLM || app.app.run.Config.CodeLevelMetrics.Scope == 0 || (app.app.run.Config.CodeLevelMetrics.Scope&TransactionCLM) != 0) {
// we are for sure collecting CLM here, so go to the trouble of collecting this code location if nothing else has yet.
if tOptions.LocationOverride == nil {
if loc, err := cache.FunctionLocation(handler, handler.ServeHTTP); err == nil {
WithCodeLocation(loc)(tOptions)
if app.app != nil {
run, _ := app.app.getState()
if run != nil && run.Config.CodeLevelMetrics.Enabled {
tOptions = resolveCLMTraceOptions(options)
if tOptions != nil && !tOptions.SuppressCLM && (tOptions.DemandCLM || run.Config.CodeLevelMetrics.Scope == 0 || (run.Config.CodeLevelMetrics.Scope&TransactionCLM) != 0) {
// we are for sure collecting CLM here, so go to the trouble of collecting this code location if nothing else has yet.
if tOptions.LocationOverride == nil {
if loc, err := cache.FunctionLocation(handler, handler.ServeHTTP); err == nil {
WithCodeLocation(loc)(tOptions)
}
}
}
}
Expand Down Expand Up @@ -96,13 +99,16 @@ func AddCodeLevelMetricsTraceOptions(app *Application, options []TraceOption, ca
return options
}

if app.app != nil && app.app.run != nil && app.app.run.Config.CodeLevelMetrics.Enabled {
tOptions = resolveCLMTraceOptions(options)
if tOptions != nil && !tOptions.SuppressCLM && (tOptions.DemandCLM || app.app.run.Config.CodeLevelMetrics.Scope == 0 || (app.app.run.Config.CodeLevelMetrics.Scope&TransactionCLM) != 0) {
// we are for sure collecting CLM here, so go to the trouble of collecting this code location if nothing else has yet.
if tOptions.LocationOverride == nil {
if loc, err := cache.FunctionLocation(cachedLocations); err == nil {
WithCodeLocation(loc)(tOptions)
if app.app != nil {
run, _ := app.app.getState()
if run != nil && run.Config.CodeLevelMetrics.Enabled {
tOptions = resolveCLMTraceOptions(options)
if tOptions != nil && !tOptions.SuppressCLM && (tOptions.DemandCLM || run.Config.CodeLevelMetrics.Scope == 0 || (run.Config.CodeLevelMetrics.Scope&TransactionCLM) != 0) {
// we are for sure collecting CLM here, so go to the trouble of collecting this code location if nothing else has yet.
if tOptions.LocationOverride == nil {
if loc, err := cache.FunctionLocation(cachedLocations); err == nil {
WithCodeLocation(loc)(tOptions)
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion v3/newrelic/secure_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type securityAgent interface {
func (app *Application) RegisterSecurityAgent(s securityAgent) {
if app != nil && app.app != nil && s != nil {
secureAgent = s
if app.app.run != nil {
run, _ := app.app.getState()
if run != nil {
secureAgent.RefreshState(getLinkedMetaData(app.app))
}
}
Expand Down

0 comments on commit 97c6313

Please sign in to comment.