protocol

package
v0.36.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchemeHTTP  scheme = "http"
	SchemeHTTPS scheme = "https"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Dsn

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

Dsn is used as the remote address source to client transport.

func NewDsn

func NewDsn(rawURL string) (*Dsn, error)

NewDsn creates a Dsn by parsing rawURL. Most users will never call this function directly. It is provided for use in custom Transport implementations.

func (Dsn) GetAPIURL

func (dsn Dsn) GetAPIURL() *url.URL

GetAPIURL returns the URL of the envelope endpoint of the project associated with the DSN.

func (Dsn) GetHost

func (dsn Dsn) GetHost() string

Get the host of the DSN.

func (Dsn) GetPath

func (dsn Dsn) GetPath() string

Get the path of the DSN.

func (Dsn) GetPort

func (dsn Dsn) GetPort() int

Get the port of the DSN.

func (Dsn) GetProjectID

func (dsn Dsn) GetProjectID() string

Get the project ID of the DSN.

func (Dsn) GetPublicKey

func (dsn Dsn) GetPublicKey() string

Get the public key of the DSN.

func (Dsn) GetScheme

func (dsn Dsn) GetScheme() string

Get the scheme of the DSN.

func (Dsn) GetSecretKey

func (dsn Dsn) GetSecretKey() string

Get the secret key of the DSN.

func (Dsn) MarshalJSON

func (dsn Dsn) MarshalJSON() ([]byte, error)

MarshalJSON converts the Dsn struct to JSON.

func (Dsn) RequestHeaders deprecated

func (dsn Dsn) RequestHeaders(sdkVersion string) map[string]string

RequestHeaders returns all the necessary headers that have to be used in the transport when sending events to the /store endpoint.

Deprecated: This method shall only be used if you want to implement your own transport that sends events to the /store endpoint. If you're using the transport provided by the SDK, all necessary headers to authenticate against the /envelope endpoint are added automatically.

func (Dsn) String

func (dsn Dsn) String() string

String formats Dsn struct into a valid string url.

func (*Dsn) UnmarshalJSON

func (dsn *Dsn) UnmarshalJSON(data []byte) error

UnmarshalJSON converts JSON data to the Dsn struct.

type DsnParseError

type DsnParseError struct {
	Message string
}

DsnParseError represents an error that occurs if a Sentry DSN cannot be parsed.

func (DsnParseError) Error

func (e DsnParseError) Error() string

type Envelope

type Envelope struct {
	Header *EnvelopeHeader `json:"-"`
	Items  []*EnvelopeItem `json:"-"`
}

Envelope represents a Sentry envelope containing headers and items.

func NewEnvelope

func NewEnvelope(header *EnvelopeHeader) *Envelope

NewEnvelope creates a new envelope with the given header.

func (*Envelope) AddItem

func (e *Envelope) AddItem(item *EnvelopeItem)

AddItem adds an item to the envelope.

func (*Envelope) Serialize

func (e *Envelope) Serialize() ([]byte, error)

Serialize serializes the envelope to the Sentry envelope format.

Format: Headers "\n" { Item } [ "\n" ] Item: Headers "\n" Payload "\n".

func (*Envelope) Size

func (e *Envelope) Size() (int, error)

Size returns the total size of the envelope when serialized.

func (*Envelope) WriteTo

func (e *Envelope) WriteTo(w io.Writer) (int64, error)

WriteTo writes the envelope to the given writer in the Sentry envelope format.

type EnvelopeConvertible

type EnvelopeConvertible interface {
	// ToEnvelope converts the item to a Sentry envelope.
	ToEnvelope(dsn *Dsn) (*Envelope, error)
}

EnvelopeConvertible represents any type that can be converted to a Sentry envelope. This interface allows the telemetry buffers to be generic while still working with concrete types like Event.

type EnvelopeHeader

type EnvelopeHeader struct {
	// EventID is the unique identifier for this event
	EventID string `json:"event_id"`

	// SentAt is the timestamp when the event was sent from the SDK as string in RFC 3339 format.
	// Used for clock drift correction of the event timestamp. The time zone must be UTC.
	SentAt time.Time `json:"sent_at,omitempty"`

	// Dsn can be used for self-authenticated envelopes.
	// This means that the envelope has all the information necessary to be sent to sentry.
	// In this case the full DSN must be stored in this key.
	Dsn string `json:"dsn,omitempty"`

	// Sdk carries the same payload as the sdk interface in the event payload but can be carried for all events.
	// This means that SDK information can be carried for minidumps, session data and other submissions.
	Sdk *SdkInfo `json:"sdk,omitempty"`

	// Trace contains the [Dynamic Sampling Context](https://develop.sentry.dev/sdk/telemetry/traces/dynamic-sampling-context/)
	Trace map[string]string `json:"trace,omitempty"`
}

EnvelopeHeader represents the header of a Sentry envelope.

func (*EnvelopeHeader) MarshalJSON

func (h *EnvelopeHeader) MarshalJSON() ([]byte, error)

MarshalJSON converts the EnvelopeHeader to JSON.

type EnvelopeItem

type EnvelopeItem struct {
	Header  *EnvelopeItemHeader `json:"-"`
	Payload []byte              `json:"-"`
}

EnvelopeItem represents a single item within an envelope.

func NewAttachmentItem

func NewAttachmentItem(filename, contentType string, payload []byte) *EnvelopeItem

NewAttachmentItem creates a new envelope item for an attachment. Parameters: filename, contentType, payload.

func NewEnvelopeItem

func NewEnvelopeItem(itemType EnvelopeItemType, payload []byte) *EnvelopeItem

NewEnvelopeItem creates a new envelope item with the specified type and payload.

func NewLogItem

func NewLogItem(itemCount int, payload []byte) *EnvelopeItem

NewLogItem creates a new envelope item for logs.

type EnvelopeItemHeader

type EnvelopeItemHeader struct {
	// Type specifies the type of this Item and its contents.
	// Based on the Item type, more headers may be required.
	Type EnvelopeItemType `json:"type"`

	// Length is the length of the payload in bytes.
	// If no length is specified, the payload implicitly goes to the next newline.
	// For payloads containing newline characters, the length must be specified.
	Length *int `json:"length,omitempty"`

	// Filename is the name of the attachment file (used for attachments)
	Filename string `json:"filename,omitempty"`

	// ContentType is the MIME type of the item payload (used for attachments and some other item types)
	ContentType string `json:"content_type,omitempty"`

	// ItemCount is the number of items in a batch (used for logs)
	ItemCount *int `json:"item_count,omitempty"`
}

EnvelopeItemHeader represents the header of an envelope item.

type EnvelopeItemType

type EnvelopeItemType string

EnvelopeItemType represents the type of envelope item.

const (
	EnvelopeItemTypeEvent       EnvelopeItemType = "event"
	EnvelopeItemTypeTransaction EnvelopeItemType = "transaction"
	EnvelopeItemTypeCheckIn     EnvelopeItemType = "check_in"
	EnvelopeItemTypeAttachment  EnvelopeItemType = "attachment"
	EnvelopeItemTypeLog         EnvelopeItemType = "log"
)

Constants for envelope item types as defined in the Sentry documentation.

type SdkInfo

type SdkInfo struct {
	Name         string       `json:"name,omitempty"`
	Version      string       `json:"version,omitempty"`
	Integrations []string     `json:"integrations,omitempty"`
	Packages     []SdkPackage `json:"packages,omitempty"`
}

SdkInfo contains SDK metadata.

type SdkPackage

type SdkPackage struct {
	Name    string `json:"name,omitempty"`
	Version string `json:"version,omitempty"`
}

SdkPackage describes a package that was installed.

type TelemetryTransport

type TelemetryTransport interface {
	// SendEnvelope sends an envelope to Sentry. Returns immediately with
	// backpressure error if the queue is full.
	SendEnvelope(envelope *Envelope) error

	// SendEvent sends an event to Sentry.
	SendEvent(event EnvelopeConvertible)

	// IsRateLimited checks if a specific category is currently rate limited
	IsRateLimited(category ratelimit.Category) bool

	// Flush waits for all pending envelopes to be sent, with timeout
	Flush(timeout time.Duration) bool

	// FlushWithContext waits for all pending envelopes to be sent
	FlushWithContext(ctx context.Context) bool

	// Close shuts down the transport gracefully
	Close()
}

TelemetryTransport represents the envelope-first transport interface. This interface is designed for the telemetry buffer system and provides non-blocking sends with backpressure signals.

Jump to

Keyboard shortcuts

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