github.com/lulzWill/go-agent@v2.1.2+incompatible/application.go (about)

     1  package newrelic
     2  
     3  import (
     4  	"net/http"
     5  	"time"
     6  )
     7  
     8  // Application represents your application.
     9  type Application interface {
    10  	// StartTransaction begins a Transaction.
    11  	// * The Transaction should only be used in a single goroutine.
    12  	// * This method never returns nil.
    13  	// * If an http.Request is provided then the Transaction is considered
    14  	//   a web transaction.
    15  	// * If an http.ResponseWriter is provided then the Transaction can be
    16  	//   used in its place.  This allows instrumentation of the response
    17  	//   code and response headers.
    18  	StartTransaction(name string, w http.ResponseWriter, r *http.Request) Transaction
    19  
    20  	// RecordCustomEvent adds a custom event to the application.  This
    21  	// feature is incompatible with high security mode.
    22  	//
    23  	// eventType must consist of alphanumeric characters, underscores, and
    24  	// colons, and must contain fewer than 255 bytes.
    25  	//
    26  	// Each value in the params map must be a number, string, or boolean.
    27  	// Keys must be less than 255 bytes.  The params map may not contain
    28  	// more than 64 attributes.  For more information, and a set of
    29  	// restricted keywords, see:
    30  	//
    31  	// https://docs.newrelic.com/docs/insights/new-relic-insights/adding-querying-data/inserting-custom-events-new-relic-apm-agents
    32  	RecordCustomEvent(eventType string, params map[string]interface{}) error
    33  
    34  	// RecordCustomMetric records a custom metric.  NOTE! The name you give
    35  	// will be prefixed by "Custom/".
    36  	//
    37  	// https://docs.newrelic.com/docs/agents/manage-apm-agents/agent-data/collect-custom-metrics
    38  	RecordCustomMetric(name string, value float64) error
    39  
    40  	// WaitForConnection blocks until the application is connected, is
    41  	// incapable of being connected, or the timeout has been reached.  This
    42  	// method is useful for short-lived processes since the application will
    43  	// not gather data until it is connected.  nil is returned if the
    44  	// application is connected successfully.
    45  	WaitForConnection(timeout time.Duration) error
    46  
    47  	// Shutdown flushes data to New Relic's servers and stops all
    48  	// agent-related goroutines managing this application.  After Shutdown
    49  	// is called, the application is disabled and no more data will be
    50  	// collected.  This method will block until all final data is sent to
    51  	// New Relic or the timeout has elapsed.
    52  	Shutdown(timeout time.Duration)
    53  
    54  	Flush()
    55  }
    56  
    57  // NewApplication creates an Application and spawns goroutines to manage the
    58  // aggregation and harvesting of data.  On success, a non-nil Application and a
    59  // nil error are returned. On failure, a nil Application and a non-nil error
    60  // are returned.
    61  //
    62  // Applications do not share global state (other than the shared log.Logger).
    63  // Therefore, it is safe to create multiple applications.
    64  func NewApplication(c Config) (Application, error) {
    65  	return newApp(c)
    66  }