Don’t reinvent the wheel and write this yourself. Have your application write out a log, ingest the log into a tool, and use the tool for your analytics. Elastic isn’t a bad choice.