@@ -35,8 +35,9 @@ module Core.Telemetry.Honeycomb (
35
35
honeycombExporter ,
36
36
) where
37
37
38
+ import Codec.Compression.GZip qualified as GZip (compress )
38
39
import Control.Exception.Safe qualified as Safe (catch , finally , throw )
39
- import Core.Data.Clock (Time , unTime , getCurrentTimeNanoseconds )
40
+ import Core.Data.Clock (Time , getCurrentTimeNanoseconds , unTime )
40
41
import Core.Data.Structures (Map , fromMap , insertKeyValue , intoMap , lookupKeyValue )
41
42
import Core.Encoding.Json
42
43
import Core.Program.Arguments
@@ -49,6 +50,8 @@ import Core.Text.Rope
49
50
import Core.Text.Utilities
50
51
import Data.ByteString (ByteString )
51
52
import Data.ByteString qualified as B (ByteString )
53
+ import Data.ByteString.Builder (Builder )
54
+ import Data.ByteString.Builder qualified as Builder (lazyByteString )
52
55
import Data.ByteString.Char8 qualified as C (append , null , putStrLn )
53
56
import Data.ByteString.Lazy qualified as L (ByteString )
54
57
import Data.Fixed
@@ -57,7 +60,8 @@ import Data.List qualified as List
57
60
import Network.Http.Client
58
61
import System.Environment (lookupEnv )
59
62
import System.Exit (ExitCode (.. ))
60
- import System.IO.Streams (InputStream )
63
+ import System.IO.Streams (InputStream , OutputStream )
64
+ import System.IO.Streams qualified as Streams (write )
61
65
import System.Posix.Process qualified as Posix (exitImmediately )
62
66
63
67
{- |
@@ -233,6 +237,13 @@ cleanupConnection r = do
233
237
writeIORef r Nothing
234
238
)
235
239
240
+ compressBody :: Bytes -> OutputStream Builder -> IO ()
241
+ compressBody bytes o = do
242
+ let x = fromBytes bytes
243
+ let x' = GZip. compress x
244
+ let b = Builder. lazyByteString x'
245
+ Streams. write (Just b) o
246
+
236
247
postEventToHoneycombAPI :: IORef (Maybe Connection ) -> ApiKey -> Dataset -> JsonValue -> IO ()
237
248
postEventToHoneycombAPI r apikey dataset json = attempt False
238
249
where
@@ -242,7 +253,7 @@ postEventToHoneycombAPI r apikey dataset json = attempt False
242
253
c <- acquireConnection r
243
254
244
255
-- actually transmit telemetry to Honeycomb
245
- sendRequest c q (simpleBody (fromBytes ( encodeToUTF8 json) ))
256
+ sendRequest c q (compressBody ( encodeToUTF8 json))
246
257
receiveResponse c handler
247
258
)
248
259
( \ (e :: SomeException ) -> do
@@ -251,14 +262,17 @@ postEventToHoneycombAPI r apikey dataset json = attempt False
251
262
cleanupConnection r
252
263
case retrying of
253
264
False -> do
254
- putStrLn " Reattempting "
265
+ putStrLn " internal: Reconnecting to Honeycomb "
255
266
attempt True
256
- True -> Safe. throw e
267
+ True -> do
268
+ putStrLn " internal: Failed to re-establish connection to Honeycomb"
269
+ Safe. throw e
257
270
)
258
271
259
272
q = buildRequest1 $ do
260
273
http POST (fromRope (" /1/batch/" <> dataset))
261
274
setContentType " application/json"
275
+ setHeader " Content-Encoding" " gzip"
262
276
setHeader " X-Honeycomb-Team" (fromRope (apikey))
263
277
264
278
{-
@@ -285,7 +299,7 @@ postEventToHoneycombAPI r apikey dataset json = attempt False
285
299
pure ()
286
300
_ -> do
287
301
-- some other status!
288
- putStrLn " Unexpected status returned;"
302
+ putStrLn " internal: Unexpected status returned;"
289
303
C. putStrLn body
290
304
_ -> putStrLn " internal: wtf?"
291
305
_ -> do
0 commit comments