transport

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2021 License: Apache-2.0 Imports: 25 Imported by: 21

Documentation

Overview

Package transport provides an interface and implementation for transporting data to the Elastic APM server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPError

type HTTPError struct {
	Response *http.Response
	Message  string
}

HTTPError is an error returned by HTTPTransport methods when requests fail.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type HTTPTransport

type HTTPTransport struct {
	// Client exposes the http.Client used by the HTTPTransport for
	// sending requests to the APM Server.
	Client *http.Client
	// contains filtered or unexported fields
}

HTTPTransport is an implementation of Transport, sending payloads via a net/http client.

func NewHTTPTransport

func NewHTTPTransport() (*HTTPTransport, error)

NewHTTPTransport returns a new HTTPTransport which can be used for streaming data to the APM Server. The returned HTTPTransport will be initialized using the following environment variables:

  • ELASTIC_APM_SERVER_URL: the APM Server URL used for sending requests. If no URL is specified, then the transport will use the default URL "http://localhost:8200".
  • ELASTIC_APM_SERVER_TIMEOUT: timeout for requests to the APM Server. If not specified, defaults to 30 seconds.

- ELASTIC_APM_SECRET_TOKEN: used to authenticate the agent.

  • ELASTIC_APM_SERVER_CERT: path to a PEM-encoded certificate that must match the APM Server-supplied certificate. This can be used to pin a self signed certificate. If this is set, then ELASTIC_APM_VERIFY_SERVER_CERT is ignored.
  • ELASTIC_APM_VERIFY_SERVER_CERT: if set to "false", the transport will not verify the APM Server's TLS certificate. Only relevant when using HTTPS. By default, the transport will verify server certificates.

func (*HTTPTransport) SendProfile added in v1.6.0

func (t *HTTPTransport) SendProfile(
	ctx context.Context,
	metadataReader io.Reader,
	profileReaders ...io.Reader,
) error

SendProfile sends a symbolised pprof profile, encoded as protobuf, and gzip-compressed.

NOTE this is an experimental API, and may be removed in a future minor version, without being considered a breaking change.

func (*HTTPTransport) SendStream added in v1.0.0

func (t *HTTPTransport) SendStream(ctx context.Context, r io.Reader) error

SendStream sends the stream over HTTP. If SendStream returns an error and the transport is configured with more than one APM Server URL, then the following request will be sent to the next URL in the list.

func (*HTTPTransport) SetAPIKey added in v1.7.0

func (t *HTTPTransport) SetAPIKey(apiKey string)

SetAPIKey sets the Authorization header with the given API Key.

This overrides the value specified via the ELASTIC_APM_SECRET_TOKEN or ELASTIC_APM_API_KEY environment variables, if either are set.

func (*HTTPTransport) SetSecretToken added in v1.0.0

func (t *HTTPTransport) SetSecretToken(secretToken string)

SetSecretToken sets the Authorization header with the given secret token.

This overrides the value specified via the ELASTIC_APM_SECRET_TOKEN or ELASTIC_APM_API_KEY environment variables, if either are set.

func (*HTTPTransport) SetServerURL added in v1.0.0

func (t *HTTPTransport) SetServerURL(u ...*url.URL)

SetServerURL sets the APM Server URL (or URLs) for sending requests. At least one URL must be specified, or the method will panic. The list will be randomly shuffled.

func (*HTTPTransport) SetUserAgent added in v1.0.0

func (t *HTTPTransport) SetUserAgent(ua string)

SetUserAgent sets the User-Agent header that will be sent with each request.

func (*HTTPTransport) WatchConfig added in v1.5.0

func (t *HTTPTransport) WatchConfig(ctx context.Context, args apmconfig.WatchParams) <-chan apmconfig.Change

WatchConfig polls the APM Server for agent config changes, sending them over the returned channel.

type Transport

type Transport interface {
	// SendStream sends a data stream to the server, returning when the
	// stream has been closed (Read returns io.EOF) or the HTTP request
	// terminates.
	SendStream(context.Context, io.Reader) error
}

Transport provides an interface for sending streams of encoded model entities to the Elastic APM server, and for querying config. Methods are not required to be safe for concurrent use.

var (
	// Default is the default Transport, using the
	// ELASTIC_APM_* environment variables.
	//
	// If ELASTIC_APM_SERVER_URL is set to an invalid
	// location, Default will be set to a Transport
	// returning an error for every operation.
	Default Transport

	// Discard is a Transport on which all operations
	// succeed without doing anything.
	Discard = discardTransport{}
)

func InitDefault

func InitDefault() (Transport, error)

InitDefault (re-)initializes Default, the default Transport, returning its new value along with the error that will be returned by the Transport if the environment variable configuration is invalid. The result is always non-nil.

Directories

Path Synopsis
Package transporttest provides implementations of transport.Transport for testing purposes.
Package transporttest provides implementations of transport.Transport for testing purposes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL