Skip to content
This repository was archived by the owner on Apr 7, 2022. It is now read-only.

Commit 36f98a9

Browse files
committed
Add an example of propagating span context across threads to README
1 parent 8dea15d commit 36f98a9

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ Example usage:
1717

1818
import Control.Concurrent
1919
import Control.Concurrent.Async
20-
import LightStep.HighLevel.IO (LogEntryKey (..), addLog, getEnvConfig, setTag, withSingletonLightStep, withSpan)
20+
import LightStep.HighLevel.IO (LogEntryKey (..), addLog, currentSpanContext, getEnvConfig, setParentSpanContext, setTag, withSingletonLightStep, withSpan)
2121

2222
seriousBusinessMain :: IO ()
23-
seriousBusinessMain = concurrently_ frontend backend
23+
seriousBusinessMain = concurrently_ frontend backend >> threadDelay 1000000
2424
where
2525
frontend =
2626
withSpan "RESTful API" $ do
@@ -58,6 +58,25 @@ seriousBusinessMain = concurrently_ frontend backend
5858
withSpan "Hadoop" $ do
5959
threadDelay 100000
6060
setTag "learning" "super_deep"
61+
withSpan "Parallel map reduce" $ do
62+
result <- withSpan "Reduce" $ do
63+
Just ctx <- currentSpanContext
64+
(a, b) <- do
65+
threadDelay 100000
66+
concurrently
67+
( withSpan "Calculate a" $ do
68+
setParentSpanContext ctx
69+
threadDelay 100000
70+
return "Lorem "
71+
)
72+
( withSpan "Calculate b" $ do
73+
setParentSpanContext ctx
74+
threadDelay 100000
75+
return "ipsum"
76+
)
77+
threadDelay 100000
78+
pure (a <> b)
79+
setTag "result" result
6180

6281
main :: IO ()
6382
main = do

examples/readme/Main.hs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import Control.Concurrent
44
import Control.Concurrent.Async
5-
import LightStep.HighLevel.IO (LogEntryKey (..), addLog, getEnvConfig, setTag, withSingletonLightStep, withSpan)
5+
import LightStep.HighLevel.IO (LogEntryKey (..), addLog, currentSpanContext, getEnvConfig, setParentSpanContext, setTag, withSingletonLightStep, withSpan)
66

77
seriousBusinessMain :: IO ()
8-
seriousBusinessMain = concurrently_ frontend backend
8+
seriousBusinessMain = concurrently_ frontend backend >> threadDelay 1000000
99
where
1010
frontend =
1111
withSpan "RESTful API" $ do
@@ -43,6 +43,25 @@ seriousBusinessMain = concurrently_ frontend backend
4343
withSpan "Hadoop" $ do
4444
threadDelay 100000
4545
setTag "learning" "super_deep"
46+
withSpan "Parallel map reduce" $ do
47+
result <- withSpan "Reduce" $ do
48+
Just ctx <- currentSpanContext
49+
(a, b) <- do
50+
threadDelay 100000
51+
concurrently
52+
( withSpan "Calculate a" $ do
53+
setParentSpanContext ctx
54+
threadDelay 100000
55+
return "Lorem "
56+
)
57+
( withSpan "Calculate b" $ do
58+
setParentSpanContext ctx
59+
threadDelay 100000
60+
return "ipsum"
61+
)
62+
threadDelay 100000
63+
pure (a <> b)
64+
setTag "result" result
4665

4766
main :: IO ()
4867
main = do

0 commit comments

Comments
 (0)