MyNixOS website logo
Description

GHC plugin for open telemetry.

This package provides a GHC plugin that exports each module's build times to an open telemetry collector. See the included README below for more details.

opentelemetry-plugin - a GHC plugin for open telemetry

This GHC plugin lets you export granular open telemetry metrics for your Haskell builds. Specifically, this creates a trace with:

  • One span for each module build
  • One sub-span for each phase of each module build

Example trace generated by this GHC plugin

Note that due to limitations of GHC's Plugin interface the root span generated by this plugin will have a duration of 0 (by default) and will not be the correct duration (for the entire build). However, the Plugin will reuse any surrounding span inherited via the standard TRACEPARENT and TRACESTATE environment variables, so if you wrap your build in something like the hotel executable (from the hotel-california package) then you will get the correct duration for the outermost span.

This plugin also supports the standard BAGGAGE environment variable, too.

To use this plugin:

  • add the opentelemetry-plugin package as a build dependency of your package

  • add ghc-options: -plugin-package opentelemetry-plugin -fplugin OpenTelemetry.Plugin to your package

  • configure the appropriate open telemetry environment variables

    In other words, you'll probably want to set at least OTEL_EXPORTER_OTLP_ENDPOINT and maybe other environment variables depending on your open telemetry backend. For example, if you're using Honeycomb then you'd also want to set OTEL_EXPORTER_OTLP_HEADERS and OTEL_SERVICE_NAME.

Then any time you build your project the build will export open telemetry metrics. The overhead of metrics export is negligible.

Development

This repository uses Nix for development. You can build this package entirely using Nix for a specific version of ghc by running:

$ nix develop .#ghc${MAJOR}${MINOR}

… replacing ${MAJOR} and ${MINOR} with the major and minor version of the ghc that you're using. For example, if you're using GHC 9.4, then you'd run:

$ nix build .#ghc94

If you want to develop interactively using Cabal inside of a Nix shell, run:

$ nix develop .#ghc${MAJOR}${MINOR}

Once you are inside that Nix shell, then you can use cabal commands, like cabal build or cabal repl. You can also use ghcid or launch your favorite IDE from inside this shell.

Metadata

Version

1.1.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows