Skip to content

Commit

Permalink
feat(metrics): add operator metric attributes in modulr calls
Browse files Browse the repository at this point in the history
  • Loading branch information
laouji authored and paul-nicolas committed Dec 16, 2024
1 parent 0e9b922 commit c31dd58
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 36 deletions.
12 changes: 4 additions & 8 deletions internal/connectors/plugins/public/modulr/client/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/http"
"strconv"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
)

//nolint:tagliatelle // allow for clients
Expand All @@ -26,10 +28,7 @@ type Account struct {
}

func (c *client) GetAccounts(ctx context.Context, page, pageSize int, fromCreatedAt time.Time) ([]Account, error) {
// TODO(polo): add metrics
// f := connectors.ClientMetrics(ctx, "modulr", "list_accounts")
// now := time.Now()
// defer f(ctx, now)
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_accounts")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.buildEndpoint("accounts"), http.NoBody)
if err != nil {
Expand All @@ -56,10 +55,7 @@ func (c *client) GetAccounts(ctx context.Context, page, pageSize int, fromCreate
}

func (c *client) GetAccount(ctx context.Context, accountID string) (*Account, error) {
// TODO(polo): add metrics
// f := connectors.ClientMetrics(ctx, "modulr", "list_accounts")
// now := time.Now()
// defer f(ctx, now)
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "get_account")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.buildEndpoint("accounts/%s", accountID), http.NoBody)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/http"
"strconv"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
)

type Beneficiary struct {
Expand All @@ -15,10 +17,7 @@ type Beneficiary struct {
}

func (c *client) GetBeneficiaries(ctx context.Context, page, pageSize int, modifiedSince time.Time) ([]Beneficiary, error) {
// TODO(polo): add metrics
// f := connectors.ClientMetrics(ctx, "modulr", "list_beneficiaries")
// now := time.Now()
// defer f(ctx, now)
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_beneficiaries")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.buildEndpoint("beneficiaries"), http.NoBody)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/connectors/plugins/public/modulr/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func New(apiKey, apiSecret, endpoint string) (Client, error) {
return nil, fmt.Errorf("failed to generate headers: %w", err)
}
config := &httpwrapper.Config{
CommonMetricsAttributes: httpwrapper.CommonMetricsAttributesFor("modulr"),
Transport: &apiTransport{
headers: headers,
apiKey: apiKey,
Expand Down
7 changes: 3 additions & 4 deletions internal/connectors/plugins/public/modulr/client/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"net/http"
"strconv"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
)

type PaymentType string
Expand Down Expand Up @@ -37,10 +39,7 @@ type Payment struct {
}

func (c *client) GetPayments(ctx context.Context, paymentType PaymentType, page, pageSize int, modifiedSince time.Time) ([]Payment, error) {
// TODO(polo): add metrics
// f := connectors.ClientMetrics(ctx, "modulr", "list_payments")
// now := time.Now()
// defer f(ctx, now)
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_payments")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.buildEndpoint("payments"), http.NoBody)
if err != nil {
Expand Down
12 changes: 4 additions & 8 deletions internal/connectors/plugins/public/modulr/client/payout.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"encoding/json"
"fmt"
"net/http"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
)

type PayoutRequest struct {
Expand All @@ -29,10 +31,7 @@ type PayoutResponse struct {
}

func (c *client) InitiatePayout(ctx context.Context, payoutRequest *PayoutRequest) (*PayoutResponse, error) {
// TODO(polo): add metrics
// f := connectors.ClientMetrics(ctx, "modulr", "initiate_payout")
// now := time.Now()
// defer f(ctx, now)
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "initiate_payout")

body, err := json.Marshal(payoutRequest)
if err != nil {
Expand All @@ -56,10 +55,7 @@ func (c *client) InitiatePayout(ctx context.Context, payoutRequest *PayoutReques
}

func (c *client) GetPayout(ctx context.Context, payoutID string) (PayoutResponse, error) {
// TODO(polo): add metrics
// f := connectors.ClientMetrics(ctx, "modulr", "get_payout")
// now := time.Now()
// defer f(ctx, now)
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "get_payout")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.buildEndpoint("payments?id=%s", payoutID), nil)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"net/http"
"strconv"
"time"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
)

//nolint:tagliatelle // allow different styled tags in client
Expand All @@ -24,10 +26,7 @@ type Transaction struct {
}

func (c *client) GetTransactions(ctx context.Context, accountID string, page, pageSize int, fromTransactionDate time.Time) ([]Transaction, error) {
// TODO(polo): add metrics
// f := connectors.ClientMetrics(ctx, "modulr", "list_transactions")
// now := time.Now()
// defer f(ctx, now)
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "list_transactions")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.buildEndpoint("accounts/%s/transactions", accountID), http.NoBody)
if err != nil {
Expand Down
12 changes: 4 additions & 8 deletions internal/connectors/plugins/public/modulr/client/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"encoding/json"
"fmt"
"net/http"

"github.com/formancehq/payments/internal/connectors/httpwrapper"
)

type DestinationType string
Expand Down Expand Up @@ -52,10 +54,7 @@ type TransferResponse struct {
}

func (c *client) InitiateTransfer(ctx context.Context, transferRequest *TransferRequest) (*TransferResponse, error) {
// TODO(polo): add metrics
// f := connectors.ClientMetrics(ctx, "modulr", "initiate_transfer")
// now := time.Now()
// defer f(ctx, now)
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "initiate_transfer")

body, err := json.Marshal(transferRequest)
if err != nil {
Expand All @@ -79,10 +78,7 @@ func (c *client) InitiateTransfer(ctx context.Context, transferRequest *Transfer
}

func (c *client) GetTransfer(ctx context.Context, transferID string) (TransferResponse, error) {
// TODO(polo): add metrics
// f := connectors.ClientMetrics(ctx, "modulr", "get_transfer")
// now := time.Now()
// defer f(ctx, now)
ctx = context.WithValue(ctx, httpwrapper.MetricOperationContextKey, "get_transfer")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.buildEndpoint("payments?id=%s", transferID), nil)
if err != nil {
Expand Down

0 comments on commit c31dd58

Please sign in to comment.