66import  datadog .trace .api .flare .TracerFlare ;
77import  datadog .trace .bootstrap .config .provider .ConfigProvider ;
88import  java .io .IOException ;
9+ import  java .nio .charset .StandardCharsets ;
10+ import  java .nio .file .Files ;
11+ import  java .nio .file .Path ;
12+ import  java .nio .file .Paths ;
913import  java .util .Map ;
1014import  java .util .zip .ZipOutputStream ;
1115
1216public  final  class  ProfilerFlare  implements  TracerFlare .Reporter  {
1317  private  static  final  ProfilerFlare  INSTANCE  = new  ProfilerFlare ();
18+   private  static  Exception  profilerInitializationException ;
1419
1520  public  static  void  register () {
1621    TracerFlare .addReporter (INSTANCE );
1722  }
1823
24+   public  static  void  reportInitializationException (Exception  e ) {
25+     profilerInitializationException  = e ;
26+   }
27+ 
1928  @ Override 
2029  public  void  addReportToFlare (ZipOutputStream  zip ) throws  IOException  {
2130    TracerFlare .addText (zip , "profiler_config.txt" , getProfilerConfig ());
31+     String  templateOverrideFile  = Config .get ().getProfilingTemplateOverrideFile ();
32+     if  (templateOverrideFile  != null ) {
33+       try  {
34+         Path  path  = Paths .get (templateOverrideFile );
35+         if  (Files .exists (path )) {
36+           String  fileContents  = new  String (Files .readAllBytes (path ), StandardCharsets .UTF_8 );
37+           TracerFlare .addText (zip , "profiling_template_override.jfp" , fileContents );
38+         }
39+       } catch  (IOException  e ) {
40+         // no-op, ignore if we can't read the template override file 
41+       }
42+     }
2243  }
2344
2445  private  String  getProfilerConfig () {
@@ -29,6 +50,15 @@ private String getProfilerConfig() {
2950    ConfigProvider  configProvider  = ConfigProvider .getInstance ();
3051    Config  config  = Config .get ();
3152
53+     sb .append ("=== Profiler Initalization Status ===\n " );
54+     if  (profilerInitializationException  == null ) {
55+       sb .append ("Profiler initialized successfully.\n " );
56+     } else  {
57+       sb .append ("Profiler initializtion failed due to: \n " );
58+       sb .append (profilerInitializationException .getMessage ());
59+       sb .append ("\n " );
60+     }
61+ 
3262    sb .append ("=== Core Settings ===\n " );
3363    appendConfig (
3464        sb ,
0 commit comments