I wanted to share the observations and outcomes from our
recent effort to integrate telemetry logging into Dynamics 365 plugins using
Azure Application Insights.
Objective
Enable telemetry tracking for plugin execution events in
Dynamics 365 using Application Insights for better monitoring and diagnostics.
Approaches Tried & Observations
- Using
Application Insights SDK in Plugin
- Attempt:
Integrated Microsoft.ApplicationInsights NuGet package and initialized
TelemetryClient in the plugin.
- Failures:
- Dynamics
sandbox blocked external DLL loading.
- Encountered
errors like:
- “Could
not load file or assembly 'Microsoft.ApplicationInsights…'”
- “Unresolved
assembly reference not allowed: System.Diagnostics.DiagnosticSource”
- ILMerge/ILRepack
attempts failed due to complex dependencies (System.Memory,
Newtonsoft.Json, etc.).
- Conclusion:
SDK-based approach is not feasible in Dynamics sandbox without heavy
workarounds.
- DLL
Merging with ILMerge/ILRepack
- Attempt:
Tried merging plugin DLL with Application Insights and dependent
assemblies.
- Failures:
- Multiple
unresolved assembly errors.
- Required
merging numerous framework-level DLLs, making it impractical.
- Conclusion:
Not recommended for maintainability and reliability.
- Lightweight
Telemetry via HTTP POST (Final Approach)
- Implementation:
Sent telemetry directly to Application Insights ingestion endpoint
(https://dc.services.visualstudio.com/v2/track) using HttpClient.
- Payload:
Custom JSON with InstrumentationKey, event name, and plugin context
details.
- Result:
Successfully logged custom events in Application Insights.
- Verification:
Confirmed via KQL queries in Azure Logs:
customEvents
| where name == "TelemetryEvent"
| order by timestamp desc
Result:
Key Learnings
- Avoid
heavy SDK dependencies in Dynamics plugins due to sandbox restrictions.
- Use Secure
Configuration for sensitive values like Instrumentation Key.
- Lightweight
HTTP telemetry is simple, reliable, and works without DLL merging.
No comments:
Post a Comment