Skip to content

Commit

Permalink
Merge pull request newrelic#958 from nr-swilloughby/ar_race
Browse files Browse the repository at this point in the history
added mutex guards around appRun for code level metrics
  • Loading branch information
nr-swilloughby authored Sep 5, 2024
2 parents ec1af19 + a78ad46 commit 2c21c19
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
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 2c21c19

Please sign in to comment.