Replies: 1 comment 6 replies
-
I'm seeing the same problem. I'm unable to use a custom sampler. This is the code used. It aims to do the same as the Node.js snippet I pasted below it. # config/initializers/instrumentation.rb
require 'opentelemetry/sdk'
require 'opentelemetry/instrumentation/all'
class ChecklySampler
def initialize
puts("initializing ChecklySampler")
end
def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
puts("using ChecklySampler")
tracestate = OpenTelemetry::Trace.current_span(parent_context).context.tracestate
decision = tracestate.get('checkly') ? OpenTelemetry::SDK::Trace::Samplers::Decision::RECORD_AND_SAMPLE :
OpenTelemetry::SDK::Trace::Samplers::Decision::DROP
OpenTelemetry::SDK::Trace::Samplers::Result.new(decision: decision, attributes: {}, tracestate: tracestate)
end
def description
'ChecklySampler'
end
end
checkly_sampler = ChecklySampler.new
tracer_provider = OpenTelemetry::SDK::Trace::TracerProvider.new(sampler: checkly_sampler)
OpenTelemetry.tracer_provider = tracer_provider
OpenTelemetry::SDK.configure do |c|
c.service_name = 'dice'
c.use_all()
end Similar sampler but in Node.js that works fine. const { NodeSDK } = require('@opentelemetry/sdk-node')
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-proto')
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node')
const { BatchSpanProcessor, SamplingDecision } = require('@opentelemetry/sdk-trace-base')
const { trace } = require('@opentelemetry/api')
const exporter = new OTLPTraceExporter({
timeoutMillis: 2000,
})
const sdk = new NodeSDK({
instrumentations: [getNodeAutoInstrumentations()],
spanProcessors: new BatchSpanProcessor(exporter),
sampler: {
shouldSample: (context, traceId, spanName, spanKind, attributes, links) => {
const isChecklySpan = trace.getSpan(context)?.spanContext()?.traceState?.get('checkly')
if (isChecklySpan) {
return { decision: SamplingDecision.RECORD_AND_SAMPLED }
} else {
return { decision: SamplingDecision.NOT_RECORD }
}
},
},
}) |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
**I'm currently in the process of setting up the Otel SDK for our Ruby application. As part of this instrumentation, I've decided to use a custom sampler called
TraceIdRatioBasedSampler
. However, I'm encountering an issue where it appears that the sampler isn’t being applied correctly.Has anyone else faced a similar issue or can suggest potential reasons why it's not working as expected? Any help or insights would be greatly appreciated!**
Below is the sample code.
Beta Was this translation helpful? Give feedback.
All reactions