What are the best practices when configuring the SDK to be optional in Rails? #1605
-
Hello. I am configuring the SDK for a Rails application. I would like to only enable instrumentation when an environment variable I have a configuration file in require "opentelemetry/sdk"
require "opentelemetry/instrumentation/all"
require "opentelemetry-exporter-otlp"
Rails.application.configure do
otel_enabled = ENV.fetch("OTEL_INSTRUMENTATION_ENABLED", false)
OpenTelemetry::SDK.configure do |c|
if otel_enabled
Rails.logger.info("Configuring OpenTelemetry SDK")
c.service_name = "MY_APP"
c.use_all
end
# Traces will automatically be sent to endpoint specified
# in the OTEL_EXPORTER_OTLP_ENDPOINT environment variable
end
if otel_enabled
MyAppTracer = OpenTelemetry.tracer_provider.tracer("MY_APP_TRACER")
end
end This should prevent automatic instrumentation, but do I need additional checks when adding manual instrumentation? For example, in one of my job's functions, I have def perform(_, arg_array)
MyAppTracer.in_span("do_work") do |span|
span.set_attribute("my_app.queue_name", "awesome_queue")
# Additional business logic code here ...
end
end Do I need to wrap each call to Thank you for any insight on this and please let me know if I can clarify anything further. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thank you for using OTel Ruby! Per the specification there is an environment variable that all OTel SDKs must support, which is
It is however not currently implemented by the Ruby SDK: #1388 Would you be interested in helping us implement this? That would help us become compliant with the latest version of the specification and allow you to disable the SDK entirely without installing any of the instrumentations. You may also simulate this behavior in your code by skipping the configure block all together when that envar is set: Rails.application.configure do
if ENV.fetch("OTEL_SDK_DISABLED", "false") == "false"
OpenTelemetry::SDK.configure do |c|
c.service_name = "MY_APP"
c.use_all
end
end
# This returns a No-Op tracer
MyAppTracer = OpenTelemetry.tracer_provider.tracer("MY_APP_TRACER")
end |
Beta Was this translation helpful? Give feedback.
Thank you for using OTel Ruby!
Per the specification there is an environment variable that all OTel SDKs must support, which is
OTEL_SDK_DISABLED
:https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration
It is however not currently implemented by the Ruby SDK: #1388
Would you be interested in helping u…