A Visual Studio Code extension demonstrating telemetry tracking using Azure Application Insights with an event-driven architecture.
- Event-driven telemetry using
TelemetryEventEmitter - Clean, reusable API for tracking events
- Component-based organization
- Azure Application Insights integration
-
Clone and install dependencies:
npm install
-
Add your Application Insights connection string in src/extension.ts:
const connectionString = 'your-connection-string-here';
-
Run the extension:
npm run compile # Press F5 to debug
Use the TelemetryEventEmitter to fire events from anywhere in your extension:
import { TelemetryEventEmitter } from './event-emitter';
TelemetryEventEmitter.instance.fire({
eventName: 'myEvent',
componentName: 'myComponent',
customDimensions: {
action: 'buttonClick',
feature: 'newFeature'
},
measurements: {
executionTime: 123,
memoryUsed: 456789
}
});Singleton event emitter for telemetry events.
Methods:
fire(payload)- Fire a telemetry eventonDidFire(listener)- Listen for telemetry events
Creates and initializes a telemetry reporter.
Sends a telemetry event to Application Insights.
The extension uses an event-driven architecture:
- Components fire telemetry events using
TelemetryEventEmitter - The extension listens for these events during activation
- Events are forwarded to Azure Application Insights via the reporter
This pattern decouples telemetry logic from business logic, making code cleaner and more maintainable.
npm run compile # Compile TypeScript
npm run watch # Watch mode
npm run lint # Lint code