项目作者: ethercrow

项目描述 :
LightStep OpenTracing client library
高级语言: Haskell
项目地址: git://github.com/ethercrow/lightstep-haskell.git
创建时间: 2019-09-29T16:13:27Z
项目社区:https://github.com/ethercrow/lightstep-haskell

开源协议:Other

下载


CI Status
Hackage
lightstep-haskell on Stackage Nightly

What is it?

A library for instrumenting your code and sending traces to LightStep.

How to use it?

Example usage:

  1. {-# LANGUAGE OverloadedStrings #-}
  2. import Control.Concurrent
  3. import Control.Concurrent.Async
  4. import LightStep.HighLevel.IO (LogEntryKey (..), addLog, currentSpanContext, getEnvConfig, setParentSpanContext, setTag, withSingletonLightStep, withSpan)
  5. seriousBusinessMain :: IO ()
  6. seriousBusinessMain = concurrently_ frontend backend >> threadDelay 1000000
  7. where
  8. frontend =
  9. withSpan "RESTful API" $ do
  10. threadDelay 10000
  11. setTag "foo" "bar"
  12. withSpan "Kafka" $ do
  13. threadDelay 20000
  14. setTag "foo" "baz"
  15. threadDelay 30000
  16. withSpan "GraphQL" $ do
  17. threadDelay 40000
  18. setTag "foo" "quux"
  19. addLog Event "monkey-job"
  20. addLog (Custom "foo") "bar"
  21. withSpan "Mongodb" $ do
  22. threadDelay 50000
  23. setTag "lorem" "ipsum"
  24. threadDelay 60000
  25. withSpan "data->json" $ pure ()
  26. withSpan "json->yaml" $ pure ()
  27. withSpan "yaml->xml" $ pure ()
  28. withSpan "xml->protobuf" $ pure ()
  29. withSpan "protobuf->thrift" $ pure ()
  30. withSpan "thrift->base64" $ pure ()
  31. threadDelay 70000
  32. backend =
  33. withSpan "Background Data Science" $ do
  34. threadDelay 10000
  35. withSpan "Tensorflow" $ do
  36. threadDelay 100000
  37. setTag "learning" "deep"
  38. withSpan "Torch" $ do
  39. threadDelay 100000
  40. setTag "learning" "very_deep"
  41. withSpan "Hadoop" $ do
  42. threadDelay 100000
  43. setTag "learning" "super_deep"
  44. withSpan "Parallel map reduce" $ do
  45. result <- withSpan "Reduce" $ do
  46. Just ctx <- currentSpanContext
  47. (a, b) <- do
  48. threadDelay 100000
  49. concurrently
  50. ( withSpan "Calculate a" $ do
  51. setParentSpanContext ctx
  52. threadDelay 100000
  53. return "Lorem "
  54. )
  55. ( withSpan "Calculate b" $ do
  56. setParentSpanContext ctx
  57. threadDelay 100000
  58. return "ipsum"
  59. )
  60. threadDelay 100000
  61. pure (a <> b)
  62. setTag "result" result
  63. main :: IO ()
  64. main = do
  65. -- Construct a config from env variables
  66. -- - LIGHTSTEP_ACCESS_TOKEN
  67. -- - LIGHTSTEP_HOST (optional)
  68. -- - LIGHTSTEP_PORT (optional)
  69. -- - LIGHTSTEP_SERVICE (optional)
  70. Just lsConfig <- getEnvConfig
  71. withSingletonLightStep lsConfig seriousBusinessMain
  72. putStrLn "All done"