I'm trying to monitor a console app (automatically run every hour) in .NET
The app is built on an HostBuilder, I have called .UseAllElasticApm()
and .UseConsoleLifetime()
on it, and I make a transaction by code :
var transaction = Elastic.Apm.Agent.Tracer.StartTransaction("ConsoleAppRunning", ApiConstants.TypeRequest);
try {
await RunCode();
}
catch (Exception ex){
transaction.CaptureException(ex);
}
finally{
transaction.End();
}
The app closes just after the finally.
This code worked on my dev machine, and I could see data appear on APM.
But once built in Release
mode and deployed to Production server, I could see the service in Kibana with Environment Production, but no data in it.
After searching a while, I think the problem is the flush interval set to 30s by default
I changed the value to 1s, and added a Task.Delay at the end of the console app, and now I see the transactions in Kibana.
But I don't like this solution, isn't there a way to force flush when I know my app is about to close, and wait for it to be done ?
Also, one more question :
for the transaction type, I use ApiConstants.TypeRequest
, can I use any other string here, or am I limited to the values in ApiConstants
?