csharp-netcore
csharp-netcore copied to clipboard
Using PerOperationSampler
Hello
I am just learning OpenTracing and Jaeger, so first of all, forgive me if the question is stupid. Also, I have tried to find this issue but haven't found it
I am trying to use PerOperationSampler, because there are some operations that usually I don't want to be sampled, but others are critical and want sampled.
So at first I instantiate a PerOperationSampler, with a OperationSamplingParameters with a DefaultProbability (1.0d) and a collection of PerOperationSamplingParameters. One of them I assigned probability 0.0d. For the operation I use [Controller]/[Action]. That is what had some sense to me.
I run it, and I see that the operation is being traced. Then I delve into your code, and I believe I know the reason.
The outmost span the one that is being generated by HostingEventProvider. And the operationName isn't Controller/Action, but "HTTP GET" or "HTTP POST".
There is an inner span generated by MvcEventProcessor, that has the information that I want. its operation names are Controller/Action. But the filtering is done at the outer spans.
I see the reason in generating outer spans such as you are doing, but I believe that renders the PerOperationSampler quite useless, unless I want to filter all HTTP GETs.
Is there a solution for that? That is: Filtering per Controller/Action
Indeed, stupid me.
Paying more attention, I saw that the operationName for an action is **Action** [controller]/[Action]. Putting that, I can assign the probability well enough.
The only annoying thing is that the httpIn "HTTP POST" span will appear. But it's ok
I'm having the same issue - I can filter on HTTP POST or HTTP GET, but if I put e.g "Action MySampleApp.Controllers.ValuesController/POST" nothing is filtered.
My setup looks like this:
new PerOperationSampler(100000, new OperationSamplingParameters(1d, -1, new List<PerOperationSamplingParameters> { new PerOperationSamplingParameters("Action MySampleApp.Controllers.ValuesController/POST", new ProbabilisticSamplingStrategy(0)) }), sp.GetRequiredService<ILoggerFactory>());
You could move the sampling to this library by ignoring requests based on an algorithm. Starting with v0.7.0 this libary does no longer create any child spans (EF Core, SQL, HTTP) if the request itself is ignored, so this should give you what you want.
builder.ConfigureAspNetCore(options =>
{
options.Hosting.IgnorePatterns.Add(ctx =>
{
// Ignore 90% of requests = Sampling of 10%
var newRandom = random.Next(100);
return newRandom >= 10;
});
});