@@ -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
9286func (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+ }
0 commit comments