Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/bridge-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Optional `failure_phase` and `error_code` on Quotes Error and Failed event context types
- Optional `source_hash_present` and `destination_hash_present` on Failed, Submitted, and Completed event context types
- Submit and status classifiers live in `@metamask/bridge-status-controller`
- Emit `failure_phase` and `error_code` on Quotes Error events ([#9949](https://github.com/MetaMask/core/pull/9949))
- Emit `failure_phase`, `error_code`, `source_hash_present`, and `destination_hash_present` on Failed events ([#9949](https://github.com/MetaMask/core/pull/9949))

## [80.0.0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ exports[`BridgeController SSE should reset quotes list if quote refresh fails 2`
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
"custom_slippage": true,
"error_code": "non_error_rejection",
"error_message": "Network error",
"failure_phase": "quote",
"feature_id": "unified_swap_bridge",
"has_sufficient_funds": true,
"is_hardware_wallet": false,
Expand Down Expand Up @@ -293,7 +295,9 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
"custom_slippage": true,
"error_code": "quote_fetch_failed",
"error_message": "Bridge-api error: timeout from server",
"failure_phase": "quote",
"feature_id": "unified_swap_bridge",
"has_sufficient_funds": true,
"is_hardware_wallet": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent bridge-status-controller c
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
"custom_slippage": true,
"destination_hash_present": false,
"destination_transaction": "PENDING",
"error_code": "unknown",
"error_message": "error_message",
"failure_phase": "unknown",
"feature_id": "unified_swap_bridge",
"gas_included": false,
"gas_included_7702": false,
Expand All @@ -137,6 +140,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent bridge-status-controller c
"quotes_list": [],
"security_warnings": [],
"slippage_limit": undefined,
"source_hash_present": false,
"source_transaction": "PENDING",
"stx_enabled": false,
"swap_type": "crosschain",
Expand All @@ -163,7 +167,10 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent bridge-status-controller c
"chain_id_destination": "eip155:1",
"chain_id_source": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"custom_slippage": true,
"destination_hash_present": false,
"error_code": "unknown",
"error_message": "Failed to submit tx",
"failure_phase": "unknown",
"feature_id": "unified_swap_bridge",
"gas_included": false,
"gas_included_7702": false,
Expand All @@ -180,6 +187,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent bridge-status-controller c
"lifi_mayanMCTP",
],
"slippage_limit": 0.5,
"source_hash_present": false,
"stx_enabled": false,
"swap_type": "crosschain",
"token_address_destination": "eip155:1/erc20:0x1234",
Expand Down Expand Up @@ -1076,7 +1084,9 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
"custom_slippage": true,
"error_code": "quote_fetch_failed",
"error_message": "Network error",
"failure_phase": "quote",
"feature_id": "unified_swap_bridge",
"has_sufficient_funds": true,
"is_hardware_wallet": false,
Expand Down
42 changes: 29 additions & 13 deletions packages/bridge-controller/src/bridge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ import {
import {
AbortReason,
BatchSellMetricsEventName,
FailurePhase,
MetaMetricsSwapsEventSource,
MetricsActionType,
SwapBridgeErrorCode,
UnifiedSwapBridgeEventName,
} from './utils/metrics/constants.js';
import type {
BridgeControllerMetricsEventName,
BridgeControllerMetricsLocation,
} from './utils/metrics/constants.js';
import { getQuoteFetchErrorCode } from './utils/metrics/failure-telemetry.js';
import {
formatProviderLabel,
getAccountHardwareType,
Expand Down Expand Up @@ -977,10 +980,11 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
state.quotesLoadingStatus = RequestStatus.ERROR;
});
// Track event and log error
this.trackUnifiedSwapBridgeEvent(
UnifiedSwapBridgeEventName.QuotesError,
context,
);
this.trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.QuotesError, {
...context,
failure_phase: FailurePhase.Quote,
error_code: getQuoteFetchErrorCode(error),
});
console.log(
`Failed to ${shouldStream ? 'stream' : 'fetch'} bridge quotes`,
error,
Expand Down Expand Up @@ -1384,33 +1388,45 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
...this.#getRequestMetadata(),
error_message: this.state.quoteFetchError,
has_sufficient_funds: !quoteRequest.insufficientBal,
failure_phase: FailurePhase.Quote,
error_code: SwapBridgeErrorCode.QuoteFetchFailed,
...baseProperties,
};
case UnifiedSwapBridgeEventName.AllQuotesOpened:
case UnifiedSwapBridgeEventName.AllQuotesSorted:
case UnifiedSwapBridgeEventName.QuoteSelected:
case UnifiedSwapBridgeEventName.Failed: {
const failedClientProperties =
propertiesFromClient as RequiredEventContextFromClient[UnifiedSwapBridgeEventName.Failed];
// Populate the properties that the error occurred before the tx was submitted
return {
...baseProperties,
...getRequestParams(
quoteRequest,
this.state.tokenSecurityTypeDestination,
),
...this.#getRequestMetadata(),
...this.#getQuoteFetchData(),
...baseProperties,
...propertiesFromClient,
failure_phase:
failedClientProperties.failure_phase ?? FailurePhase.Unknown,
error_code:
failedClientProperties.error_code ?? SwapBridgeErrorCode.Unknown,
source_hash_present:
failedClientProperties.source_hash_present ?? false,
destination_hash_present:
failedClientProperties.destination_hash_present ?? false,
};
case UnifiedSwapBridgeEventName.Failed: {
// Populate the properties that the error occurred before the tx was submitted
}
case UnifiedSwapBridgeEventName.AllQuotesOpened:
case UnifiedSwapBridgeEventName.AllQuotesSorted:
case UnifiedSwapBridgeEventName.QuoteSelected:
return {
...baseProperties,
...getRequestParams(
quoteRequest,
this.state.tokenSecurityTypeDestination,
),
...this.#getRequestMetadata(),
...this.#getQuoteFetchData(),
...propertiesFromClient,
...baseProperties,
};
}
case UnifiedSwapBridgeEventName.AssetDetailTooltipClicked:
case UnifiedSwapBridgeEventName.AssetPickerOpened:
return baseProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SwapBridgeErrorCode } from './constants.js';
* Classify a thrown value for Quotes Error. Quote fetch always stays in the
* `quote` phase; this only chooses `error_code`.
*
* Submit and status failure classifiers live in `@metamask/bridge-status-controller`.
*
* @param error - The thrown value from quote fetch.
* @returns The Mixpanel `error_code`.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/bridge-status-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add SwapBridge submit and status failure telemetry classifiers for a later emit ([#9947](https://github.com/MetaMask/core/pull/9947))
- New exports: `getHashPresenceProperties`, `getStatusFailurePhase`, `getSubmitErrorCode`, `getSubmitFailureTelemetry`, and `getStatusFailureTelemetry`
- Classifies submit and status failures from the code path (not from `error_message`)
- Emit `failure_phase`, `error_code`, `source_hash_present`, and `destination_hash_present` on SwapBridge Submitted, Completed, and Failed events ([#9949](https://github.com/MetaMask/core/pull/9949))

## [75.3.0]

Expand Down
Loading