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

added mutex guards around appRun for code level metrics #958

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 0 additions & 1 deletion v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
google.golang.org/grpc v1.56.3
)


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

retract v3.25.0 // release process error corrected in v3.25.1
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
Loading