(Re)attaching to an App Insights Operation from another machine/process (not using HTTP)
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Application Insights, a part of Azure Monitor, is a highly versatile application performance management (APM) service that monitors live applications efficiently. One of its pivotal features includes the ability to correlate telemetry data from multiple sources to a single operation, using Operation IDs. This becomes particularly useful in distributed systems where components may run on different machines or processes.
However, linking telemetry from different processes or machines that do not use HTTP (which automatically supports correlation) requires a manual approach. Below, we explore how to manually (re)attach telemetry to an Application Insights Operation from another machine or process.
Understanding Operation and Telemetry Context
When telemetry is sent to Application Insights, it's associated with a TelemetryContext. This context includes the Operation ID (a GUID representing the operation across components), and potentially a Parent ID (representing a specific parent operation within the overall operation).
For enabling cross-component telemetry correlation in scenarios not covered automatically by Application Insights (such as non-HTTP based communications), you must manually propagate and set these context values.
Manual Propagation of Operation IDs
- Extract and Transmit Context Data: Initially, when the operation starts, an Operation ID is generated. This ID and any other context data, like Parent ID, must be explicitly extracted and transmitted to the other machine or process. This often means serializing this context into a message or data format that is being sent to the other component.
- Deserialize and Apply the Context: On the receiving end, this context must be deserialized from the incoming message and used to configure the TelemetryContext for that operation in that specific machine or process environment.
Example Scenario: Non-HTTP Messaging
Consider a scenario where two services communicate over a custom TCP-based protocol. Here’s how you could manually link the operations:
Sending Side:
Receiving Side:
Key Points in Operation Reattachment
Below is a table summarizing key considerations when manually reattaching telemetry to an App Insights Operation:
| Aspect | Consideration | Example |
| Context Propagation | Must manually transmit context values | Operation ID and Parent ID in message |
| Serialization | Context must be serialized into transmittable format | JSON, XML, key-value pairs in message |
| Deserialization | Extract context from received data | Deserialize JSON, XML, etc., to extract context values |
| TelemetryClient Usage | Use TelemetryClient API to apply context | StartOperation and StopOperation called with context values |
| Automation Limitation | No automatic correlation like HTTP | Manual handling of correlation context |
Additional Considerations
- Security: Ensure that the propagation of telemetry context does not expose sensitive information, and that the mechanism used for transmission is secure.
- Performance: Consider the overhead of adding telemetry propagation, particularly serialization and deserialization in performance-critical paths.
- Integration: In complex systems, ensure consistent implementation across all components to maintain reliable telemetry.
Conclusion
Manually reattaching operations across different machines or processes in non-HTTP environments, although complex, is crucial for maintaining a holistic view of application performance and troubleshooting in distributed systems. By ensuring correct propagation and assignment of the telemetry context, developers can provide deep insights into the health and activities of their applications across varied environments.
Related reading
- Receive AccessDenied when trying to access a page via the full url on my website
- Redirect http port to nodePort
- Redirect http// requests to https// on AWS API Gateway using Custom Domains
- Refreshing OAuth token using Retrofit without modifying all calls
- Regional/Edge-optimized API Gateway VS Regional/Edge-optimized custom domain name
- Reliable Webhook dispatching system
- Replacing tf.placeholder and feed_dict with tf.data API
- Repository not necessary when implementing JpaRepository?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.