This package provides both the base functionality needed to build instrumentation for arbitrary classes/libraries, but also ready-made instrumentation for commonly used Crystal libraries.
-
Add the dependency to your
shard.yml
:dependencies: opentelemetry-instrumentation: github: wyhaines/opentelemetry-instrumentation.cr
-
Run
shards install
require "opentelemetry-instrumentation.cr"
Requiring the top level library will attempt to instrument, via a macro finished
block, every component within your project for which there exists instrumentation. Each instrumentation package attempts to determine whether it is safe to install before doing so, by validating that required components are installed, and that their versions are compatible.
The reason for running the autoinstrumentation within a finished
block is to ensure that all other classes have been loaded prior to loading the instrumentation. However, the structure of some softare and frameworks (such as https://luckyframework.org/) prevent this from working properly. If it appears that instrumentation has not been installed, you can check what instruments have been installed by examining the data returned from OpenTelemetry::Instrumentation::Registry.instruments
. It may look like this:
[OpenTelemetry::Instrumentation::CrystalDB,
OpenTelemetry::Instrumentation::CrystalHttpServer,
OpenTelemetry::Instrumentation::CrystalLog]
If the array is empty, then no instrumentation was installed. You can require instrumentation manually by requiring the relevant file. For instance, to manually install the DB instrumentation (assuming that DB has been previously required):
require "opentelemetry-instrumentation/src/instrumentation/crystal/db"
The generated docs can all be found here:
https://wyhaines.github.io/opentelemetry-instrumentation.cr/
- Fork it (https://github.com/wyhaines/opentelemetry-instrumentation.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Kirk Haines - creator and maintainer