Skip to content

feat(intercom): add diagnostic logging for bot boot flow (LFXV2-2024)#820

Merged
dealako merged 4 commits into
mainfrom
feat/LFXV2-2024-intercom-bot-logs
May 29, 2026
Merged

feat(intercom): add diagnostic logging for bot boot flow (LFXV2-2024)#820
dealako merged 4 commits into
mainfrom
feat/LFXV2-2024-intercom-bot-logs

Conversation

@audigregorie
Copy link
Copy Markdown
Contributor

Summary

This pull request improves observability and error handling for the Intercom integration in both the frontend (AppComponent, IntercomService) and backend (server.ts) of the application. The main focus is on adding detailed logging to help diagnose issues with Intercom widget initialization and script loading.

Improved logging and diagnostics for Intercom integration:

  • Added warnings and info logs in AppComponent to indicate when Intercom boot is skipped due to missing configuration, and to log the presence of key user and JWT fields when dispatching the boot command. [1] [2]
  • Enhanced IntercomService with:
    • Warnings when boot is called without an app_id, and info logs when boot is ignored due to an existing session or when the boot command is dispatched.
    • Info log when the Intercom widget script loads successfully, and improved error message when script loading fails.

Backend observability:

  • Added a debug log in server.ts to record the resolved Intercom SSR context, including presence of app ID, JWT, user ID, and authentication/impersonation status for each request.

Signed-off-by: Audi Young <audi.mycloud@gmail.com>
Signed-off-by: Audi Young <audi.mycloud@gmail.com>
Copilot AI review requested due to automatic review settings May 29, 2026 20:48
@audigregorie audigregorie requested a review from a team as a code owner May 29, 2026 20:48
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 53f0af70-01b6-47f4-9261-1c547aff4f85

📥 Commits

Reviewing files that changed from the base of the PR and between f9059b1 and a13ffdc.

📒 Files selected for processing (2)
  • apps/lfx-one/src/app/app.component.ts
  • apps/lfx-one/src/app/shared/services/intercom.service.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/lfx-one/src/app/app.component.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/lfx-one/src/app/shared/services/intercom.service.ts

Walkthrough

Adds ordered runtime guards and logging to Intercom boot on the client (service and component) and emits SSR-side Intercom context during server request handling.

Changes

Intercom boot logging enhancements

Layer / File(s) Summary
IntercomService boot logic and script loading
apps/lfx-one/src/app/shared/services/intercom.service.ts
boot() performs ordered checks (SSR, missing app_id, duplicate boot), tracks the injected script element, avoids duplicate script injection, logs dispatch, and logs/cleans up on script load success or failure.
AppComponent boot dispatch with context logging
apps/lfx-one/src/app/app.component.ts
bootIntercom() warns and returns when intercomAppId is absent, and emits console.info('Intercom: dispatching boot', ...) with boolean flags for JWT, userId, name, and email before calling the service.
Server-side SSR Intercom context logging
apps/lfx-one/src/server/server.ts
SSR handler emits a logger.debug intercom_ssr_context event containing flags for Intercom config presence, claim presence, user IDs, auth, and impersonation state.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding diagnostic logging for the Intercom bot boot flow, which aligns perfectly with the changeset across all three modified files.
Description check ✅ Passed The description is well-detailed and directly related to the changeset, providing context about logging improvements in both frontend and backend components for Intercom integration observability.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/LFXV2-2024-intercom-bot-logs

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 29, 2026

🚀 Deployment Status

Your branch has been deployed to: https://ui-pr-820.dev.v2.cluster.linuxfound.info

Deployment Details:

  • Environment: Development
  • Namespace: ui-pr-820
  • ArgoCD App: ui-pr-820

The deployment will be automatically removed when this PR is closed.

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

This PR improves observability for the Intercom “bot boot” flow across SSR (Express) and the Angular client by adding additional diagnostics around configuration presence, identity/JWT availability, and script load outcomes.

Changes:

  • Added SSR debug logging to capture whether Intercom-related inputs (app id / jwt / user id) are present for each request.
  • Added client-side console diagnostics when Intercom boot is skipped and when a boot command is dispatched.
  • Added additional IntercomService diagnostics around boot invocation and widget script load success/failure.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
apps/lfx-one/src/server/server.ts Adds SSR debug log for resolved Intercom runtime/auth context.
apps/lfx-one/src/app/shared/services/intercom.service.ts Adds more explicit client logging around boot calls and script load outcomes.
apps/lfx-one/src/app/app.component.ts Adds client diagnostics when boot is skipped or dispatched, including presence checks for required fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/lfx-one/src/app/shared/services/intercom.service.ts
Comment thread apps/lfx-one/src/app/shared/services/intercom.service.ts
Comment thread apps/lfx-one/src/app/app.component.ts
Signed-off-by: Audi Young <audi.mycloud@gmail.com>
Copy link
Copy Markdown
Contributor

@dealako dealako left a comment

Choose a reason for hiding this comment

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

Security Review — LFX Security Engineer Pass ✅

Ran a full Phase 1 + Phase 2 security scan against the 3 changed files. All checks passed:

  • Secrets/credentials: No hardcoded API keys, tokens, or credentials — INTERCOM_APP_ID consumed via process.env.
  • PII/sensitive data in logs: Every new log statement emits boolean presence flags (!!value) only — raw JWT, email, userId, or username values are never logged to the browser console or server log stream. This is the correct approach.
  • Injection — querySelector interpolation: scriptSrc is built from appId, which flows from process.env['INTERCOM_APP_ID'] (trusted config, not user-controlled). No injection vector.
  • No SQL/command injection, no XSS (innerHTML) patterns, no auth bypass.

AI Bot Reconciliation

Copilot left 3 inline comments. All three are resolved:

Copilot Comment Status Resolving Commit
#1 — isBootRequested log wording was misleading ✅ Resolved a13ffdc6 — message now reads 'boot ignored — already requested'
#2 — duplicate <script> tags on retry after load failure ✅ Resolved f9059b1b — added scriptElement tracking + dedup guard; onerror removes the element and nulls the ref, allowing a clean retry
#3 — snake_case vs camelCase key naming inconsistency ✅ Resolved a13ffdc6app.component.ts client logs now uniformly use camelCase; server.ts uses snake_case per the server-side logging convention in .claude/rules/logging-patterns.md

CodeRabbit: No actionable comments generated. 🎉


Findings

Minor (1)

See inline comment on server.ts:324.

Nits (2)

One inline on intercom.service.ts:70. One note here (not on a diff line):

[nit] app.component.ts:116 — The pre-existing warn at line 116 ('Intercom boot skipped: App ID present but missing identity') uses a slightly different message prefix style than the two new logs added in this PR ('Intercom: boot skipped — …', 'Intercom: dispatching boot'). Not introduced here, so not a blocker — but if message-grep consistency matters for log filtering, worth a follow-up align in a cleanup commit.


Summary

Hey Audi 👋 — clean, purposeful PR. The diagnostic scaffolding is exactly right: every log emits boolean presence flags rather than raw values, the server-side log uses the logger service correctly (right method, right signature, right log level for a request-scoped debug trace), and the retry hardening in IntercomService is a genuine improvement on top of the logging. All three Copilot findings were addressed before review — well done iterating before asking for approval. One minor note on log volume (inline below), two nits, zero blockers.

0 blocking issues · 1 minor · 2 nits

Decision: ✅ Approved with minor comments

intercomAppId: process.env['INTERCOM_APP_ID'] || '',
};

logger.debug(req, 'intercom_ssr_context', 'Intercom SSR inputs resolved', {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[minor] This logger.debug fires on every request that hits the SSR catch-all (/**), not just Intercom-relevant ones. At DEBUG level it is gated in production, so the log-volume impact is low — but it is worth deciding upfront whether this is meant to be permanent observability (fine as-is, no action needed) or temporary diagnostic scaffolding to triage the current boot issue (in which case a follow-up PR should remove or gate it once the root cause is confirmed). A brief comment in the code — // TODO(LFXV2-2024): remove once boot-flow is stable — would make intent clear for the next reviewer.

const scriptSrc = `https://widget.intercom.io/widget/${appId}`;
if (this.scriptElement?.isConnected || document.querySelector(`script[src="${scriptSrc}"]`)) {
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] The new dedup + cleanup logic here (lines 67–70: scriptElement.isConnected guard, document.querySelector fallback, script.remove() + null-reset in onerror) is actual behavior change, not just logging. The retry path was verified manually — onerror resets isBootRequested, removes the script element, and nulls the ref, so a subsequent boot() call passes the guard and re-injects cleanly. Correct. No automated test coverage, but the repo is E2E-only with no unit-test surface for services, so this is expected and acceptable. Flagging for awareness if a unit-test layer is ever introduced.

Copilot AI review requested due to automatic review settings May 29, 2026 21:48
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@dealako dealako merged commit 6ac35c4 into main May 29, 2026
12 checks passed
@dealako dealako deleted the feat/LFXV2-2024-intercom-bot-logs branch May 29, 2026 21:58
@github-actions
Copy link
Copy Markdown

🧹 Deployment Removed

The deployment for PR #820 has been removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants