You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{SamplingDecision,TraceIdRatioBasedSampler}from'@opentelemetry/sdk-trace-node';import{ATTR_HTTP_REQUEST_METHOD,ATTR_HTTP_ROUTE}from'@opentelemetry/semantic-conventions';import{HTTP_METHOD_BLACKLIST,HTTP_ROUTE_BLACKLIST}from'../conventions/conventions.js';importtype{Attributes,AttributeValue,Context,Link,SpanKind}from'@opentelemetry/api';importtype{Sampler,SamplingResult}from'@opentelemetry/sdk-trace-node';classCustomSamplerextendsTraceIdRatioBasedSamplerimplementsSampler{publicreadonlyexcludeHttpMethods=HTTP_METHOD_BLACKLIST;publicreadonlyexcludeHttpRoutes=HTTP_ROUTE_BLACKLIST;// @ts-expect-error -- this is obvious with TS ! We can do it for sure// eslint-disable-next-line max-paramspublicoverrideshouldSample(context: Context,traceId: string,_spanName: string,_spanKind: SpanKind,attributes: Attributes,_links: Array<Link>,): SamplingResult{constradioSampleDecision: SamplingResult=super.shouldSample(context,traceId);if(radioSampleDecision.decision===SamplingDecision.NOT_RECORD){returnradioSampleDecision;}constmaybeSpanHttpMethod: AttributeValue|undefined=attributes['http.method']??attributes[ATTR_HTTP_REQUEST_METHOD];constmaybeSpanHttpRoute: AttributeValue|undefined=attributes['http.route']??attributes[ATTR_HTTP_ROUTE];constnormalizedHttpMethod=maybeSpanHttpMethod?.toString().toUpperCase()??'GET';constnormalizedHttpRoute=maybeSpanHttpRoute?.toString().toLowerCase()??'/';if(this.excludeHttpMethods.includes(normalizedHttpMethod)){return{
...radioSampleDecision,decision: SamplingDecision.NOT_RECORD,};}if(this.excludeHttpRoutes.includes(normalizedHttpRoute)){return{
...radioSampleDecision,decision: SamplingDecision.NOT_RECORD,};}returnradioSampleDecision;}}export{CustomSampler};
My sampler is triggered, and my decision are returned, but SamplingDecision.NOT_RECORD is not doing anything, span are still sent on my collector
What did i missed ?
The text was updated successfully, but these errors were encountered:
blephy
changed the title
How to properly sample a span
How to properly filter span by sampling
Jan 6, 2025
I have an API that has 3 endpoints on which I would not like to send any span to my collector.
I have designed a custom SpanSampler to filter them, but this is not working as expected.
Could you please help me to review my implementation ?
My sampler is triggered, and my decision are returned, but
SamplingDecision.NOT_RECORD
is not doing anything, span are still sent on my collectorWhat did i missed ?
The text was updated successfully, but these errors were encountered: