FsOpenTelemetry
FsOpenTelemetry is a single file you can copy paste or add through Paket Github dependencies to provide your F# library with safe helpers for Activity and ActivitySource.
Install / Use
/learn @TheAngryByrd/FsOpenTelemetryREADME
FsOpenTelemetry
What is this?
FsOpenTelemetry is a single file you can copy paste or add through Paket Github dependencies to provide your F# library with safe helpers for Activity and ActivitySource.
Why does this exist?
One of the best practices from the Microsoft Distributed Tracing documentation states to use the ?. since "activity returned by ActivitySource.StartActivity may be null". Since F# does not have this operator you have to put if activity <> null then doThing everywhere. This uses extensions methods on an existing Activity so calls are straight forward without doing the null checks.
This additionally adds several additional helpers such as RecordException, Adding many of the semantic conventions as constants, and automatically creating Activity with Source Code attributes filled out.
How do I get started?
1. Put the file into your project
Option 1
Copy/paste FsOpenTelemetry.fs into your library.
Option 2
Read over Paket Github dependencies.
Add the following line to your paket.depedencies file.
github TheAngryByrd/FsOpenTelemetry src/FsOpenTelemetry/FsOpenTelemetry.fs
Then add the following line to projects with paket.references file you want FsOpenTelemetry to be available to.
File: FsOpenTelemetry.fs
2. Replace its namespace with yours
To alleviate potential naming conflicts, it's best to replace FsOpenTelemetry namespace with your own.
Here is an example with FAKE 5:
Target.create "Replace" <| fun _ ->
Shell.replaceInFiles
[ "FsOpenTelemetry", "MyLib.DistributedTracing" ]
(!! "paket-files/TheAngryByrd/FsOpenTelemetry/src/FsOpenTelemetry/FsOpenTelemetry.fs")
Builds
Developing
Make sure the following requirements are installed on your system:
- dotnet SDK 3.0 or higher
- Mono if you're on Linux or macOS.
or
Environment Variables
CONFIGURATIONwill set the configuration of the dotnet commands. If not set, it will default to Release.CONFIGURATION=Debug ./build.shwill result in-cadditions to commands such as indotnet build -c Debug
GITHUB_TOKENwill be used to upload release notes and Nuget packages to GitHub.- Be sure to set this before releasing
DISABLE_COVERAGEWill disable running code coverage metrics. AltCover can have severe performance degradation so it's worth disabling when looking to do a quicker feedback loop.DISABLE_COVERAGE=1 ./build.sh
Building
> build.cmd <optional buildtarget> // on windows
$ ./build.sh <optional buildtarget>// on unix
The bin of your library should look similar to:
$ tree src/MyCoolNewLib/bin/
src/MyCoolNewLib/bin/
└── Debug
└── net50
├── MyCoolNewLib.deps.json
├── MyCoolNewLib.dll
├── MyCoolNewLib.pdb
└── MyCoolNewLib.xml
Build Targets
Clean- Cleans artifact and temp directories.DotnetRestore- Runs dotnet restore on the solution file.DotnetBuild- Runs dotnet build on the solution file.DotnetTest- Runs dotnet test on the solution file.GenerateCoverageReport- Code coverage is run duringDotnetTestand this generates a report via ReportGenerator.WatchTests- Runs dotnet watch with the test projects. Useful for rapid feedback loops.GenerateAssemblyInfo- Generates AssemblyInfo for libraries.DotnetPack- Runs dotnet pack. This includes running Source Link.SourceLinkTest- Runs a Source Link test tool to verify Source Links were properly generated.PublishToNuGet- Publishes the NuGet packages generated inDotnetPackto NuGet via paket push.GitRelease- Creates a commit message with the Release Notes and a git tag via the version in theRelease Notes.GitHubRelease- Publishes a GitHub Release with the Release Notes and any NuGet packages.FormatCode- Runs Fantomas on the solution file.BuildDocs- Generates Documentation fromdocsSrcand the XML Documentation Comments from your libraries insrc.WatchDocs- Generates documentation and starts a webserver locally. It will rebuild and hot reload if it detects any changes made todocsSrcfiles, libraries insrc, or thedocsToolitself.ReleaseDocs- Will stage, commit, and push docs generated in theBuildDocstarget.Release- Task that runs all release type tasks such asPublishToNuGet,GitRelease,ReleaseDocs, andGitHubRelease. Make sure to read Releasing to setup your environment correctly for releases.
Releasing
git add .
git commit -m "Scaffold"
git remote add origin https://github.com/user/MyCoolNewLib.git
git push -u origin master
-
paket config add-token "https://www.nuget.org" 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a- or set the environment variable
NUGET_TOKENto your key
- or set the environment variable
-
- You can then set the environment variable
GITHUB_TOKENto upload release notes and artifacts to github - Otherwise it will fallback to username/password
- You can then set the environment variable
-
Then update the
CHANGELOG.mdwith an "Unreleased" section containing release notes for this version, in KeepAChangelog format.
NOTE: Its highly recommend to add a link to the Pull Request next to the release note that it affects. The reason for this is when the RELEASE target is run, it will add these new notes into the body of git commit. GitHub will notice the links and will update the Pull Request with what commit referenced it saying "added a commit that referenced this pull request". Since the build script automates the commit message, it will say "Bump Version to x.y.z". The benefit of this is when users goto a Pull Request, it will be clear when and which version those code changes released. Also when reading the CHANGELOG, if someone is curious about how or why those changes were made, they can easily discover the work and discussions.
Here's an example of adding an "Unreleased" section to a CHANGELOG.md with a 0.1.0 section already released.
## [Unreleased]
### Added
- Does cool stuff!
### Fixed
- Fixes that silly oversight
## [0.1.0] - 2017-03-17
First release
### Added
- This release already has lots of features
[Unreleased]: https://github.com/user/MyCoolNewLib.git/compare/v0.1.0...HEAD
[0.1.0]: https://github.com/user/MyCoolNewLib.git/releases/tag/v0.1.0
- You can then use the
Releasetarget, specifying the version number either in theRELEASE_VERSIONenvironment variable, or else as a parameter after the target name. This will:- update
CHANGELOG.md, moving changes from the `Unrel
- update
Related Skills
node-connect
345.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
