@@ -72,6 +72,9 @@ pub struct EncodedProfile {
7272 pub end : SystemTime ,
7373 pub buffer : Vec < u8 > ,
7474 pub endpoints_stats : ProfiledEndpointsStats ,
75+ /// The filename to use when uploading this profile as a multipart attachment,
76+ /// e.g. `"profile.pprof"` or `"profile.otel"`.
77+ pub filename : & ' static str ,
7578}
7679
7780impl EncodedProfile {
@@ -101,6 +104,7 @@ impl EncodedProfile {
101104 end,
102105 buffer,
103106 endpoints_stats,
107+ filename : "profile.pprof" ,
104108 } )
105109 }
106110}
@@ -338,6 +342,7 @@ impl Profile {
338342 upscaling_info : UpscalingInfo ,
339343 ) -> anyhow:: Result < ( ) > {
340344 anyhow:: ensure!( offset_values. len( ) == 1 || offset_values. len( ) == 2 ) ;
345+ #[ cfg( feature = "otel" ) ]
341346 if offset_values. len ( ) == 2 {
342347 anyhow:: ensure!(
343348 self . observations. paired_samples[ offset_values[ 0 ] ] == Some ( offset_values[ 1 ] )
@@ -496,6 +501,23 @@ impl Profile {
496501 self . encode_otel ( end_time, duration)
497502 }
498503
504+ /// Serialize the aggregated profile, choosing the output format at runtime.
505+ ///
506+ /// If the `DD_PROFILING_OTEL_FORMAT` environment variable is set to any non-empty value **and**
507+ /// the crate was compiled with the `otel` feature, the profile is encoded as OTLP; otherwise
508+ /// it falls back to pprof.
509+ pub fn serialize_into_compressed (
510+ self ,
511+ end_time : Option < SystemTime > ,
512+ duration : Option < Duration > ,
513+ ) -> anyhow:: Result < EncodedProfile > {
514+ #[ cfg( feature = "otel" ) ]
515+ if std:: env:: var_os ( "DD_PROFILING_OTEL_FORMAT" ) . is_some ( ) {
516+ return self . encode_otel ( end_time, duration) ;
517+ }
518+ self . serialize_into_compressed_pprof ( end_time, duration)
519+ }
520+
499521 /// Serialize the aggregated profile, adding the end time and duration.
500522 /// # Arguments
501523 /// * `end_time` - Optional end time of the profile. Passing None will use the current time.
@@ -904,6 +926,7 @@ impl Profile {
904926 end,
905927 buffer,
906928 endpoints_stats,
929+ filename : "profile.otel" ,
907930 } )
908931 }
909932
@@ -1070,6 +1093,7 @@ impl Profile {
10701093 end,
10711094 buffer : Vec :: new ( ) ,
10721095 endpoints_stats,
1096+ filename : "profile.pprof" ,
10731097 } )
10741098 }
10751099
0 commit comments