I'm using sampling overrides (java sdk) to apply sampling on different telemetry types. I'd like to know if I can use different default percentages for different telemetry types, along with their own overrides. A use case for me is:
.audit
. Audit logs should be logged 100% of timeHere is a pseudo-config I'm thinking:
{
"preview": {
"sampling": {
"percentage": 100 => overall sampling percentage (100)
"overrides": [
{
"telemetryType": "trace",
"percentage": 10, => overall sampling percentage for traces. This should override the default set at parent (100)
"overrides": [
{
"percentage": 100, => override the default sampling for traces (10%)
"attributes": [
<match with entries that contain `.audit` in the trace message> => is this even possible? the trace message body is not part of attributes. Even if it was in the attributes, can we achieve this?
]
}
]
},
{
"telemetryType": "request",
"attributes": [
{
"key": "http.target",
"value": "/actuator/health",
"matchType": "strict"
}
],
"percentage": 0
},
{
"telemetryType": "dependency",
"percentage": 25 => overall sampling percentage for dependencies
}
]
}
}
}
I am also using telemetry processors to sample custom metrics, but for the above use case (since percentages are involved), I am not sure if I can use telemetry processors
Set the overall default sampling rate to 100% to log everything.
Trace Logs: Default to 10%, but 100% for audit logs. Request Logs: 0% for health check requests. Dependency Logs: 25%.
Direct matching on the content of trace messages for .audit
will not be directly possible through the sampling configuration alone.
.audit
keyword in trace messagesCustomTelemetryProcessor.java
import com.microsoft.applicationinsights.telemetry.TraceTelemetry;
import com.microsoft.applicationinsights.channel.TelemetryProcessor;
import com.microsoft.applicationinsights.channel.TelemetryProcessorChain;
public class CustomTelemetryProcessor implements TelemetryProcessor {
private TelemetryProcessor next;
@Override
public void initialize(TelemetryProcessorChain chain) {
this.next = chain;
}
@Override
public boolean process(TraceTelemetry telemetry) {
String message = telemetry.getMessage();
if (message != null && message.contains(".audit")) {
return true; // Always send audit logs
}
return next.process(telemetry); // Continue with other processors
}
// Implement other telemetry types if needed
}
applicationinsights.json:
{
"sampling": {
"percentage": 100,
"requests": {
"percentage": 100,
"overrides": [
{
"attribute": "http.target",
"value": "/actuator/health",
"percentage": 0
}
]
},
"dependencies": {
"percentage": 25
},
"traces": {
"percentage": 10
}
}
}
Result:
Resquest logs:
Trace logs:
Exception logs: