opentelemetry
Version, currently 0.3.58 versions
github.com/jgaskins/opentelemetry
OpenTelemetry SDK and exporters for the Crystal language
17 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
opentelemetry:
github: jgaskins/opentelemetry
version: ~> 0.3.5Then run:
shards installshard.yml
- Crystal
1.0.0- License
- MIT
- Author
- Jamie Gaskins <jgaskins@hey.com>
- Target
example_appfrom examples/app.cr
Dependencies
Runtime Dependencies
Development Dependencies
README
# OpenTelemetry
[OpenTelemetry](https://opentelemetry.io) is an observability framework for cloud-native software.
This Crystal shard allows you to add it to your applications to export application telemetry to OpenTelemetry-compatible services, such as:
- [Honeycomb](https://honeycomb.io)
- [Datadog](https://www.datadoghq.com)
- [Prometheus](https://prometheus.io)
- [New Relic](https://newrelic.com/)
- [Lightstep](https://lightstep.com)
You can see more at the OpenTelemetry website.
## Installation
1. Add the dependency to your `shard.yml`:
```
dependencies:
opentelemetry:
github: jgaskins/opentelemetry
```
2. Run `shards install`
## Usage
To use this shard, you'll need to have a service setup to receive OpenTelemetry data. In this example, we'll use Honeycomb:
```crystal
require "opentelemetry"
OpenTelemetry.configure do |c|
c.exporter = OpenTelemetry::BatchExporter.new(
OpenTelemetry::HTTPExporter.new(
endpoint: URI.parse("https://api.honeycomb.io"),
headers: HTTP::Headers{
# Get your Honeycomb API key from https://ui.honeycomb.io/account
"x-honeycomb-team" => ENV["HONEYCOMB_API_KEY"],
# Name this whatever you like. Honeycomb will create the dataset when it
# begins reporting data in Honeycomb Classic accounts
"x-honeycomb-dataset" => ENV["HONEYCOMB_DATASET"],
},
)
)
end
```
Note: The shard supports using `OTEL_SERVICE_NAME` and `OTEL_RESOURCE_ATTRIBUTES` environment variables to populate the trace's associated resource (dataset in the Honeycomb example above).
### Instrumenting
Use the `OpenTelemetry.trace` method to create a new trace for the current fiber or to add a span inside the current trace.
```crystal
OpenTelemetry.trace "outer-span" do |span|
span["my-attribute"] = "my value"
# do some work
OpenTelemetry.trace "inner-span" do |span|
span["another-attribute"] = "another value"
# do some work
end
# do some work
end
```
### `HTTP::Server` middleware
If you are instrumenting a Crystal web app, you will want to add a `OpenTelemetry::Middleware` instance to your server middleware stack, passing in the name of the root span.
```crystal
http = HTTP::Server.new([
# ...
OpenTelemetry::Middleware.new("http.server.request"),
# ...
])
```
### Integrations
You enable many integrations simply by requiring them. They will be instrumented automatically.
```crystal
# Load the integration for the crystal-lang/crystal-db shard
require "opentelemetry/integrations/db"
```
You can see all of the integrations available in [the integrations directory](https://github.com/jgaskins/opentelemetry/tree/main/src/integrations).
## Contributing
1. Fork it (<https://github.com/jgaskins/opentelemetry/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [Jamie Gaskins](https://github.com/jgaskins) - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.3.5- Tagged
- Jan 27, 2025
- Commit
d47d21314a33- Crystal
1.0.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/jgaskins/opentelemetry
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 13, 2026
- Synced
- Aug 13, 2026
- Versions
- 8