9090 ssl_options => []}.
9191
9292-type protocol () :: grpc | http_protobuf | http_json .
93+ -type compression () :: gzip .
9394
9495-type opts () :: #{endpoints => [endpoint ()],
9596 headers => headers (),
103104-record (state , {protocol :: protocol (),
104105 channel_pid :: pid () | undefined ,
105106 headers :: headers (),
107+ compression :: compression () | undefined ,
106108 grpc_metadata :: map () | undefined ,
107109 endpoints :: [endpoint_map ()]}).
108110
@@ -113,14 +115,22 @@ init(Opts) ->
113115 SSLOptions = maps :get (ssl_options , Opts1 , undefined ),
114116 Endpoints = endpoints (maps :get (endpoints , Opts1 , ? DEFAULT_ENDPOINTS ), SSLOptions ),
115117 Headers = headers (maps :get (headers , Opts1 , [])),
118+ Compression = maps :get (compression , Opts1 , undefined ),
116119 case maps :get (protocol , Opts1 , http_protobuf ) of
117120 grpc ->
118121 ChannelOpts = maps :get (channel_opts , Opts1 , #{}),
119- case grpcbox_channel :start_link (? MODULE , grpcbox_endpoints (Endpoints ), ChannelOpts ) of
122+ UpdatedChannelOpts = case Compression of
123+ undefined -> ChannelOpts ;
124+ Encoding -> maps :put (encoding , Encoding , ChannelOpts )
125+ end ,
126+ case grpcbox_channel :start_link (? MODULE ,
127+ grpcbox_endpoints (Endpoints ),
128+ UpdatedChannelOpts ) of
120129 {ok , ChannelPid } ->
121130 {ok , # state {channel_pid = ChannelPid ,
122131 endpoints = Endpoints ,
123132 headers = Headers ,
133+ compression = Compression ,
124134 grpc_metadata = headers_to_grpc_metadata (Headers ),
125135 protocol = grpc }};
126136 ErrorOrIgnore ->
@@ -130,15 +140,18 @@ init(Opts) ->
130140 " to http_protobuf protocol. reason=~p " , [ErrorOrIgnore ]),
131141 {ok , # state {endpoints = Endpoints ,
132142 headers = Headers ,
143+ compression = Compression ,
133144 protocol = http_protobuf }}
134145 end ;
135146 http_protobuf ->
136147 {ok , # state {endpoints = Endpoints ,
137148 headers = Headers ,
149+ compression = Compression ,
138150 protocol = http_protobuf }};
139151 http_json ->
140152 {ok , # state {endpoints = Endpoints ,
141153 headers = Headers ,
154+ compression = Compression ,
142155 protocol = http_json }}
143156 end .
144157
@@ -147,18 +160,24 @@ export(_Tab, _Resource, #state{protocol=http_json}) ->
147160 {error , unimplemented };
148161export (Tab , Resource , # state {protocol = http_protobuf ,
149162 headers = Headers ,
163+ compression = Compression ,
150164 endpoints = [#{scheme := Scheme ,
151165 host := Host ,
152166 path := Path ,
153167 port := Port ,
154168 ssl_options := SSLOptions } | _ ]}) ->
155169 Proto = opentelemetry_exporter_trace_service_pb :encode_msg (tab_to_proto (Tab , Resource ),
156170 export_trace_service_request ),
171+ {NewHeaders , NewProto } = case Compression of
172+ gzip -> {[{" content-encoding" , " gzip" } | Headers ], zlib :gzip (Proto )};
173+ _ -> {Headers , Proto }
174+ end ,
157175 Address = uri_string :normalize (#{scheme => Scheme ,
158176 host => Host ,
159177 port => Port ,
160178 path => Path }),
161- case httpc :request (post , {Address , Headers , " application/x-protobuf" , Proto },
179+
180+ case httpc :request (post , {Address , NewHeaders , " application/x-protobuf" , NewProto },
162181 [{ssl , SSLOptions }], []) of
163182 {ok , {{_ , Code , _ }, _ , _ }} when Code >= 200 andalso Code =< 202 ->
164183 ok ;
@@ -199,7 +218,7 @@ shutdown(#state{channel_pid=Pid}) ->
199218% %
200219
201220grpcbox_endpoints (Endpoints ) ->
202- [{scheme (Scheme ), Host , Port , maps :get (ssl_options , Endpoint , [])} ||
221+ [{scheme (Scheme ), Host , Port , maps :get (ssl_options , Endpoint , [])} ||
203222 #{scheme := Scheme , host := Host , port := Port } = Endpoint <- Endpoints ].
204223
205224headers_to_grpc_metadata (Headers ) ->
0 commit comments