22 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
5- import { Injectable } from '@nestjs/common' ;
5+ import { Inject , Injectable } from '@nestjs/common' ;
66
77import { GoogleManager } from '@fxa/google' ;
88import {
@@ -75,6 +75,7 @@ import { ValidateLocationActionResult } from './validators/ValidateLocationActio
7575import { ValidateLocationActionArgs } from './validators/ValidateLocationActionArgs' ;
7676import { UpdateTaxAddressActionArgs } from './validators/UpdateTaxAddressActionArgs' ;
7777import { UpdateTaxAddressActionResult } from './validators/UpdateTaxAddressActionResult' ;
78+ import { CaptureTimingWithStatsD , StatsDService , type StatsD } from '@fxa/shared/metrics/statsd' ;
7879
7980/**
8081 * ANY AND ALL methods exposed via this service should be considered publicly accessible and callable with any arguments.
@@ -93,12 +94,14 @@ export class NextJSActionsService {
9394 private geodbManager : GeoDBManager ,
9495 private currencyManager : CurrencyManager ,
9596 private eligibilityService : EligibilityService ,
96- private productConfigurationManager : ProductConfigurationManager
97+ private productConfigurationManager : ProductConfigurationManager ,
98+ @Inject ( StatsDService ) public statsd : StatsD
9799 ) { }
98100
99101 @SanitizeExceptions ( )
100102 @NextIOValidator ( GetCartActionArgs , GetCartActionResult )
101103 @WithTypeCachableAsyncLocalStorage ( )
104+ @CaptureTimingWithStatsD ( )
102105 async getCart ( args : { cartId : string } ) {
103106 const cart = await this . cartService . getCart ( args . cartId ) ;
104107
@@ -110,6 +113,7 @@ export class NextJSActionsService {
110113 } )
111114 @NextIOValidator ( GetCartActionArgs , GetSuccessCartActionResult )
112115 @WithTypeCachableAsyncLocalStorage ( )
116+ @CaptureTimingWithStatsD ( )
113117 async getSuccessCart ( args : { cartId : string } ) : Promise < SuccessCartDTO > {
114118 const cart = await this . cartService . getCart ( args . cartId ) ;
115119
@@ -129,6 +133,7 @@ export class NextJSActionsService {
129133 } )
130134 @NextIOValidator ( UpdateCartActionArgs , UpdateCartActionResult )
131135 @WithTypeCachableAsyncLocalStorage ( )
136+ @CaptureTimingWithStatsD ( )
132137 async updateCart ( args : {
133138 cartId : string ;
134139 version : number ;
@@ -151,6 +156,7 @@ export class NextJSActionsService {
151156 @SanitizeExceptions ( )
152157 @NextIOValidator ( RestartCartActionArgs , RestartCartActionResult )
153158 @WithTypeCachableAsyncLocalStorage ( )
159+ @CaptureTimingWithStatsD ( )
154160 async restartCart ( args : { cartId : string } ) {
155161 const cart = await this . cartService . restartCart ( args . cartId ) ;
156162
@@ -162,6 +168,7 @@ export class NextJSActionsService {
162168 } )
163169 @NextIOValidator ( SetupCartActionArgs , SetupCartActionResult )
164170 @WithTypeCachableAsyncLocalStorage ( )
171+ @CaptureTimingWithStatsD ( )
165172 async setupCart ( args : {
166173 interval : SubplatInterval ;
167174 offeringConfigId : string ;
@@ -180,6 +187,7 @@ export class NextJSActionsService {
180187 @SanitizeExceptions ( )
181188 @NextIOValidator ( FinalizeCartWithErrorArgs , undefined )
182189 @WithTypeCachableAsyncLocalStorage ( )
190+ @CaptureTimingWithStatsD ( )
183191 async finalizeCartWithError ( args : {
184192 cartId : string ;
185193 errorReasonId : CartErrorReasonId ;
@@ -193,13 +201,15 @@ export class NextJSActionsService {
193201 @SanitizeExceptions ( )
194202 @NextIOValidator ( FinalizeProcessingCartActionArgs , undefined )
195203 @WithTypeCachableAsyncLocalStorage ( )
204+ @CaptureTimingWithStatsD ( )
196205 async finalizeProcessingCart ( args : { cartId : string } ) {
197206 await this . cartService . finalizeProcessingCart ( args . cartId ) ;
198207 }
199208
200209 @SanitizeExceptions ( )
201210 @NextIOValidator ( GetPayPalCheckoutTokenArgs , GetPayPalCheckoutTokenResult )
202211 @WithTypeCachableAsyncLocalStorage ( )
212+ @CaptureTimingWithStatsD ( )
203213 async getPayPalCheckoutToken ( args : { currencyCode : string } ) {
204214 const token = await this . checkoutTokenManager . get ( args . currencyCode ) ;
205215
@@ -211,6 +221,7 @@ export class NextJSActionsService {
211221 @SanitizeExceptions ( )
212222 @NextIOValidator ( GetTaxAddressArgs , GetTaxAddressResult )
213223 @WithTypeCachableAsyncLocalStorage ( )
224+ @CaptureTimingWithStatsD ( )
214225 async getTaxAddress ( args : { ipAddress : string ; uid ?: string } ) {
215226 const result = await this . taxService . getTaxAddress (
216227 args . ipAddress ,
@@ -223,6 +234,7 @@ export class NextJSActionsService {
223234 @SanitizeExceptions ( )
224235 @NextIOValidator ( CheckoutCartWithPaypalActionArgs , undefined )
225236 @WithTypeCachableAsyncLocalStorage ( )
237+ @CaptureTimingWithStatsD ( )
226238 async checkoutCartWithPaypal ( args : {
227239 cartId : string ;
228240 version : number ;
@@ -240,6 +252,7 @@ export class NextJSActionsService {
240252 @SanitizeExceptions ( )
241253 @NextIOValidator ( CheckoutCartWithStripeActionArgs , undefined )
242254 @WithTypeCachableAsyncLocalStorage ( )
255+ @CaptureTimingWithStatsD ( )
243256 async checkoutCartWithStripe ( args : {
244257 cartId : string ;
245258 version : number ;
@@ -257,6 +270,7 @@ export class NextJSActionsService {
257270 @SanitizeExceptions ( { allowlist : [ ProductConfigError ] } )
258271 @NextIOValidator ( FetchCMSDataActionArgs , FetchCMSDataActionResult )
259272 @WithTypeCachableAsyncLocalStorage ( )
273+ @CaptureTimingWithStatsD ( )
260274 async fetchCMSData ( args : {
261275 offeringId : string ;
262276 acceptLanguage ?: string | null ;
@@ -274,6 +288,7 @@ export class NextJSActionsService {
274288 @SanitizeExceptions ( )
275289 @NextIOValidator ( RecordEmitterEventArgs , undefined )
276290 @WithTypeCachableAsyncLocalStorage ( )
291+ @CaptureTimingWithStatsD ( )
277292 async recordEmitterEvent ( args : {
278293 eventName : string ;
279294 requestArgs : CommonMetrics ;
@@ -307,6 +322,7 @@ export class NextJSActionsService {
307322 @SanitizeExceptions ( )
308323 @NextIOValidator ( GetNeedsInputActionArgs , getNeedsInputActionResult )
309324 @WithTypeCachableAsyncLocalStorage ( )
325+ @CaptureTimingWithStatsD ( )
310326 async getNeedsInput ( args : { cartId : string } ) {
311327 return await this . cartService . getNeedsInput ( args . cartId ) ;
312328 }
@@ -316,19 +332,22 @@ export class NextJSActionsService {
316332 } )
317333 @NextIOValidator ( SubmitNeedsInputActionArgs , undefined )
318334 @WithTypeCachableAsyncLocalStorage ( )
335+ @CaptureTimingWithStatsD ( )
319336 async submitNeedsInput ( args : { cartId : string } ) {
320337 await this . cartService . submitNeedsInput ( args . cartId ) ;
321338 }
322339
323340 @SanitizeExceptions ( )
324341 @NextIOValidator ( undefined , GetMetricsFlowActionResult )
342+ @CaptureTimingWithStatsD ( )
325343 async getMetricsFlow ( ) {
326344 return this . contentServerManager . getMetricsFlow ( ) ;
327345 }
328346
329347 @SanitizeExceptions ( )
330348 @NextIOValidator ( ValidatePostalCodeActionArgs , ValidatePostalCodeActionResult )
331349 @WithTypeCachableAsyncLocalStorage ( )
350+ @CaptureTimingWithStatsD ( )
332351 async validateAndFormatPostalCode ( args : {
333352 postalCode : string ;
334353 countryCode : string ;
@@ -342,6 +361,7 @@ export class NextJSActionsService {
342361 @SanitizeExceptions ( )
343362 @NextIOValidator ( DetermineCurrencyActionArgs , DetermineCurrencyActionResult )
344363 @WithTypeCachableAsyncLocalStorage ( )
364+ @CaptureTimingWithStatsD ( )
345365 async determineCurrency ( args : { ip : string } ) {
346366 const location = this . geodbManager . getTaxAddress ( args . ip ) ;
347367
@@ -361,6 +381,7 @@ export class NextJSActionsService {
361381 @SanitizeExceptions ( )
362382 @NextIOValidator ( UpdateTaxAddressActionArgs , UpdateTaxAddressActionResult )
363383 @WithTypeCachableAsyncLocalStorage ( )
384+ @CaptureTimingWithStatsD ( )
364385 async updateTaxAddress ( args : {
365386 cartId : string ;
366387 version : number ;
@@ -416,6 +437,7 @@ export class NextJSActionsService {
416437 @SanitizeExceptions ( )
417438 @NextIOValidator ( ValidateLocationActionArgs , ValidateLocationActionResult )
418439 @WithTypeCachableAsyncLocalStorage ( )
440+ @CaptureTimingWithStatsD ( )
419441 async validateLocation ( args : {
420442 offeringId : string ;
421443 taxAddress ?: TaxAddress ;
0 commit comments