Stefan Holm Olsen

Correlate telemetry for scheduled jobs in Optimizely CMS

Previously on this blog, I presented a way to correlate Application Insights telemetry to those of us who use Hangfire for running scheduled and queued jobs.

But even if you make your scheduled jobs based on Optimizely's scheduled job framework, you can still correlate all the telemetry generated while running a job.

The Application Insights SDK provides a method, StartOperation, which creates a telemetry holder for all subsequent telemetry.

To take advantage of this in a nice way, I created a simple class, ScheduledJobOperationScope, to wrap all telemetry for the duration of the job. It looks like this:

This can then be used in a scheduled job, like this sample:

With this in place, all telemetry data that was sent, while running the scheduled job, is grouped together in Application Insights.

Be aware that this only works for your own scheduled jobs, where you can add scope. It cannot (yet) be applied to built-in scheduled jobs.