Application Insights Operation around Jobs #1224
Replies: 2 comments
-
I don't have any canned answers for this, but @maldago is current working on a PR to get OpenTelemetry support - which is super awesome! What I understand this should also enable some AI scenarios via exporters, but I'm not sure if there's anything out of the box to export to Application Insights. I'm not an expert on this area, but more than willing to tweak Quartz to record any data necessary to enable such scenarios. |
Beta Was this translation helpful? Give feedback.
-
It's quite some time since that Question arised, but maybe my answer helps some others which have similar requirements: I did something similar with Elastic.Apm (https://www.elastic.co/guide/en/apm/agent/dotnet/current/public-api.html). Using the MicrosoftDependencyInjectionJobFactory approach you can wrap the Execution with your own JobWrapper, override the Execute-Method and wrap the execution with the Transaction or Span of the chosen Insight-Framework. I did that including the usage of DI, which means I just inherited the MicrosoftDependencyInjectionJobFactory and wrapped it again. Example: public interface IJobWrapper
{
IJob Target { get; }
}
public class CustomTelemetryJobFactoryWithDI : MicrosoftDependencyInjectionJobFactory
{
public CustomTelemetryJobFactoryWithDI(IServiceProvider serviceProvider, IOptions<QuartzOptions> options)
: base(serviceProvider, options)
{
}
protected override IJob InstantiateJob(TriggerFiredBundle bundle, IScheduler scheduler)
=> new MonitoredJob(base.InstantiateJob(bundle, scheduler));
public override void SetObjectProperties(object obj, JobDataMap data)
{
if (obj is IJobWrapper jobWrapper)
SetObjectProperties(jobWrapper.Target, data); // recursion for additional wrappers
else
base.SetObjectProperties(obj, data); // rely on base-implementation for other types, we cannot handle Quartz-IJobWrappers
}
public override void ReturnJob(IJob job)
{
if (job is IDisposable disposable)
disposable.Dispose(); // Wrappers should handle inner Disposing on it's own, no further recursion
else if (job is IJobWrapper wrapper)
ReturnJob(wrapper.Target);
else
base.ReturnJob(job); // rely on base-implementation for other types, we cannot handle Quartz-IJobWrappers
}
private sealed class MonitoredJob : IJobWrapper, IJob
{
public IJob Target { get; }
public MonitoredJob(IJob target)
{
Target = target;
}
public ValueTask Execute(IJobExecutionContext context)
{
//wrap job with Telemetry here
return Target.Execute(context);
}
}
} edit: renamed JobWrapper |
Beta Was this translation helpful? Give feedback.
-
Does anyone know how you can wrap a job execution in an application insights operation ?
I tried to wrap it with the following listener:
The operation is started correctly, however the job execution itself is not in the operation:
In application insights, I when I search the logs for the operation id logged by the Listener, the logs of the job are not included
Beta Was this translation helpful? Give feedback.
All reactions