@@ -19,7 +19,10 @@ impl LogExporter for OtlpHttpClient {
19
19
_ => Err ( LogError :: Other ( "exporter is already shut down" . into ( ) ) ) ,
20
20
} ) ?;
21
21
22
- let ( body, content_type) = build_body ( batch) ?;
22
+ let ( body, content_type) = {
23
+ let resource = self . resource . lock ( ) . unwrap ( ) ;
24
+ build_body ( batch, & * resource) ?
25
+ } ;
23
26
let mut request = http:: Request :: builder ( )
24
27
. method ( Method :: POST )
25
28
. uri ( & self . collector_endpoint )
@@ -58,21 +61,29 @@ impl LogExporter for OtlpHttpClient {
58
61
}
59
62
60
63
#[ cfg( feature = "http-proto" ) ]
61
- fn build_body ( logs : Vec < LogEvent > ) -> LogResult < ( Vec < u8 > , & ' static str ) > {
64
+ fn build_body (
65
+ logs : Vec < LogEvent > ,
66
+ resource : & opentelemetry_sdk:: Resource ,
67
+ ) -> LogResult < ( Vec < u8 > , & ' static str ) > {
62
68
use opentelemetry_proto:: tonic:: collector:: logs:: v1:: ExportLogsServiceRequest ;
63
69
use prost:: Message ;
70
+ let resource_logs = logs
71
+ . into_iter ( )
72
+ . map ( |log_event| ( log_event, resource) . into ( ) )
73
+ . collect :: < Vec < _ > > ( ) ;
64
74
65
- let req = ExportLogsServiceRequest {
66
- resource_logs : logs. into_iter ( ) . map ( Into :: into) . collect ( ) ,
67
- } ;
75
+ let req = ExportLogsServiceRequest { resource_logs } ;
68
76
let mut buf = vec ! [ ] ;
69
77
req. encode ( & mut buf) . map_err ( crate :: Error :: from) ?;
70
78
71
79
Ok ( ( buf, "application/x-protobuf" ) )
72
80
}
73
81
74
82
#[ cfg( not( feature = "http-proto" ) ) ]
75
- fn build_body ( logs : Vec < LogData > ) -> LogResult < ( Vec < u8 > , & ' static str ) > {
83
+ fn build_body (
84
+ logs : Vec < LogEvent > ,
85
+ resource : & opentelemetry_sdk:: Resource ,
86
+ ) -> LogResult < ( Vec < u8 > , & ' static str ) > {
76
87
Err ( LogsError :: Other (
77
88
"No http protocol configured. Enable one via `http-proto`" . into ( ) ,
78
89
) )
0 commit comments