iand675 / hs-opentelemetry

OpenTelemetry support for the Haskell programming language
https://iankduncan.com/projects/opentelemetry
BSD 3-Clause "New" or "Revised" License
68 stars 33 forks source link

Figure out how to get library versions without hardcoding them #2

Open iand675 opened 2 years ago

hw202207 commented 2 years ago

One option is to get from generated Paths_ module.

import Paths_${package_name} (version)

It has type Version

iand675 commented 2 years ago

Unfortunately that only works if the package explicitly exports it.

freizl commented 2 years ago

Unfortunately that only works if the package explicitly exports it.

Curious what's the problem with this?

Looks like we could leave in other-module and it wont be public (haddock document)? e.g. https://github.com/tekul/jose-jwt/blob/master/jose-jwt.cabal#L47

hw202207 commented 2 years ago

~nvm. it doesn't work unless there is {-# OPTIONS_HADDOCK prune #-} in the module.~

Didn't know what I did wrong but looks like using other-module can hide the module from public. e.g.

So wonder if there are other reasons you'd like to avoid explicitly exports it?

iand675 commented 1 year ago

I think maybe the aim of this wasn't explained well enough when I created this issue.

The goal is this:

For libraries that we write instrumentation for (Yesod, persistent, etc.), it would be nice to know what version of things like yesod-core that we are running against when debugging an issue in production. As far as I can tell, those libraries would have to be altered to export their Paths_ module so that we would have access to that information. In the long-term, it would be really nice to have the hs-opentelemetry suite of packages become stable enough and trusted enough that these libraries feel comfortable integrating directly or making changes to make us happy, but in the meantime it's a little challenging to get at this information.

hw202207 commented 1 year ago

Aha.. I see what's meaning now. Thanks!

I learned there is cabal command to list all installed packages. Not sure if it could be short term hacky solution.

mmhat commented 1 year ago

You can simply use something like this:

{-# LANGUAGE CPP #-}

yesodVersionString :: String
yesodVersionString = VERSION_yesod