github.com/newrelic/newrelic-client-go@v1.1.0/pkg/apm/key_transactions.go (about) 1 package apm 2 3 import ( 4 "context" 5 "fmt" 6 ) 7 8 // KeyTransaction represents information about a New Relic key transaction. 9 type KeyTransaction struct { 10 ID int `json:"id,omitempty"` 11 Name string `json:"name,omitempty"` 12 TransactionName string `json:"transaction_name,omitempty"` 13 HealthStatus string `json:"health_status,omitempty"` 14 LastReportedAt string `json:"last_reported_at,omitempty"` 15 Reporting bool `json:"reporting"` 16 Summary ApplicationSummary `json:"application_summary,omitempty"` 17 EndUserSummary ApplicationEndUserSummary `json:"end_user_summary,omitempty"` 18 Links KeyTransactionLinks `json:"links,omitempty"` 19 } 20 21 // KeyTransactionLinks represents associations for a key transaction. 22 type KeyTransactionLinks struct { 23 Application int `json:"application,omitempty"` 24 } 25 26 // ListKeyTransactionsParams represents a set of filters to be 27 // used when querying New Relic key transactions. 28 type ListKeyTransactionsParams struct { 29 Name string `url:"filter[name],omitempty"` 30 IDs []int `url:"filter[ids],omitempty,comma"` 31 } 32 33 // ListKeyTransactions returns all key transactions for an account. 34 func (a *APM) ListKeyTransactions(params *ListKeyTransactionsParams) ([]*KeyTransaction, error) { 35 return a.ListKeyTransactionsWithContext(context.Background(), params) 36 } 37 38 // ListKeyTransactionsWithContext returns all key transactions for an account. 39 func (a *APM) ListKeyTransactionsWithContext(ctx context.Context, params *ListKeyTransactionsParams) ([]*KeyTransaction, error) { 40 results := []*KeyTransaction{} 41 nextURL := a.config.Region().RestURL("key_transactions.json") 42 43 for nextURL != "" { 44 response := keyTransactionsResponse{} 45 resp, err := a.client.GetWithContext(ctx, nextURL, ¶ms, &response) 46 47 if err != nil { 48 return nil, err 49 } 50 51 results = append(results, response.KeyTransactions...) 52 53 paging := a.pager.Parse(resp) 54 nextURL = paging.Next 55 } 56 57 return results, nil 58 } 59 60 // GetKeyTransaction returns a specific key transaction by ID. 61 func (a *APM) GetKeyTransaction(id int) (*KeyTransaction, error) { 62 return a.GetKeyTransactionWithContext(context.Background(), id) 63 } 64 65 // GetKeyTransactionWithContext returns a specific key transaction by ID. 66 func (a *APM) GetKeyTransactionWithContext(ctx context.Context, id int) (*KeyTransaction, error) { 67 response := keyTransactionResponse{} 68 url := fmt.Sprintf("/key_transactions/%d.json", id) 69 70 _, err := a.client.GetWithContext(ctx, a.config.Region().RestURL(url), nil, &response) 71 72 if err != nil { 73 return nil, err 74 } 75 76 return &response.KeyTransaction, nil 77 } 78 79 type keyTransactionsResponse struct { 80 KeyTransactions []*KeyTransaction `json:"key_transactions,omitempty"` 81 } 82 83 type keyTransactionResponse struct { 84 KeyTransaction KeyTransaction `json:"key_transaction,omitempty"` 85 }