Created
November 20, 2021 03:02
-
-
Save stevenharman/68bd8fa0f9d1e367f49fcb4c5b485316 to your computer and use it in GitHub Desktop.
A minimally functional OpenTelemetry setup to send traces to Honeycomb. This leaves a lot to be desired, but is a starting point.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Observability | |
gem "opentelemetry-sdk" | |
gem "opentelemetry-exporter-otlp" | |
gem "opentelemetry-instrumentation-all" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OpenTelemetry::SDK.configure do |c| | |
c.service_name = "PlaneExpress-Fullfillment" | |
c.service_version = ENV.fetch("HEROKU_RELEASE_VERSION", "v0-dev") | |
api_key = ENV.fetch("HONEYCOMB_API_KEY", nil) | |
if api_key.present? | |
oltp_exporter = OpenTelemetry::Exporter::OTLP::Exporter.new( | |
endpoint: "https://api.honeycomb.io:443/v1/traces", | |
headers: { | |
"x-honeycomb-team" => api_key, | |
"x-honeycomb-dataset" => "planetexpress - production" | |
}, | |
compression: "gzip" | |
) | |
batch_processor = OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(oltp_exporter) | |
c.add_span_processor(batch_processor) | |
end | |
env = ENV.fetch("RACK_ENV") | |
if env == "development" | |
console_exporter = OpenTelemetry::SDK::Trace::Export::ConsoleSpanExporter.new | |
c.add_span_processor(OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(console_exporter)) | |
elsif env == "test" | |
in_memory_exporter = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new(recording: false) | |
c.add_span_processor(OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(in_memory_exporter)) | |
end | |
c.use_all # enables all instrumentation, watch out! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment