github.com/newrelic/go-agent@v3.26.0+incompatible/application.go (about) 1 // Copyright 2020 New Relic Corporation. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package newrelic 5 6 import ( 7 "net/http" 8 "time" 9 ) 10 11 // Application represents your application. 12 type Application interface { 13 // StartTransaction begins a Transaction. 14 // * Transaction.NewGoroutine() must be used to pass the Transaction 15 // between goroutines. 16 // * This method never returns nil. 17 // * The Transaction is considered a web transaction if an http.Request 18 // is provided. 19 // * The transaction returned implements the http.ResponseWriter 20 // interface. Provide your ResponseWriter as a parameter and 21 // then use the Transaction in its place to instrument the response 22 // code and response headers. 23 StartTransaction(name string, w http.ResponseWriter, r *http.Request) Transaction 24 25 // RecordCustomEvent adds a custom event. 26 // 27 // eventType must consist of alphanumeric characters, underscores, and 28 // colons, and must contain fewer than 255 bytes. 29 // 30 // Each value in the params map must be a number, string, or boolean. 31 // Keys must be less than 255 bytes. The params map may not contain 32 // more than 64 attributes. For more information, and a set of 33 // restricted keywords, see: 34 // 35 // https://docs.newrelic.com/docs/insights/new-relic-insights/adding-querying-data/inserting-custom-events-new-relic-apm-agents 36 // 37 // An error is returned if event type or params is invalid. 38 RecordCustomEvent(eventType string, params map[string]interface{}) error 39 40 // RecordCustomMetric records a custom metric. The metric name you 41 // provide will be prefixed by "Custom/". Custom metrics are not 42 // currently supported in serverless mode. 43 // 44 // https://docs.newrelic.com/docs/agents/manage-apm-agents/agent-data/collect-custom-metrics 45 RecordCustomMetric(name string, value float64) error 46 47 // WaitForConnection blocks until the application is connected, is 48 // incapable of being connected, or the timeout has been reached. This 49 // method is useful for short-lived processes since the application will 50 // not gather data until it is connected. nil is returned if the 51 // application is connected successfully. 52 WaitForConnection(timeout time.Duration) error 53 54 // Shutdown flushes data to New Relic's servers and stops all 55 // agent-related goroutines managing this application. After Shutdown 56 // is called, The application is disabled and will never collect data 57 // again. This method blocks until all final data is sent to New Relic 58 // or the timeout has elapsed. Increase the timeout and check debug 59 // logs if you aren't seeing data. 60 Shutdown(timeout time.Duration) 61 } 62 63 // NewApplication creates an Application and spawns goroutines to manage the 64 // aggregation and harvesting of data. On success, a non-nil Application and a 65 // nil error are returned. On failure, a nil Application and a non-nil error 66 // are returned. Applications do not share global state, therefore it is safe 67 // to create multiple applications. 68 func NewApplication(c Config) (Application, error) { 69 return newApp(c) 70 }