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
impl ManagedEnvelope
Sourcepub fn new(
envelope: Box<Envelope>,
outcome_aggregator: Addr<TrackOutcome>,
) -> Self
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
.
Sourcepub fn envelope_mut(&mut self) -> &mut Envelope
pub fn envelope_mut(&mut self) -> &mut Envelope
Returns a mutable reference to the contained [Envelope
].
Sourcepub fn into_envelope(self) -> Box<Envelope>
pub fn into_envelope(self) -> Box<Envelope>
Consumes itself returning the managed envelope.
Sourcepub fn into_processed(self) -> TypedEnvelope<Processed>
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.
Sourcepub fn update(&mut self) -> &mut Self
pub fn update(&mut self) -> &mut Self
Update the context with envelope information.
This updates the item summary as well as the event id.
Sourcepub fn retain_items<F>(&mut self, f: F)where
F: FnMut(&mut Item) -> ItemAction,
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.
Sourcepub fn drop_items_silently(&mut self)
pub fn drop_items_silently(&mut self)
Drops every item in the envelope.
Sourcepub fn scope(&mut self, scoping: Scoping) -> &mut Self
pub fn scope(&mut self, scoping: Scoping) -> &mut Self
Re-scopes this context to the given scoping.
Sourcepub fn reject_event(&mut self, outcome: Outcome)
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.
Sourcepub fn track_outcome(
&self,
outcome: Outcome,
category: DataCategory,
quantity: usize,
)
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.
Sourcepub fn accept(self)
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.
Sourcepub fn reject(&mut self, outcome: Outcome)
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.
Sourcepub fn partition_key(&self) -> Option<u32>
pub fn partition_key(&self) -> Option<u32>
Returns the partition key, which is set on upstream requests in the X-Sentry-Relay-Shard
header.
Sourcepub fn set_partition_key(&mut self, partition_key: Option<u32>) -> &mut Self
pub fn set_partition_key(&mut self, partition_key: Option<u32>) -> &mut Self
Sets a new Self::partition_key
.
Sourcepub fn estimated_size(&self) -> usize
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.
Sourcepub fn received_at(&self) -> DateTime<Utc>
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
.
Trait Implementations§
Source§impl Debug for ManagedEnvelope
impl Debug for ManagedEnvelope
Source§impl Drop for ManagedEnvelope
impl Drop for ManagedEnvelope
Source§impl<G> From<TypedEnvelope<G>> for ManagedEnvelope
impl<G> From<TypedEnvelope<G>> for ManagedEnvelope
Source§fn from(value: TypedEnvelope<G>) -> Self
fn from(value: TypedEnvelope<G>) -> Self
Auto Trait Implementations§
impl Freeze for ManagedEnvelope
impl !RefUnwindSafe for ManagedEnvelope
impl Send for ManagedEnvelope
impl Sync for ManagedEnvelope
impl Unpin for ManagedEnvelope
impl !UnwindSafe for ManagedEnvelope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered
].