1
0

application.go 2.7 KB

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