Skip to content

Commit f085ada

Browse files
committed
Add opentelemetry-lightstep subproject
1 parent 14cff4a commit f085ada

File tree

9 files changed

+204
-0
lines changed

9 files changed

+204
-0
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ jobs:
2727
run: |
2828
cd opentelemetry
2929
cabal test
30+
- name: Build opentelemetry-lightstep
31+
run: |
32+
cd opentelemetry-lightstep
33+
cabal build -f examples
34+
- name: Test opentelemetry-lightstep
35+
run: |
36+
cd opentelemetry-lightstep
37+
cabal test
3038
3139
linux-stack-lts-14:
3240
runs-on: ubuntu-18.04

opentelemetry-lightstep/LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2020-present Dmitry Ivanov
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
4+
5+
http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main :: IO ()
2+
main = putStrLn "All done"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE TypeApplications #-}
3+
4+
module SomeUsageOfImplicitApi where
5+
6+
import Control.Concurrent
7+
import Control.Concurrent.Async
8+
import Control.Monad
9+
import OpenTelemetry.Common
10+
import OpenTelemetry.FileExporter
11+
import OpenTelemetry.Implicit
12+
13+
main :: IO ()
14+
main = do
15+
exporter <- createFileSpanExporter "helloworld.trace"
16+
let otConfig =
17+
OpenTelemetryConfig
18+
{ otcSpanExporter = exporter
19+
}
20+
withOpenTelemetry otConfig $ do
21+
result <- pieceOfSeriousBusinessLogic 42
22+
print result
23+
24+
pieceOfSeriousBusinessLogic :: Int -> IO Int
25+
pieceOfSeriousBusinessLogic input = withSpan "serious business" $ do
26+
let result = 2 * input
27+
-- setTag is value-polymorphic
28+
29+
-- setTag "input" input -- Int (inferred)
30+
-- setTag @Int "result" result -- Int (explicit)
31+
-- setTag @String "seriousness" "serious" -- literals are polymorphic under OverloadedStrings so we need to annotate
32+
-- setTag @Double "profit" 99 -- numeric literals are also polymorphic
33+
-- setTag "error" False -- Bool literals are not polymorphic
34+
-- setTag @Int "largest integer below 100" 99 -- Int (inferred)
35+
36+
-- TODO: JSON values
37+
38+
addEvent "rpc roundtrip begin"
39+
withSpan "leveraging synergies" $ do
40+
threadDelay 10000
41+
addEvent "enough synergies leveraged"
42+
addEvent "All your base are belong to us"
43+
addEvent "rpc roundtrip end"
44+
withSpan "project" $ do
45+
-- Connecting spans across threads requires some manual plumbing
46+
sp <- getCurrentActiveSpan
47+
asyncWork <- async $ withChildSpanOf sp "data science" $ do
48+
threadDelay 1000000
49+
pure 42
50+
-- Doing a withSpan inside a loop is fine
51+
forM_ [input .. input + 10] $ \i -> withSpan "sprint" $ do
52+
-- setTag "week" i
53+
threadDelay 10000
54+
wait asyncWork
55+
pure result
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
cabal-version: 2.4
2+
name: opentelemetry-lightstep
3+
version: 0.1.0.0
4+
license-file: LICENSE
5+
author: Dmitry Ivanov
6+
maintainer: [email protected]
7+
build-type: Simple
8+
9+
source-repository head
10+
type: git
11+
location: https://github.com/ethercrow/opentelemetry-haskell
12+
13+
common options
14+
default-language: Haskell2010
15+
default-extensions:
16+
BangPatterns
17+
BlockArguments
18+
DataKinds
19+
FlexibleInstances
20+
LambdaCase
21+
MultiParamTypeClasses
22+
MultiWayIf
23+
NamedFieldPuns
24+
NumericUnderscores
25+
RecordWildCards
26+
ScopedTypeVariables
27+
TupleSections
28+
TypeApplications
29+
ViewPatterns
30+
ghc-options:
31+
-Wall
32+
-Wcompat
33+
-Widentities
34+
-Wincomplete-record-updates
35+
-Wincomplete-uni-patterns
36+
-Wpartial-fields
37+
-Wredundant-constraints
38+
-fhide-source-paths
39+
-ferror-spans
40+
-freverse-errors
41+
42+
library
43+
import: options
44+
build-depends:
45+
base >= 4.12,
46+
opentelemetry,
47+
text,
48+
unordered-containers
49+
hs-source-dirs: src
50+
exposed-modules:
51+
OpenTelemetry.LightStepExporter
52+
53+
test-suite just-some-usage-code-that-must-compile
54+
import: options
55+
type: exitcode-stdio-1.0
56+
main-is: Main.hs
57+
other-modules:
58+
SomeUsageOfImplicitApi
59+
hs-source-dirs: just-some-usage-code-that-must-compile
60+
build-depends:
61+
base,
62+
async,
63+
opentelemetry,
64+
opentelemetry-lightstep
65+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
3+
module LightStep.Config where
4+
5+
import Control.Monad.IO.Class
6+
import Data.Foldable
7+
import Data.Maybe
8+
import qualified Data.Text as T
9+
import Network.HTTP2.Client
10+
import System.Environment
11+
import System.IO
12+
13+
data LightStepConfig
14+
= LightStepConfig
15+
{ lsHostName :: HostName,
16+
lsPort :: PortNumber,
17+
lsToken :: T.Text,
18+
lsServiceName :: T.Text,
19+
lsGlobalTags :: [(T.Text, T.Text)],
20+
lsGracefulShutdownTimeoutSeconds :: Int
21+
}
22+
23+
lookupOneOfEnvs :: [String] -> IO (Maybe String)
24+
lookupOneOfEnvs names = asum <$> traverse lookupEnv names
25+
26+
getEnvTagsWithPrefix :: T.Text -> IO [(T.Text, T.Text)]
27+
getEnvTagsWithPrefix prefix =
28+
mapMaybe unprefix <$> getEnvironment
29+
where
30+
unprefix ((T.stripPrefix prefix . T.pack) -> Just k, v) = Just (k, T.pack v)
31+
unprefix _ = Nothing
32+
33+
getEnvConfig :: MonadIO m => m (Maybe LightStepConfig)
34+
getEnvConfig = liftIO $ do
35+
maybe_token_from_env <- lookupOneOfEnvs ["LIGHTSTEP_TOKEN", "LIGHTSTEP_ACCESS_TOKEN", "OPENTRACING_LIGHTSTEP_ACCESS_TOKEN"]
36+
global_tags <- getEnvTagsWithPrefix "OPENTRACING_TAG_"
37+
case maybe_token_from_env of
38+
Just t -> do
39+
host <- fromMaybe "ingest.lightstep.com" <$> lookupOneOfEnvs ["LIGHTSTEP_HOST", "OPENTRACING_LIGHTSTEP_COLLECTOR_HOST"]
40+
port <- maybe 443 read <$> lookupOneOfEnvs ["LIGHTSTEP_PORT", "OPENTRACING_LIGHTSTEP_COLLECTOR_PORT"]
41+
service <- fromMaybe "example-haskell-service" <$> lookupOneOfEnvs ["LIGHTSTEP_SERVICE", "OPENTRACING_LIGHTSTEP_COMPONENT_NAME"]
42+
pure $ Just $ LightStepConfig host port (T.pack t) (T.pack service) global_tags 5
43+
Nothing -> do
44+
hPutStrLn stderr "LIGHTSTEP_ACCESS_TOKEN environment variable not defined"
45+
pure Nothing
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module OpenTelemetry.LightStepExporter where
2+
3+
import Data.Function
4+
import qualified Data.HashMap.Strict as HM
5+
import Data.List
6+
import qualified Data.Text as T
7+
import OpenTelemetry.Common
8+
import System.IO
9+
import Text.Printf
10+
11+
createLightStepExporter :: LightStepConfig -> IO (Exporter Span)
12+
createLightStepExporter LightStepConfig {..} = do
13+
pure
14+
$! Exporter
15+
( \sps -> do
16+
pure ExportSuccess
17+
)
18+
( do
19+
pure ()
20+
)

stack-8.8.1.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ resolver: nightly-2020-01-04
22

33
packages:
44
- opentelemetry
5+
- opentelemetry-lightstep

stack.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ resolver: lts-14.19
22

33
packages:
44
- opentelemetry
5+
- opentelemetry-lightstep

0 commit comments

Comments
 (0)