feat: Add gzip decompression and NDJSON support for Application Insig…#2
Merged
Merged
Conversation
…hts SDK ## Problem The official Microsoft Application Insights SDK sends telemetry with two characteristics that azurinsight didn't handle: 1. **Gzip compression**: Telemetry is sent with `content-encoding: gzip` header 2. **NDJSON format**: Multiple telemetry items are batched as newline-delimited JSON, not a single JSON array Without this support, the emulator would fail to parse Application Insights SDK telemetry with errors like: - "SyntaxError: Unexpected non-whitespace character after JSON at position X" - Telemetry silently lost or partially captured ## Solution Added gzip decompression middleware that: 1. **Detects gzipped requests** by checking `content-encoding: gzip` header 2. **Decompresses the payload** using Node.js built-in `zlib.gunzipSync` 3. **Parses NDJSON format** by splitting on newlines and parsing each line as separate JSON 4. **Maintains backward compatibility** by detecting single-line JSON and parsing normally 5. **Positioned correctly** before bodyParser middleware to intercept and pre-process the request body ## Testing This fix has been production-tested in the SentimentIQ project with: - ✅ 15/15 Application Insights integration tests passing - ✅ Verified with actual Application Insights SDK telemetry - ✅ Handles both single and batched telemetry items - ✅ Proper error handling for malformed payloads ## Impact This change makes azurinsight fully compatible with the official Microsoft Application Insights SDK, enabling developers to use it as a local development emulator without SDK-specific workarounds. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Owner
Excellent contribution! 🎉@ChNorman - Thank you for adding gzip/NDJSON support! This is a significant step makes Really appreciate your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The official Microsoft Application Insights SDK sends telemetry with two characteristics that azurinsight didn't handle:
content-encoding: gzipheaderWithout this support, the emulator would fail to parse Application Insights SDK telemetry with errors like:
Solution
Added gzip decompression middleware that:
content-encoding: gzipheaderzlib.gunzipSyncTesting
Impact
This change makes azurinsight fully compatible with the official Microsoft Application Insights SDK, enabling developers to use it as a local development emulator without SDK-specific workarounds.