@@ -9,42 +9,48 @@ use super::OtlpHttpClient;
99
1010#[ async_trait]
1111impl LogExporter for OtlpHttpClient {
12- async fn export ( & self , batch : LogBatch < ' _ > ) -> LogResult < ( ) > {
13- let client = self
14- . client
15- . lock ( )
16- . map_err ( |e| LogError :: Other ( e. to_string ( ) . into ( ) ) )
17- . and_then ( |g| match & * g {
18- Some ( client) => Ok ( Arc :: clone ( client) ) ,
19- _ => Err ( LogError :: Other ( "exporter is already shut down" . into ( ) ) ) ,
20- } ) ?;
21-
22- let ( body, content_type) = { self . build_logs_export_body ( batch) ? } ;
23- let mut request = http:: Request :: builder ( )
24- . method ( Method :: POST )
25- . uri ( & self . collector_endpoint )
26- . header ( CONTENT_TYPE , content_type)
27- . body ( body)
28- . map_err ( |e| crate :: Error :: RequestFailed ( Box :: new ( e) ) ) ?;
29-
30- for ( k, v) in & self . headers {
31- request. headers_mut ( ) . insert ( k. clone ( ) , v. clone ( ) ) ;
12+ #[ allow( clippy:: manual_async_fn) ]
13+ fn export < ' a > (
14+ & ' a self ,
15+ batch : & ' a LogBatch < ' a > ,
16+ ) -> impl std:: future:: Future < Output = LogResult < ( ) > > + Send + ' a {
17+ async move {
18+ let client = self
19+ . client
20+ . lock ( )
21+ . map_err ( |e| LogError :: Other ( e. to_string ( ) . into ( ) ) )
22+ . and_then ( |g| match & * g {
23+ Some ( client) => Ok ( Arc :: clone ( client) ) ,
24+ _ => Err ( LogError :: Other ( "exporter is already shut down" . into ( ) ) ) ,
25+ } ) ?;
26+
27+ let ( body, content_type) = { self . build_logs_export_body ( batch) ? } ;
28+ let mut request = http:: Request :: builder ( )
29+ . method ( Method :: POST )
30+ . uri ( & self . collector_endpoint )
31+ . header ( CONTENT_TYPE , content_type)
32+ . body ( body)
33+ . map_err ( |e| crate :: Error :: RequestFailed ( Box :: new ( e) ) ) ?;
34+
35+ for ( k, v) in & self . headers {
36+ request. headers_mut ( ) . insert ( k. clone ( ) , v. clone ( ) ) ;
37+ }
38+
39+ let request_uri = request. uri ( ) . to_string ( ) ;
40+ let response = client. send ( request) . await ?;
41+
42+ if !response. status ( ) . is_success ( ) {
43+ let error = format ! (
44+ "OpenTelemetry logs export failed. Url: {}, Status Code: {}, Response: {:?}" ,
45+ response. status( ) . as_u16( ) ,
46+ request_uri,
47+ response. body( )
48+ ) ;
49+ return Err ( LogError :: Other ( error. into ( ) ) ) ;
50+ }
51+
52+ Ok ( ( ) )
3253 }
33-
34- let request_uri = request. uri ( ) . to_string ( ) ;
35- let response = client. send ( request) . await ?;
36-
37- if !response. status ( ) . is_success ( ) {
38- let error = format ! (
39- "OpenTelemetry logs export failed. Url: {}, Status Code: {}, Response: {:?}" ,
40- response. status( ) . as_u16( ) ,
41- request_uri,
42- response. body( )
43- ) ;
44- return Err ( LogError :: Other ( error. into ( ) ) ) ;
45- }
46-
47- Ok ( ( ) )
4854 }
4955
5056 fn shutdown ( & mut self ) {
0 commit comments