github.com/newrelic/newrelic-client-go@v1.1.0/pkg/apm/example_key_transaction_test.go (about)

     1  package apm
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"os"
     7  
     8  	"github.com/newrelic/newrelic-client-go/pkg/config"
     9  )
    10  
    11  func Example_keyTransaction() {
    12  	// Initialize the client configuration. A Personal API key is required to
    13  	// communicate with the backend API.
    14  	cfg := config.New()
    15  	cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY")
    16  
    17  	// Initialize the client.
    18  	client := New(cfg)
    19  
    20  	// Search the key transactions for the current account by name.
    21  	listParams := &ListKeyTransactionsParams{
    22  		Name: "Example key transaction",
    23  	}
    24  
    25  	transactions, err := client.ListKeyTransactions(listParams)
    26  	if err != nil {
    27  		log.Fatal("error listing key transactions:", err)
    28  	}
    29  
    30  	// Get a key transaction by ID.  This example assumes that at least one key
    31  	// transaction has been returned by the list endpoint, but in practice it is
    32  	// possible that an empty slice is returned.
    33  	transaction, err := client.GetKeyTransaction(transactions[0].ID)
    34  	if err != nil {
    35  		log.Fatal("error getting key transaction:", err)
    36  	}
    37  
    38  	// Output the key transaction's health status.
    39  	fmt.Printf("Key transaction status: %s\n", transaction.HealthStatus)
    40  }