Skip to content

Commit

Permalink
Reduce honeycomb init timeout and bypass otel when failed (#20)
Browse files Browse the repository at this point in the history
* Reduce timeout and bypass otel ceremony when failing to initialize honeycomb

* bump version
  • Loading branch information
friedbrice authored Mar 28, 2024
1 parent ffd4d47 commit 22c1897
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ and this project adheres to the

## Unreleased

## 0.0.6.0 - 2024-03-28

- [#20](https://github.com/parsonsmatt/hotel-california/pull/19/)
- Reduce Honeycomb target initialization timeout from 3 seconds to 1 second.
- `withGlobalTracing` now expects a callback that accepts the honeycomb target.
- Executable bypasses OTEL operations if Honeycomb target cannot be initialized.

## 0.0.5.0 - 2024-02-29

- [#19](https://github.com/parsonsmatt/hotel-california/pull/19/)
Expand Down
6 changes: 4 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ optionsParser =

main :: IO ()
main = do
withGlobalTracing do
withGlobalTracing $ \mTarget -> do
let parserPrefs = defaultPrefs{ prefMultiSuffix = "..." }
Command {..} <- customExecParser parserPrefs optionsParser
case commandSubCommand of
Exec execArgs ->
runExecArgs execArgs
case mTarget of
Just _target -> runExecArgs execArgs
Nothing -> runNoTracing $ execArgsSubprocess execArgs
4 changes: 2 additions & 2 deletions hotel-california.cabal
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.35.2.
-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack

name: hotel-california
version: 0.0.5.0
version: 0.0.6.0
description: Please see the README on GitHub at <https://github.com/parsonsmatt/hotel-california#readme>
homepage: https://github.com/parsonsmatt/hotel-california#readme
bug-reports: https://github.com/parsonsmatt/hotel-california/issues
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: hotel-california
version: 0.0.5.0
version: 0.0.6.0
github: "parsonsmatt/hotel-california"
license: BSD3
author: Matt Parsons
Expand Down
7 changes: 7 additions & 0 deletions src/HotelCalifornia/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ makeInitialAttributes subprocess extraAttributes = do

pure $ processAttributes <> extraAttributes

runNoTracing :: Subprocess -> IO ()
runNoTracing subproc = do
let processConfig = commandToProcessConfig subproc
userEnv <- getEnvironment
exitCode <- runProcess $ setEnv userEnv processConfig
exitWith exitCode

runExecArgs :: ExecArgs -> IO ()
runExecArgs ExecArgs {..} = do
initialAttributes <- makeInitialAttributes execArgsSubprocess execArgsAttributes
Expand Down
8 changes: 4 additions & 4 deletions src/HotelCalifornia/Tracing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import UnliftIO
-- up the provider afterwards.
--
-- This also sets up an empty context (creating a new trace ID).
withGlobalTracing :: MonadUnliftIO m => m a -> m a
withGlobalTracing :: MonadUnliftIO m => (Maybe Honeycomb.HoneycombTarget -> m a) -> m a
withGlobalTracing act = do
void $ attachContext Context.empty
liftIO setParentSpanFromEnvironment
bracket (liftIO initializeGlobalTracerProvider) shutdownTracerProvider $ \_ -> do
-- note: this is not in a span since we don't have a root span yet so it
-- would not wind up in the trace in a helpful way anyway
void $
mTarget <-
Honeycomb.getOrInitializeHoneycombTargetInContext initializationTimeout
`catch` \(e :: SomeException) -> do
-- we are too early in initialization to be able to use a normal logger,
Expand All @@ -47,9 +47,9 @@ withGlobalTracing act = do
liftIO . BS8.hPutStrLn stderr $ "error setting up Honeycomb trace links: " <> (BS8.pack $ displayException e)
pure Nothing

act
act mTarget
where
initializationTimeout = secondsToNominalDiffTime 3
initializationTimeout = secondsToNominalDiffTime 1

globalTracer :: MonadIO m => m Tracer
globalTracer = getGlobalTracerProvider >>= \tp -> pure $ makeTracer tp "hotel-california" tracerOptions
Expand Down

0 comments on commit 22c1897

Please sign in to comment.