internal

package
v2.5.0-dev Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

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

type Range[T cmp.Ordered] struct {
	Min T
	Max T
}

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.

func (Range[T]) Contains

func (r Range[T]) Contains(value T) bool

Contains checks if a value is within the range.

func (Range[T]) IsOrdered

func (r Range[T]) IsOrdered() bool

IsOrdered checks if the range is ordered. e.g. Min <= Max.

func (Range[T]) ReduceMax

func (r Range[T]) ReduceMax(value T) Range[T]

ReduceMax returns a new range where value is the new max and min is either the current min or the new value to make sure the range is ordered.

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

func NewRecorder[T any]() Recorder[T]

NewRecorder creates a new Recorder instance. with 512 as the maximum number of recorded functions before overflowing.

func (Recorder[T]) Clear

func (r Recorder[T]) Clear()

Clear clears the Recorder's queue.

func (Recorder[T]) Record

func (r Recorder[T]) Record(f func(T)) bool

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.

func (Recorder[T]) Replay

func (r Recorder[T]) Replay(t T)

Replay uses T as an argument to replay all recorded functions 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

func NewRingQueue[T any](rang Range[int]) *RingQueue[T]

NewRingQueue creates a new RingQueue with a minimum size and a maximum size.

func NewRingQueueWithPool

func NewRingQueueWithPool[T any](rang Range[int], pool *SyncPool[[]T]) *RingQueue[T]

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

func (rq *RingQueue[T]) Enqueue(vals ...T) bool

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]) IsEmpty

func (rq *RingQueue[T]) IsEmpty() bool

IsEmpty returns true if the buffer is empty.

func (*RingQueue[T]) IsFull

func (rq *RingQueue[T]) IsFull() bool

IsFull returns true if the buffer is full and cannot accept more elements.

func (*RingQueue[T]) Length

func (rq *RingQueue[T]) Length() int

Length returns the number of elements currently stored in the queue.

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.

func (*SumReaderCloser) Read

func (s *SumReaderCloser) Read(p []byte) (n int, err error)

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

func NewSyncPool[T any](newT func() T) *SyncPool[T]

NewSyncPool creates a new Pool with the given new function.

func (*SyncPool[T]) Get

func (sp *SyncPool[T]) Get() T

func (*SyncPool[T]) Put

func (sp *SyncPool[T]) Put(v T)

type TickFunc

type TickFunc func()

type Ticker

type Ticker struct {
	// contains filtered or unexported fields
}

func NewTicker

func NewTicker(tickFunc TickFunc, interval Range[time.Duration]) *Ticker

func (*Ticker) CanDecreaseSpeed

func (t *Ticker) CanDecreaseSpeed()

func (*Ticker) CanIncreaseSpeed

func (t *Ticker) CanIncreaseSpeed()

func (*Ticker) Stop

func (t *Ticker) Stop()

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

type WriterStatusCodeError struct {
	Status string
	Body   string
}

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

Directories

Path Synopsis
generator command

Jump to

Keyboard shortcuts

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