Documentation ¶
Index ¶
- Constants
- func Divide(numerator, denominator int) ([]int, error)
- func EnvelopeFromBody(eventID string, sentAt time.Time, eventType string, ...) (*bytes.Buffer, error)
- func ExponentialBackoff(initial time.Duration, maximum time.Duration, factor float64) func() time.Duration
- func FileExists(fileName string) bool
- func GetAuthHeader(projectKey string) string
- func GetExternalIPv4() (string, error)
- func GetStatsd(statsdAddr string) *statsd.Client
- func LowerFirstLetter(s string) string
- func Min(a, b int) int
- func PerSecond(elements int64, interval time.Duration) (float64, error)
- func PrivateKeyFromString(public string, private string) (ed25519.PrivateKey, error)
- func RandomChoice(choices []string, relativeWeights []int64) (string, error)
- func RegisterProjectProvider(projectsFileName string) error
- func RelayAuthSign(privateKey ed25519.PrivateKey, data []byte, timestamp time.Time) (string, error)
- func SimpleRandomChoice(choices []string) string
- func UuidAsHex(id uuid.UUID) string
- type FileProjectProvider
- func (provider FileProjectProvider) GetNextProjectId(maxProjects int, currentProjectId string) string
- func (provider FileProjectProvider) GetNumberOfProjects() int
- func (provider FileProjectProvider) GetProjectId(maxProjects int) string
- func (provider FileProjectProvider) GetProjectIdV2(profiles []ProjectFreqProfile) (string, int, error)
- func (provider FileProjectProvider) GetProjectInfo(projectId string) ProjectInfo
- type ProjectFreqProfile
- type ProjectInfo
- type ProjectProvider
- type RandomProjectProvider
- func (provider RandomProjectProvider) GetNextProjectId(maxProjects int, currentProjectId string) string
- func (provider RandomProjectProvider) GetNumberOfProjects() int
- func (provider RandomProjectProvider) GetProjectId(maxProjects int) string
- func (provider RandomProjectProvider) GetProjectIdV2(profiles []ProjectFreqProfile) (string, int, error)
- func (provider RandomProjectProvider) GetProjectInfo(projectId string) ProjectInfo
- type StringDuration
Constants ¶
const NegativeDivision = errorString("cannot divide a number into a number of parts <=0")
Variables ¶
This section is empty.
Functions ¶
func EnvelopeFromBody ¶
func EnvelopeFromBody(eventID string, sentAt time.Time, eventType string, extraHeaders map[string]string, body json.RawMessage) (*bytes.Buffer, error)
EnvelopeFromBody creates the body of a session shamelessly stolen and modified from sentry-go/transport.go
func ExponentialBackoff ¶
func ExponentialBackoff(initial time.Duration, maximum time.Duration, factor float64) func() time.Duration
ExponentialBackoff returns an exponentially increasing Duration
the duration will increase until the maximum duration is reached after which it will return that duration forever. This is not thread safe and should only be called from one goroutine per backoff function.
func FileExists ¶
FileExists returns True if a file exists ( it must be a file i.e. not a directory)
func GetAuthHeader ¶
func GetExternalIPv4 ¶
func LowerFirstLetter ¶
LowerFirstLetter converts the first letter to lower case
func PrivateKeyFromString ¶
func PrivateKeyFromString(public string, private string) (ed25519.PrivateKey, error)
PrivateKeyFromString creates a private key (and does some basic validation) from base64URL encoded public/private key pair. The public private key pair is in the same format as Relay's public/private key pair (found in credentials.json).
func RandomChoice ¶
RandomChoice implements the weighted version of the python random.choices standard function
if relativeWeights is empty or smaller than choices weights of 1 will be considered for the missing weights, if more weights are passed they will be ignored
func RegisterProjectProvider ¶
func RelayAuthSign ¶
RelayAuthSign signs the given data for Relay authentication (the data should be the body of the request). The signature should be passed with the message in the Relay authentication header (X-Sentry-Relay-Signature).
func SimpleRandomChoice ¶
SimpleRandomChoice returns one of the given choices picked up randomly, with the same probability for each choice.
Types ¶
type FileProjectProvider ¶
type FileProjectProvider struct {
// contains filtered or unexported fields
}
func LoadFileProjectProvider ¶
func LoadFileProjectProvider(filePath string) (*FileProjectProvider, error)
LoadFileProjectProvider loads projects from a json file containing a list of projectId to projectKey mappings.
func (FileProjectProvider) GetNextProjectId ¶
func (provider FileProjectProvider) GetNextProjectId(maxProjects int, currentProjectId string) string
func (FileProjectProvider) GetNumberOfProjects ¶
func (provider FileProjectProvider) GetNumberOfProjects() int
func (FileProjectProvider) GetProjectId ¶
func (provider FileProjectProvider) GetProjectId(maxProjects int) string
func (FileProjectProvider) GetProjectIdV2 ¶
func (provider FileProjectProvider) GetProjectIdV2(profiles []ProjectFreqProfile) (string, int, error)
func (FileProjectProvider) GetProjectInfo ¶
func (provider FileProjectProvider) GetProjectInfo(projectId string) ProjectInfo
type ProjectFreqProfile ¶
ProjectFreqProfile defines the frequency relative to other profiles in which a project is picked. Example: [ {numProjects:5, relativeFreq:1}, {numProjects:3, relativeFreq:2}] With the example above the project provider will return 8 projects (5+3) and each of the 5 projects in the first group would be return 3 times less often than each of the 3 project in the second group.
type ProjectInfo ¶
type ProjectInfo struct { ProjectId string `json:"project_id" yaml:"project_id"` ProjectKey string `json:"project_key" yaml:"project_key"` ProjectApiKey string `json:"access_token,omitempty" yaml:"access_token,omitempty"` ProjectSlug string `json:"project_slug,omitempty" yaml:"project_slug,omitempty"` OrganizationSlug string `json:"organization_slug,omitempty" yaml:"organization_slug,omitempty"` }
type ProjectProvider ¶
type ProjectProvider interface { // GetNumberOfProjects returns the number of projects that can be used GetNumberOfProjects() int // GetProjectId returns a random project id GetProjectId(maxProjects int) string // GetProjectIdV2 returns a random project id weighted by the specified project // profiles. With this function you are able to specify that some projects may // be called with a greater frequency than other projects. Profiles is a list // of elements containing the number of projects and their relative frequency ratio GetProjectIdV2(profiles []ProjectFreqProfile) (string, int, error) // GetNextProjectId returns the next project id given the last used project id GetNextProjectId(maxProjects int, currentProjectId string) string GetProjectInfo(projectId string) ProjectInfo }
ProjectProvider can be used to get project Ids and keys for testing
func GetProjectProvider ¶
func GetProjectProvider() ProjectProvider
GetProjectProvider returns the current project provider. Note: this function is not thread safe but since this is only initialised once at the start of the program, it should be fine.
type RandomProjectProvider ¶
type RandomProjectProvider struct{}
func (RandomProjectProvider) GetNextProjectId ¶
func (provider RandomProjectProvider) GetNextProjectId(maxProjects int, currentProjectId string) string
func (RandomProjectProvider) GetNumberOfProjects ¶
func (provider RandomProjectProvider) GetNumberOfProjects() int
func (RandomProjectProvider) GetProjectId ¶
func (provider RandomProjectProvider) GetProjectId(maxProjects int) string
func (RandomProjectProvider) GetProjectIdV2 ¶
func (provider RandomProjectProvider) GetProjectIdV2(profiles []ProjectFreqProfile) (string, int, error)
func (RandomProjectProvider) GetProjectInfo ¶
func (provider RandomProjectProvider) GetProjectInfo(projectId string) ProjectInfo
type StringDuration ¶
StringDuration a duration that serializes in Json/Yaml as a string e.g. "2m"
func (StringDuration) MarshalJSON ¶
func (t StringDuration) MarshalJSON() ([]byte, error)
func (StringDuration) MarshalYAML ¶
func (t StringDuration) MarshalYAML() (any, error)
func (*StringDuration) UnmarshalJSON ¶
func (t *StringDuration) UnmarshalJSON(b []byte) error
func (*StringDuration) UnmarshalYAML ¶
func (t *StringDuration) UnmarshalYAML(unmarshal func(any) error) error