Skip to content

Emit integration invoke error metric for destination load failures#1341

Merged
MichaelGHSeg merged 3 commits intomasterfrom
fix/destination-load-metrics
Mar 4, 2026
Merged

Emit integration invoke error metric for destination load failures#1341
MichaelGHSeg merged 3 commits intomasterfrom
fix/destination-load-metrics

Conversation

@MichaelGHSeg
Copy link
Copy Markdown
Collaborator

Summary

  • Classic destination script loading (loadIntegration) and construction (buildIntegration) failures were not emitting any analytics_js.integration.invoke.error metrics — errors went straight to handleLoadError in event-queue.ts which only does console.warn and removes the plugin
  • Action destination failures in the remote-loader per-plugin catch block only logged console.warn with no metrics
  • The remoteLoader() call in browser/index.ts had a completely silent .catch(() => []) that swallowed all errors with no logging

These gaps were identified during investigation of a GTM incident where a new "Google Custom Domain" field with an empty value silently broke all GTM destination instances with zero visibility in Datadog.

Changes

  • Wrap loadIntegration/buildIntegration in LegacyDestination.load() with try/catch that calls recordIntegrationMetric with method:load, type:classic, didError:true
  • Add recordIntegrationMetric call in remote-loader catch block with method:load, type:action, didError:true
  • Replace silent .catch(() => []) on remoteLoader call with console.error logging
  • Add tests for both classic and action destination load error metric emission

Test plan

  • Existing browser test suite passes (68 suites, 750 tests, 0 failures)
  • New test: recordIntegrationMetric called with method:load, didError:true when loadIntegration throws (classic)
  • New test: recordIntegrationMetric called with method:load, didError:true when buildIntegration throws (classic)
  • New test: recordIntegrationMetric called with method:load, didError:true when remote plugin factory throws (action)
  • Verify metrics appear in Datadog after deploy by triggering a destination load failure in staging

🤖 Generated with Claude Code

…d failures

Classic destination script loading (loadIntegration) and construction
(buildIntegration) failures were not emitting any metrics, causing
silent failures invisible to Datadog. Similarly, action destination
failures in the remote-loader only logged console.warn with no metrics.

- Wrap loadIntegration/buildIntegration in LegacyDestination.load()
  with try/catch that calls recordIntegrationMetric (method:load)
- Add recordIntegrationMetric call in remote-loader catch block
- Replace silent .catch(() => []) on remoteLoader with console.error
- Add tests for both classic and action destination load error metrics

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 12, 2026

🦋 Changeset detected

Latest commit: 59bbf3e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@segment/analytics-next Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 12, 2026

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.20%. Comparing base (ece6393) to head (59bbf3e).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
packages/browser/src/browser/index.ts 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1341      +/-   ##
==========================================
+ Coverage   91.19%   91.20%   +0.01%     
==========================================
  Files         163      163              
  Lines        4383     4388       +5     
  Branches     1052     1052              
==========================================
+ Hits         3997     4002       +5     
  Misses        386      386              
Flag Coverage Δ
browser 92.23% <70.00%> (+0.01%) ⬆️
core 89.86% <ø> (ø)
node 87.93% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

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 destination load failures by emitting analytics_js.integration.invoke.error metrics for both classic (AJS) destinations and action (remote) destinations, and by surfacing previously swallowed remote-loader errors.

Changes:

  • Emit integration invoke error metrics when classic destinations fail during loadIntegration/buildIntegration.
  • Emit integration invoke error metrics when remote action plugin factories fail during remote loading.
  • Replace a silent remoteLoader() catch with explicit error logging; add unit tests covering these error-metric emissions.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/browser/src/plugins/remote-loader/index.ts Records an integration invoke error metric when a remote plugin fails to load.
packages/browser/src/plugins/remote-loader/tests/index.test.ts Adds coverage ensuring the action destination load failure metric is emitted.
packages/browser/src/plugins/ajs-destination/index.ts Wraps classic destination load/build to emit an integration invoke error metric on failure.
packages/browser/src/plugins/ajs-destination/tests/index.test.ts Adds coverage ensuring classic destination load/build failures emit error metrics.
packages/browser/src/browser/index.ts Logs remote loader failures instead of silently swallowing them.

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

Comment on lines 311 to +317
console.warn('Failed to load Remote Plugin', error)
recordIntegrationMetric(Context.system(), {
integrationName: remotePlugin.creationName,
methodName: 'load',
type: 'action',
didError: true,
})
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

The new error metric uses integrationName: remotePlugin.creationName, but action destination metrics elsewhere in this module use integrationName: this.action.name (i.e., the plugin's name). This means load failures will be tagged under a different integration_name than successful load/invoke metrics for the same destination, making dashboards and error-rate calculations inconsistent. Consider using remotePlugin.name here for consistency, or update the ActionDestination metric calls to use the wrapper/destination name consistently (e.g., this.name / remotePlugin.creationName).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

chenxzhang
chenxzhang previously approved these changes Feb 13, 2026
Copy link
Copy Markdown
Collaborator

@chenxzhang chenxzhang left a comment

Choose a reason for hiding this comment

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

lgtm, let's just make sure the integrationName is consistent

Copy link
Copy Markdown

Copilot AI commented Feb 19, 2026

@MichaelGHSeg I've opened a new pull request, #1345, to work on those changes. Once the pull request is ready, I'll request review from you.

… metrics (#1345)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MichaelGHSeg <101233650+MichaelGHSeg@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MichaelGHSeg MichaelGHSeg merged commit 6477267 into master Mar 4, 2026
8 checks passed
@MichaelGHSeg MichaelGHSeg deleted the fix/destination-load-metrics branch March 4, 2026 20:00
@github-actions github-actions bot mentioned this pull request Mar 4, 2026
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.

4 participants