Struct ManagedEnvelope

Source
pub struct ManagedEnvelope { /* private fields */ }
Expand description

Tracks the lifetime of an [Envelope] in Relay.

The managed envelope accompanies envelopes through the processing pipeline in Relay and ensures that outcomes are recorded when the Envelope is dropped. They can be dropped in one of three ways:

  • By calling accept. Responsibility of the envelope has been transferred to another service, and no further outcomes need to be recorded.
  • By calling reject. The entire envelope was dropped, and the outcome specifies the reason.
  • By dropping the managed envelope. This indicates an issue or a bug and raises the "internal" outcome. There should be additional error handling to report an error to Sentry.

The managed envelope also holds a processing queue permit which is used for backpressure management. It is automatically reclaimed when the context is dropped along with the envelope.

Implementations§

Source§

impl ManagedEnvelope

Source

pub fn new( envelope: Box<Envelope>, outcome_aggregator: Addr<TrackOutcome>, ) -> Self

Computes a managed envelope from the given envelope and binds it to the processing queue.

To provide additional scoping, use ManagedEnvelope::scope.

Source

pub fn envelope(&self) -> &Envelope

Returns a reference to the contained [Envelope].

Source

pub fn envelope_mut(&mut self) -> &mut Envelope

Returns a mutable reference to the contained [Envelope].

Source

pub fn into_envelope(self) -> Box<Envelope>

Consumes itself returning the managed envelope.

Source

pub fn into_processed(self) -> TypedEnvelope<Processed>

Converts current managed envelope into processed envelope.

Once it’s marked processed it can be submitted to upstream.

Source

pub fn update(&mut self) -> &mut Self

Update the context with envelope information.

This updates the item summary as well as the event id.

Source

pub fn retain_items<F>(&mut self, f: F)
where F: FnMut(&mut Item) -> ItemAction,

Retains or drops items based on the ItemAction.

This method operates in place and preserves the order of the retained items.

Source

pub fn drop_items_silently(&mut self)

Drops every item in the envelope.

Source

pub fn scope(&mut self, scoping: Scoping) -> &mut Self

Re-scopes this context to the given scoping.

Source

pub fn reject_event(&mut self, outcome: Outcome)

Removes event item(s) and logs an outcome.

Note: This function relies on the envelope summary being correct.

Source

pub fn track_outcome( &self, outcome: Outcome, category: DataCategory, quantity: usize, )

Records an outcome scoped to this envelope’s context.

This managed envelope should be updated using update soon after this operation to ensure that subsequent outcomes are consistent.

Source

pub fn accept(self)

Accepts the envelope and drops the context.

This should be called if the envelope has been accepted by the upstream, which means that the responsibility for logging outcomes has been moved. This function will not log any outcomes.

Source

pub fn reject(&mut self, outcome: Outcome)

Records rejection outcomes for all items stored in this context.

This does not send outcomes for empty envelopes or request-only contexts.

Source

pub fn scoping(&self) -> Scoping

Returns scoping stored in this context.

Source

pub fn partition_key(&self) -> Option<u32>

Returns the partition key, which is set on upstream requests in the X-Sentry-Relay-Shard header.

Source

pub fn set_partition_key(&mut self, partition_key: Option<u32>) -> &mut Self

Sets a new Self::partition_key.

Source

pub fn meta(&self) -> &RequestMeta

Returns the contained original request meta.

Source

pub fn estimated_size(&self) -> usize

Returns estimated size of this envelope.

This is just an estimated size, which in reality can be somewhat bigger, depending on the list of additional attributes allocated on all of the inner types.

NOTE: Current implementation counts in only the size of the items payload and stack allocated parts of [Envelope] and ManagedEnvelope. All the heap allocated fields within early mentioned types are skipped.

Source

pub fn received_at(&self) -> DateTime<Utc>

Returns the time at which the envelope was received at this Relay.

This is the date time equivalent to start_time.

Source

pub fn age(&self) -> Duration

Returns the time elapsed in seconds since the envelope was received by this Relay.

In case the elapsed time is negative, it is assumed that no time elapsed.

Trait Implementations§

Source§

impl Debug for ManagedEnvelope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for ManagedEnvelope

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<G> From<TypedEnvelope<G>> for ManagedEnvelope

Source§

fn from(value: TypedEnvelope<G>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T