Skip to content

Instantly share code, notes, and snippets.

@samkahchiin
Created August 25, 2022 09:06
Show Gist options
  • Save samkahchiin/8b4a27351be730eabc04d2ff5942d4ef to your computer and use it in GitHub Desktop.
Save samkahchiin/8b4a27351be730eabc04d2ff5942d4ef to your computer and use it in GitHub Desktop.
unless Rails.env.test?
# SAMPLING_RATE = 0.10
OpenTelemetry::SDK.configure do |c|
c.service_name = ENV.fetch('CLUSTER_NAME', "project-#{Rails.env}")
c.id_generator = OpenTelemetry::Propagator::XRay::IDGenerator
# The X-Ray Propagator injects the X-Ray Tracing Header into downstream calls
c.propagators = [OpenTelemetry::Propagator::XRay::TextMapPropagator.new]
# we want calls that go into the AWS SDK to be terminal requests without tracing underlying
# HTTP calls and other things which would make the trace noise-y.
c.use 'OpenTelemetry::Instrumentation::AwsSdk', {
suppress_internal_instrumentation: true,
}
c.use 'OpenTelemetry::Instrumentation::Rails'
c.use 'OpenTelemetry::Instrumentation::Rack'
c.use 'OpenTelemetry::Instrumentation::ActionPack'
c.use 'OpenTelemetry::Instrumentation::ActiveSupport'
c.use 'OpenTelemetry::Instrumentation::ActionView'
c.use 'OpenTelemetry::Instrumentation::ActiveRecord'
c.use 'OpenTelemetry::Instrumentation::Faraday'
c.use 'OpenTelemetry::Instrumentation::PG'
c.use 'OpenTelemetry::Instrumentation::Redis'
c.use 'OpenTelemetry::Instrumentation::Sidekiq'
c.use 'OpenTelemetry::Instrumentation::Net::HTTP'
# c.add_span_processor(
# OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
# # Arguments for exporter:
# # https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md
# OpenTelemetry::Exporter::OTLP::Exporter.new,
# ),
# )
# Alternatively, we could just enable all instrumentation:
# c.use_all({ 'OpenTelemetry::Instrumentation::ActiveRecord' => { enabled: false } })
end
# OpenTelemetry.tracer_provider.sampler = OpenTelemetry::SDK::Trace::Samplers.parent_based(root: OpenTelemetry::SDK::Trace::Samplers.trace_id_ratio_based(SAMPLING_RATE))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment