ApplicationInsights-Java icon indicating copy to clipboard operation
ApplicationInsights-Java copied to clipboard

Question: Sampling overrides

Open xsmrcek opened this issue 1 year ago • 2 comments

Sorry I didn;t find any another way to ask: I am migration to agent v 3.4.0 and I have two questions: In logs from agent/application start I saw this: "ignoreRemoteParentNotSampled" has been deprecated and "ignoreRemoteParentNotSampled": false has replaced with "preview": { "sampling": { "parentBased": true } } (while "ignoreRemoteParentNotSampled": true is just the default behavior) So it means, to have the same functionality (agent won't sample requests from upstream if receive samled flag '00', and it have bigger priority than sampling percentage value), I just add "preview": { "sampling": { "parentBased": true } } and ti will work. I did read somewhere that you can override sampling based on headers now, but I dind;t find any documetation for it. My example situation: tracestate header with value a -> sample tracestate header with value b -> drop/do not sample missing tracestate header or tracestate header with dirrent value -> sample It is possible to achieve this? I would replace parent based sampling by this. And it is possible to combine it with another overrides like do not sample any request with given url (I have this one for heath checks - from your documentation). btw it is possible to add tracestate if it is missing?

xsmrcek avatar Sep 21 '22 13:09 xsmrcek

I didn't find any another way to ask

this is a great place to ask!

I just add "preview": { "sampling": { "parentBased": true } } and it will work

yes, this is correct

did you need some other behavior than using parentBased, or is parentBased not working for you?

trask avatar Sep 22 '22 00:09 trask

Hi @trask ! Thank you for answer!

'parentBased' is working for me. I just read somewhere that we can use headers :) We are using tracestate header in our project for sampling. tracestate A -> sample tracestate B -> do not sample tracestate C / missing tracestate -> sample

So my question is if this behaviour is possible? :) And second one, if it is possible to add missing tracestate to actual request if there is no header on the request. Thank you! (I did ask the same question in past, and it wasn't possible, that's why I am using parentBased. But I just read somwehre that it may be possible with newest versions)

xsmrcek avatar Sep 22 '22 13:09 xsmrcek

hey @xsmrcek, have you tried a combination of capturing the http header as a span attribute https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-config#http-headers, e.g.

{
  "preview": {
    "captureHttpServerHeaders": {
      "requestHeaders": [
        "myheader"
      ]
    }
  }
}

the resulting span attributes follow OpenTelemetry spec: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers

and then using sampling overrides https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-sampling-overrides, e.g.

{
  "connectionString": "...",
  "sampling": {
    "percentage": 10
  },
  "preview": {
    "sampling": {
      "overrides": [
        {
          "telemetryType": "request",
          "attributes": [
            {
              "key": "http.request.header.myheader",
              "value": "myregex",
              "matchType": "regexp"
            }
          ],
          "percentage": 0
        }
      ]
    }
  }
}

trask avatar Nov 05 '22 22:11 trask