Skip to content

Commit fafaca3

Browse files
committed
Fix apm framework + comments
1 parent 4691caf commit fafaca3

9 files changed

Lines changed: 43 additions & 13 deletions

src/java/frameworks/azure_application_insights_agent.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ func (a *AzureApplicationInsightsAgentFramework) Supply() error {
101101
a.context.Log.Warning("Could not install default Azure Application Insights configuration: %s", err.Error())
102102
}
103103

104+
// constructJarPath can be skipped here and do it only in finalize, but it can be left as a double check
105+
// if jar path exists after the dependency install
104106
err = a.constructJarPath(agentDir)
105107
if err != nil {
106108
return fmt.Errorf("azure application insights agent not found during supply: %w", err)

src/java/frameworks/datadog_javaagent.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ func (d *DatadogJavaagentFramework) Supply() error {
9696
return fmt.Errorf("failed to install Datadog Javaagent: %w", err)
9797
}
9898

99+
// constructJarPathAndFixClassCount can be skipped here and do it only in finalize, but it can be left
100+
// as a double check if jar path exists after the dependency install
99101
err = d.constructJarPathAndFixClassCount(datadogDir)
100102
if err != nil {
101103
return fmt.Errorf("datadog Java agent JAR path not found during supply: %w", err)

src/java/frameworks/elastic_apm_agent.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,28 @@ func (e *ElasticApmAgentFramework) Supply() error {
7373
return fmt.Errorf("failed to install Elastic APM agent: %w", err)
7474
}
7575

76-
// Find the installed JAR
77-
jarPattern := filepath.Join(elasticDir, "elastic-apm-agent*.jar")
78-
matches, err := filepath.Glob(jarPattern)
76+
err = e.constructJarPath(elasticDir)
7977
if err != nil {
80-
return fmt.Errorf("failed to search for Elastic APM agent JAR: %w", err)
78+
return err
8179
}
82-
if len(matches) == 0 {
83-
return fmt.Errorf("Elastic APM agent JAR not found after installation in %s", elasticDir)
84-
}
85-
e.jarPath = matches[0]
8680

8781
e.context.Log.Info("Elastic APM agent %s installed", dep.Version)
8882
return nil
8983
}
9084

9185
// Finalize configures the Elastic APM agent
9286
func (e *ElasticApmAgentFramework) Finalize() error {
93-
if e.jarPath == "" || e.service == nil {
94-
return nil
87+
elasticDir := filepath.Join(e.context.Stager.DepDir(), "elastic_apm_agent")
88+
err := e.constructJarPath(elasticDir)
89+
if err != nil {
90+
return err
91+
}
92+
service := e.findElasticApmService()
93+
// service should not be nil as detect has already passed
94+
if service == nil {
95+
e.context.Log.Debug("Elastic APM Agent: No elastic-apm service found")
9596
}
97+
e.service = service
9698

9799
e.context.Log.BeginStep("Configuring Elastic APM agent")
98100

@@ -257,3 +259,17 @@ func (e *ElasticApmAgentFramework) getApplicationName() string {
257259

258260
return ""
259261
}
262+
263+
func (e *ElasticApmAgentFramework) constructJarPath(elasticDir string) error {
264+
// Find the installed JAR
265+
jarPattern := filepath.Join(elasticDir, "elastic-apm-agent*.jar")
266+
matches, err := filepath.Glob(jarPattern)
267+
if err != nil {
268+
return fmt.Errorf("failed to search for Elastic APM agent JAR: %w", err)
269+
}
270+
if len(matches) == 0 {
271+
return fmt.Errorf("Elastic APM agent JAR not found after installation in %s", elasticDir)
272+
}
273+
e.jarPath = matches[0]
274+
return nil
275+
}

src/java/frameworks/google_stackdriver_profiler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func (g *GoogleStackdriverProfilerFramework) Supply() error {
8383
return fmt.Errorf("failed to install Google Stackdriver Profiler: %w", err)
8484
}
8585

86+
// constructAgentPath can be skipped here and do it only in finalize, but it can be left as a double check
87+
// if jar path exists after the dependency install
8688
err = g.constructAgentPath(profilerDir)
8789
if err != nil {
8890
return fmt.Errorf("google stackdriver profiler agent not found during supply: %w", err)

src/java/frameworks/introscope_agent.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func (i *IntroscopeAgentFramework) Supply() error {
6363
return fmt.Errorf("failed to install Introscope agent: %w", err)
6464
}
6565

66+
// constructAgentPath can be skipped here and do it only in finalize, but it can be left as a double check
67+
// if jar path exists after the dependency install
6668
err = i.constructAgentPath(agentDir)
6769
if err != nil {
6870
return fmt.Errorf("introscope Agent.jar not found during supply: %w", err)

src/java/frameworks/maria_db_jdbc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ func (f *MariaDBJDBCFramework) Supply() error {
6767
return fmt.Errorf("failed to install MariaDB JDBC: %w", err)
6868
}
6969

70-
// Find the installed JAR
70+
// constructJarPath can be skipped here and do it only in finalize, but it can be left as a double check
71+
// if jar path exists after the dependency install
7172
err = f.constructJarPath(mariadbDir)
7273
if err != nil {
7374
return fmt.Errorf("MariaDB JDBC JAR not found during supply: %w", err)

src/java/frameworks/riverbed_appinternals_agent.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ func (r *RiverbedAppInternalsAgentFramework) Supply() error {
6363
return fmt.Errorf("failed to install Riverbed AppInternals agent: %w", err)
6464
}
6565

66-
// Find the installed agent directory (contains lib/rvbd-agent.jar)
66+
// constructAgentJarPath can be skipped here and do it only in finalize, but it can be left as a double check
67+
// if jar path exists after the dependency install
6768
err = r.constructAgentJarPath(agentDir)
6869
if err != nil {
6970
return fmt.Errorf("riverbed appinternals agent JAR not found during supply: %w", err)
@@ -217,6 +218,7 @@ func (r *RiverbedAppInternalsAgentFramework) getApplicationName() string {
217218
}
218219

219220
func (r *RiverbedAppInternalsAgentFramework) constructAgentJarPath(agentDir string) error {
221+
// Find the installed agent directory (contains lib/rvbd-agent.jar)
220222
agentJarPath := filepath.Join(agentDir, "lib", "rvbd-agent.jar")
221223
if _, err := os.Stat(agentJarPath); err != nil {
222224
return fmt.Errorf("agent jar not found after installation: %w", err)

src/java/frameworks/sky_walking_agent.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func (s *SkyWalkingAgentFramework) Supply() error {
8181
return fmt.Errorf("failed to install SkyWalking agent: %w", err)
8282
}
8383

84+
// constructJarPath can be skipped here and do it only in finalize, but it can be left as a double check
85+
// if jar path exists after the dependency install
8486
err = s.constructJarPath(agentDir)
8587
if err != nil {
8688
return fmt.Errorf("SkyWalking agent JAR path not found during supply: %w", err)

src/java/frameworks/splunk_otel_java_agent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ func (s *SplunkOtelJavaAgentFramework) Supply() error {
9090
return fmt.Errorf("failed to install Splunk OTEL Java agent: %w", err)
9191
}
9292

93-
// Find the installed agent JAR
93+
// constructJarPath can be skipped here and do it only in finalize, but it can be left as a double check
94+
// if jar path exists after the dependency install
9495
err = s.constructJarPath(agentDir)
9596
if err != nil {
9697
return fmt.Errorf("splunk OTEL Java agent JAR path not found during supply: %w", err)

0 commit comments

Comments
 (0)