New Relic Inc.

05/24/2022 | News release | Distributed by Public on 05/24/2022 11:08

Introducing OpenTelemetry observability for Crystal

Crystal is an object-oriented programming language with a syntax that is heavily influenced by Ruby and includes a sprinkling of influence from Go and other languages. Enterprise companies are running core systems on Crystal and offering products implemented with Crystal, but Crystal hasn't received much attention from existing observability platforms. However, you need observability to help find and fix errors and performance issues in your production systems-and that includes systems using Crystal. In this piece, you'll learn how to instrument Crystal applications with New Relic and Open Telemetry.

There are a lot of moving parts in OpenTelemetry. The basics are fairly simple, but the full spectrum of features and capabilities is deeply complex. I started working on an OpenTelemetry framework for Crystal late in September 2021. There is a lot left to do, but the project as a whole is ready for others to start using it.

So how does one implement OpenTelemetry-based observability in your Crystal software, and what capabilities does that give you?

The first approach to instrumenting your Crystal code is to leverage the OpenTelemetry API to manually add instrumentation where you need it. To use OpenTelemetry, you need a place to send your data, and this example is written to send data to New Relic. If you don't have a New Relic account, take a minute and sign up. A free account includes 100 GB of ingest per month, one full platform user, and unlimited basic users.

Let's look at an example. Consider a basic service, built with just the Crystal standard library, that responds to HTTP GET requests by calculating the nth Fibonacci number. The code in this example isn't the most concise way to do it in Crystal, but it's structured so that it could potentially be expanded into a larger, more complex service. Here's the full code for this basic, uninstrumented application on GitHub. And here is the code for the instrumented version of the application that I'll discuss later in this post.

Here's the code in :