Skip to content

feat: Application Insights telemetry for backend and Android#280

Merged
dkhalife merged 2 commits intomainfrom
app_insights
Mar 27, 2026
Merged

feat: Application Insights telemetry for backend and Android#280
dkhalife merged 2 commits intomainfrom
app_insights

Conversation

@dkhalife
Copy link
Copy Markdown
Owner

Summary

Add Application Insights telemetry to the Go API server and Android app, following the same CustomEvent pattern used in my-journey.

Backend (Go API Server)

  • Version package (\internal/version/) — build-time injected Version, BuildNumber, CommitHash via -ldflags\
  • Telemetry package (\internal/telemetry/) — singleton App Insights client, \TrackEvent/\TrackError/\TrackWarning\ functions with \�pp_component\ field
  • DNT middleware — reads \DNT: 1\ header from requests and skips telemetry for that user; tracks HTTP requests as CustomEvents
  • Error instrumentation — added telemetry tracking to ~13 files: API handlers, auth middleware, task/label/user/notification services, WebSocket server, scheduler, database, rate limiter
  • Flush on shutdown — telemetry is flushed before server stops

Android App

  • OpenTelemetry SDK + custom \AzureMonitorSpanExporter\ that posts EventData to App Insights
  • TelemetryManager — Hilt singleton with \logInfo/\logWarning/\logError/\logDebug/\logTrace\ methods, gated by user preference
  • Analytics toggle in Settings (OFF by default) with a conditional \Debug logging\ sub-toggle for verbose diagnostics
  • DoNotTrackInterceptor — OkHttp interceptor sends \DNT: 1\ header when telemetry is disabled
  • BuildConfig fields — \GIT_SHA\ and \APPINSIGHTS_CONNECTION_STRING\ injected at build time
  • Error instrumentation — added telemetry to ~15 files: auth, repositories, sync workers, WebSocket, calendar, ViewModels, widgets, sound manager
  • Crash handler — uncaught exceptions are tracked before propagating

CI/CD

  • .goreleaser.yaml\ — added -ldflags\ for version/build/commit injection
  • \�pi-build.yml\ — CI build includes -ldflags\ with commit hash
  • \ ull-release.yml\ — passes \APPINSIGHTS_CONNECTION_STRING\ secret to Android release build

Documentation

  • README — added Telemetry configuration section and \APPINSIGHTS_CONNECTION_STRING\ to config reference
  • Privacy Policy — added Optional Telemetry section, updated Third-Party Services, removed outdated claim about no telemetry

Key Design Decisions

  • \�pp_component\ field used on both platforms for KQL query compatibility
  • Android telemetry is OFF by default — user must opt in
  • Backend reads \APPINSIGHTS_CONNECTION_STRING\ from env (not config.yaml)
  • \ elemetryManager.logError()\ calls \Log.e()\ internally — no duplicate logging
  • Glance widgets fall back to \Log.w\ since they lack DI access

Copilot AI review requested due to automatic review settings March 27, 2026 02:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds optional Azure Application Insights telemetry across the Go API server and Android client, plus documentation/privacy updates and CI/CD wiring to inject build metadata and secrets.

Changes:

  • Backend: introduce internal/telemetry + internal/version, add DNT-aware request middleware, instrument errors/warnings across handlers/services, and flush on shutdown.
  • Android: add OpenTelemetry-based TelemetryManager, Do-Not-Track request header support, Settings toggles (telemetry + debug logging), and instrument key app flows/workers.
  • Ops/docs: wire -ldflags/BuildConfig fields in CI/release builds and update README + Privacy Policy.

Reviewed changes

Copilot reviewed 53 out of 54 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
frontend/src/views/PrivacyPolicy.tsx Updates privacy policy to describe optional telemetry + third-party services.
apiserver/main.go Enables DNT CORS header, registers telemetry middleware, flushes telemetry on shutdown.
apiserver/internal/ws/server.go Adds telemetry for WS auth/upgrade/read/write failures.
apiserver/internal/version/version.go New build-metadata package populated via -ldflags.
apiserver/internal/utils/middleware/middleware.go Adds request-level telemetry + DNT detection; instruments rate limiting.
apiserver/internal/utils/database/database.go Instruments DB open failure telemetry.
apiserver/internal/telemetry/telemetry.go New telemetry helper APIs (TrackEvent/Warning/Error) with shared properties.
apiserver/internal/telemetry/appinsights.go App Insights client singleton initialization + connection string parsing + flush.
apiserver/internal/telemetry/appinsights_test.go Unit tests for connection string parsing helpers.
apiserver/internal/services/users/user.go Adds telemetry on notification-settings failures.
apiserver/internal/services/tasks/task.go Adds telemetry across task CRUD + recurrence flows.
apiserver/internal/services/scheduler/scheduler.go Adds telemetry when scheduled jobs fail.
apiserver/internal/services/notifications/notifications.go Adds telemetry for notification cleanup/send failures.
apiserver/internal/services/labels/label.go Adds telemetry for label CRUD failures + forbidden operations.
apiserver/internal/middleware/auth/auth.go Adds telemetry for unauthorized/forbidden auth decisions.
apiserver/internal/apis/user.go Adds telemetry for user handler failures/bind errors.
apiserver/internal/apis/task.go Adds telemetry for invalid params and bind errors in task endpoints.
apiserver/internal/apis/log.go Adds telemetry for client-side warn/error log endpoints.
apiserver/internal/apis/label.go Adds telemetry for invalid params and bind errors in label endpoints.
apiserver/go.mod Adds indirect dependencies for ApplicationInsights-Go.
apiserver/go.sum Adds checksums for new telemetry dependencies.
android/gradle/libs.versions.toml Adds OpenTelemetry dependency version + library entries.
android/app/src/main/res/values/strings.xml Adds Settings strings for Analytics + Debug logging toggles.
android/app/src/main/java/com/dkhalife/tasks/ws/WebSocketManager.kt Adds telemetry logging for WS connect/send/parse/failure scenarios.
android/app/src/main/java/com/dkhalife/tasks/viewmodel/TaskListViewModel.kt Logs repository failures to telemetry.
android/app/src/main/java/com/dkhalife/tasks/viewmodel/TaskFormViewModel.kt Logs load/save failures to telemetry.
android/app/src/main/java/com/dkhalife/tasks/viewmodel/LabelViewModel.kt Logs label CRUD failures to telemetry.
android/app/src/main/java/com/dkhalife/tasks/viewmodel/AuthViewModel.kt Logs MSAL sign-in/out failures to telemetry.
android/app/src/main/java/com/dkhalife/tasks/utils/SoundManager.kt Routes sound errors through telemetry instead of Log.e.
android/app/src/main/java/com/dkhalife/tasks/ui/screen/SettingsScreen.kt Adds Analytics + Debug logging toggles to Settings UI.
android/app/src/main/java/com/dkhalife/tasks/ui/navigation/AppNavigation.kt Threads telemetry/debug settings through navigation to Settings screen.
android/app/src/main/java/com/dkhalife/tasks/telemetry/TelemetryManager.kt New OpenTelemetry-based telemetry manager with user preference gating.
android/app/src/main/java/com/dkhalife/tasks/telemetry/AzureMonitorSpanExporter.kt Custom exporter sending EventData payloads to App Insights.
android/app/src/main/java/com/dkhalife/tasks/repo/UserRepository.kt Logs API failures to telemetry.
android/app/src/main/java/com/dkhalife/tasks/repo/TaskRepository.kt Logs API failures to telemetry.
android/app/src/main/java/com/dkhalife/tasks/repo/LabelRepository.kt Logs API failures to telemetry.
android/app/src/main/java/com/dkhalife/tasks/di/NetworkModule.kt Adds DNT interceptor; injects TelemetryManager into auth interceptor.
android/app/src/main/java/com/dkhalife/tasks/data/widget/WidgetSyncEngine.kt Adds telemetry warnings for widget sync/deserialize failures.
android/app/src/main/java/com/dkhalife/tasks/data/sync/TaskSyncWorkerFactory.kt Injects TelemetryManager into TaskSyncWorker.
android/app/src/main/java/com/dkhalife/tasks/data/sync/TaskSyncWorker.kt Logs sync engine and fetch failures to telemetry.
android/app/src/main/java/com/dkhalife/tasks/data/calendar/CalendarSyncEngine.kt Logs calendar edge cases/date parse failures to telemetry.
android/app/src/main/java/com/dkhalife/tasks/data/calendar/CalendarRepository.kt Logs enable/disable calendar sync failures to telemetry.
android/app/src/main/java/com/dkhalife/tasks/data/TelemetryRepository.kt New SharedPreferences-backed repo for telemetry/debug toggles.
android/app/src/main/java/com/dkhalife/tasks/data/AppPreferences.kt Adds preference keys for telemetry/debug/device id.
android/app/src/main/java/com/dkhalife/tasks/auth/AuthManager.kt Logs token/sign-in/out issues via TelemetryManager.
android/app/src/main/java/com/dkhalife/tasks/api/DoNotTrackInterceptor.kt New interceptor that adds DNT: 1 header when telemetry disabled.
android/app/src/main/java/com/dkhalife/tasks/api/AuthInterceptor.kt Adds telemetry warnings when auth retry/refresh fails.
android/app/src/main/java/com/dkhalife/tasks/TaskWizardApplication.kt Initializes telemetry and installs crash handler.
android/app/src/main/java/com/dkhalife/tasks/MainActivity.kt Holds telemetry/debug state and wires it into Settings UI.
android/app/build.gradle.kts Injects git SHA + App Insights connection string into BuildConfig; adds OpenTelemetry deps.
README.md Documents telemetry configuration and env var usage.
.goreleaser.yaml Injects version/build/commit into backend binaries via -ldflags.
.github/workflows/full-release.yml Passes APPINSIGHTS_CONNECTION_STRING into Android release build job.
.github/workflows/api-build.yml Adds -ldflags build metadata injection during CI backend build.

Comment thread apiserver/internal/telemetry/appinsights.go
Comment thread apiserver/internal/middleware/auth/auth.go
Comment thread apiserver/internal/version/version.go
Comment thread apiserver/internal/utils/middleware/middleware.go Outdated
Comment thread android/app/src/main/java/com/dkhalife/tasks/api/DoNotTrackInterceptor.kt Outdated
Comment thread android/app/src/main/java/com/dkhalife/tasks/api/AuthInterceptor.kt Outdated
Comment thread apiserver/internal/telemetry/appinsights_test.go
Comment thread android/app/src/main/java/com/dkhalife/tasks/TaskWizardApplication.kt Outdated
@dkhalife dkhalife merged commit cfbd45c into main Mar 27, 2026
9 checks passed
@dkhalife dkhalife deleted the app_insights branch March 27, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants