opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

Custom Sampler with TraceIdRatioBasedSampler per spanname

Open zxcian opened this issue 3 years ago • 1 comments
trafficstars

  • [ /] This only affects the JavaScript OpenTelemetry library
  • [ /] This may affect other libraries, but I would like to get opinions here first

Is there anyway that you could give certain sampling rate per span name? I was hoping to find something similar with what sentry

I currently have a custom sampler which excludes certain urls from getting trace, and I want to know if it's possible to also have custom sampling per span name. my shouldSample code is as follows


  shouldSample(
    context: Context,
    traceId: String,
    spanName: String,
    spanKind: SpanKind,
    attributes: SpanAttributes,
    links: Link[],
  ): SamplingResult {
    let res = {}
    if (attributes['url'] === 'url1') {
      res = {
        decision: SamplingDecision.NOT_RECORD,
      };
    }
if(spanName === 'sample') {
// dont know what to do here / how to invoke TraceIdRatiobasedSampler

}
    return result;

zxcian avatar Aug 26 '22 13:08 zxcian

You can create your own TraceIdRatioBasedSampler in your sampler and delegate the shouldSample request to that sampler if needed. See also ParentBasedSampler, which delegates all shouldSample requests to the designated sampler if the sampling decision is not made yet.

legendecas avatar Aug 29 '22 07:08 legendecas

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] avatar Nov 07 '22 06:11 github-actions[bot]

This issue was closed because it has been stale for 14 days with no activity.

github-actions[bot] avatar Nov 28 '22 06:11 github-actions[bot]