This library provides the base functionality for implementing services that utilize OpenTelemetry to send or receive metrics, traces, and logs. This library is intended to be focused specifically on OpenTelemetry itself, with most higher level functionality implemented by other libraries which use this library.
As a general rule, naming conventions have been based on the standard glossary of OpenTelementry terms, as found at https://opentelemetry.io/docs/concepts/glossary/
The general architecture of the implementation is guided by this document:
The TL;DR is that a TraceProvider
is used to create a Tracer
. A Span
is created inside of the context of a Tracer
, and one Span
may nest inside of another.
https://wyhaines.github.io/opentelemetry-api.cr/
-
Add the dependency to your
shard.yml
:dependencies: otel: github: wyhaines/opentelemetry-api.cr
-
Run
shards install
require "opentelemetry-api"
OpenTelemetry.configure do |config|
config.service_name = "my_app_or_library"
config.service_version = "1.1.1"
config.exporter = OpenTelemetry::IOExporter.new(:STDOUT)
end
tracer = OpenTelemetry.tracer_provider("my_app_or_library", "1.1.1")
tracer = OpenTelemetry.tracer_provider do |tracer|
tracer.service_name = "my_app_or_library"
tracer.service_version = "1.1.1"
end
provider_a = OpenTelemetry::TracerProvider.new("my_app_or_library", "1.1.1")
provider_a.exporter = OpenTelemetry::IOExporter.new(:STDOUT)
provider_b = OpenTelementry::TracerProvider.new do |config|
config.service_name = "my_app_or_library"
config.service_version = "1.1.1"
config.exporter = OpenTelemetry::IOExporter.new(:STDOUT)
end
tracer = provider_a.tracer # Inherit all configuration from the Provider Object
tracer = provider_a.tracer("microservice foo", "1.2.3") # Override the configuration
tracer = provider_a.tracer do |tracer|
tracer.service_name = "microservice foo"
tracer.service_version = "1.2.3"
end
tracer.in_span("request") do |span|
span.set_attribute("verb", "GET")
span.set_attribute("url", "http://example.com/foo")
span.add_event("dispatching to handler")
tracer.in_span("handler") do |child_span|
child_span.add_event("handling request")
tracer.in_span("db") do |child_span|
child_span.add_event("querying database")
end
end
end
TODO: Write development instructions here
- Fork it (https://github.com/your-github-user/otel/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