Documentation
¶
Index ¶
- type EndpointRequestResult
- type Range
- type RecordWriter
- type Recorder
- type RingQueue
- func (rq *RingQueue[T]) Clear()
- func (rq *RingQueue[T]) Dequeue() T
- func (rq *RingQueue[T]) Enqueue(vals ...T) bool
- func (rq *RingQueue[T]) Flush() []T
- func (rq *RingQueue[T]) IsEmpty() bool
- func (rq *RingQueue[T]) IsFull() bool
- func (rq *RingQueue[T]) Length() int
- func (rq *RingQueue[T]) ReversePeek() T
- type SumReaderCloser
- type SyncPool
- type TickFunc
- type Ticker
- type TracerConfig
- type Writer
- type WriterConfig
- type WriterStatusCodeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EndpointRequestResult ¶
type EndpointRequestResult struct {
// Error is the error that occurred when sending the payload to the endpoint. This is nil if the payload was sent successfully.
Error error
// PayloadByteSize is the number of bytes that were sent to the endpoint, zero if the payload was not sent.
PayloadByteSize int
// CallDuration is the duration of the call to the endpoint if the call was successful
CallDuration time.Duration
// StatusCode is the status code of the response from the endpoint even if the call failed but only with an actual HTTP error
StatusCode int
}
EndpointRequestResult is returned by the Flush method of the Writer interface.
type Range ¶
Range is a type that represents a range of values.
func (Range[T]) Clamp ¶
func (r Range[T]) Clamp(value T) T
Clamp squeezes a value between a minimum and maximum value.
type RecordWriter ¶
type RecordWriter struct {
// contains filtered or unexported fields
}
RecordWriter is a Writer that stores the payloads in memory. Used for testing purposes
func (*RecordWriter) Flush ¶
func (w *RecordWriter) Flush(payload transport.Payload) ([]EndpointRequestResult, error)
func (*RecordWriter) Payloads ¶
func (w *RecordWriter) Payloads() []transport.Payload
type Recorder ¶
type Recorder[T any] struct { // contains filtered or unexported fields }
Recorder is a generic thread-safe type that records functions that could have taken place before object T was created. Once object T is created, the Recorder can replay all the recorded functions with object T as an argument.
func NewRecorder ¶
NewRecorder creates a new Recorder instance. with 512 as the maximum number of recorded functions before overflowing.
func (Recorder[T]) Record ¶
Record takes a function and records it in the Recorder's queue. If the queue is full, it returns false. Once Recorder.Replay is called, all recorded functions will be replayed with object T as an argument in order of recording.
type RingQueue ¶
type RingQueue[T any] struct { // BufferSizes is the range of buffer sizes that the ring queue can have. BufferSizes Range[int] // contains filtered or unexported fields }
RingQueue is a thread-safe ring buffer can be used to store a fixed number of elements and overwrite old values when full.
func NewRingQueue ¶
NewRingQueue creates a new RingQueue with a minimum size and a maximum size.
func NewRingQueueWithPool ¶
NewRingQueueWithPool creates a new RingQueue with a minimum size, a maximum size and a pool. Make sure the pool is properly initialized with the right type
func (*RingQueue[T]) Clear ¶
func (rq *RingQueue[T]) Clear()
Clear removes all elements from the buffer.
func (*RingQueue[T]) Dequeue ¶
func (rq *RingQueue[T]) Dequeue() T
Dequeue removes a value from the buffer.
func (*RingQueue[T]) Enqueue ¶
Enqueue adds one or multiple values to the buffer. Returns false if at least one item had to be pulled out from the queue to make space for new ones
func (*RingQueue[T]) Flush ¶
func (rq *RingQueue[T]) Flush() []T
Flush returns a copy of the buffer and resets it.
func (*RingQueue[T]) IsFull ¶
IsFull returns true if the buffer is full and cannot accept more elements.
func (*RingQueue[T]) ReversePeek ¶
func (rq *RingQueue[T]) ReversePeek() T
ReversePeek returns the last element that was enqueued without removing it.
type SumReaderCloser ¶
type SumReaderCloser struct {
io.ReadCloser
// contains filtered or unexported fields
}
SumReaderCloser is a ReadCloser that wraps another ReadCloser and counts the number of bytes read.
type SyncPool ¶
type SyncPool[T any] struct { // contains filtered or unexported fields }
SyncPool is a wrapper around sync.Pool that provides type safety.
func NewSyncPool ¶
NewSyncPool creates a new Pool with the given new function.
type Ticker ¶
type Ticker struct {
// contains filtered or unexported fields
}
func (*Ticker) CanDecreaseSpeed ¶
func (t *Ticker) CanDecreaseSpeed()
func (*Ticker) CanIncreaseSpeed ¶
func (t *Ticker) CanIncreaseSpeed()
type TracerConfig ¶
type TracerConfig struct {
// Service is the name of the service being traced.
Service string
// Env is the environment the service is running in.
Env string
// Version is the version of the service.
Version string
}
TracerConfig is the configuration for the tracer for the telemetry client.
type Writer ¶
type Writer interface {
// Flush does a synchronous call to the telemetry endpoint with the given payload. Thread-safe.
// It returns a non-empty [EndpointRequestResult] slice and a nil error if the payload was sent successfully.
// Otherwise, the error is a call to [errors.Join] on all errors that occurred.
Flush(transport.Payload) ([]EndpointRequestResult, error)
}
Writer is an interface that allows to send telemetry data to any endpoint that implements the instrumentation telemetry v2 API. The telemetry data is sent as a JSON payload as described in the API documentation.
func NewWriter ¶
func NewWriter(config WriterConfig) (Writer, error)
type WriterConfig ¶
type WriterConfig struct {
// TracerConfig is the configuration the tracer sent when the telemetry client was created (required)
TracerConfig
// Endpoints is a list of requests that will be used alongside the body of the telemetry data to create the requests to the telemetry endpoint (required to not be empty)
// The writer will try each endpoint in order until it gets a 2XX HTTP response from the server
Endpoints []*http.Request
// HTTPClient is the http client that will be used to send the telemetry data (defaults to a copy of [http.DefaultClient])
HTTPClient *http.Client
// Debug is a flag that indicates whether the telemetry client is in debug mode (defaults to false)
Debug bool
}
type WriterStatusCodeError ¶
WriterStatusCodeError is an error that is returned when the writer receives an unexpected status code from the server.
func (*WriterStatusCodeError) Error ¶
func (w *WriterStatusCodeError) Error() string