Skip to content

Commit

Permalink
add request to transaction
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <github@jessfraz.com>
  • Loading branch information
jessfraz committed Mar 2, 2022
1 parent 0009a2d commit 42f78e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
22 changes: 22 additions & 0 deletions sentry-core/src/performance.rs
Expand Up @@ -202,6 +202,14 @@ impl TransactionOrSpan {
}
}

/// Set the HTTP request information for this Transaction/Span.
pub fn set_request(&self, request: protocol::Request) {
match self {
TransactionOrSpan::Transaction(transaction) => transaction.set_request(request),
TransactionOrSpan::Span(span) => span.set_request(request),
}
}

/// Returns the headers needed for distributed tracing.
pub fn iter_headers(&self) -> TraceHeadersIter {
match self {
Expand Down Expand Up @@ -355,6 +363,14 @@ impl Transaction {
inner.context.status = Some(status);
}

/// Set the HTTP request information for this Transaction.
pub fn set_request(&self, request: protocol::Request) {
let mut inner = self.inner.lock().unwrap();
if let Some(transaction) = inner.transaction.as_mut() {
transaction.request = Some(request);
}
}

/// Returns the headers needed for distributed tracing.
pub fn iter_headers(&self) -> TraceHeadersIter {
let inner = self.inner.lock().unwrap();
Expand Down Expand Up @@ -454,6 +470,12 @@ impl Span {
span.status = Some(status);
}

/// Set the HTTP request information for this Span.
pub fn set_request(&self, request: protocol::Request) {
let mut span = self.span.lock().unwrap();
span.request = Some(request);
}

/// Returns the headers needed for distributed tracing.
pub fn iter_headers(&self) -> TraceHeadersIter {
let span = self.span.lock().unwrap();
Expand Down
11 changes: 10 additions & 1 deletion sentry-types/src/protocol/v7.rs
Expand Up @@ -15,7 +15,7 @@ use std::ops;
use std::str;
use std::time::SystemTime;

use ::debugid::{CodeId, DebugId};
use self::debugid::{CodeId, DebugId};
use serde::Serializer;
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -1737,6 +1737,9 @@ pub struct Span {
/// Optional extra information to be sent with the span.
#[serde(default, skip_serializing_if = "Map::is_empty")]
pub data: Map<String, Value>,
/// Optionally HTTP request data to be sent along.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub request: Option<Request>,
}

impl Default for Span {
Expand All @@ -1753,6 +1756,7 @@ impl Default for Span {
same_process_as_parent: Default::default(),
op: Default::default(),
data: Default::default(),
request: Default::default(),
}
}
}
Expand Down Expand Up @@ -1942,6 +1946,9 @@ pub struct Transaction<'a> {
/// Optional contexts.
#[serde(default, skip_serializing_if = "Map::is_empty")]
pub contexts: Map<String, Context>,
/// Optionally HTTP request data to be sent along.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub request: Option<Request>,
}

impl<'a> Default for Transaction<'a> {
Expand All @@ -1959,6 +1966,7 @@ impl<'a> Default for Transaction<'a> {
start_timestamp: SystemTime::now(),
spans: Default::default(),
contexts: Default::default(),
request: Default::default(),
}
}
}
Expand All @@ -1984,6 +1992,7 @@ impl<'a> Transaction<'a> {
start_timestamp: self.start_timestamp,
spans: self.spans,
contexts: self.contexts,
request: self.request,
}
}

Expand Down

0 comments on commit 42f78e3

Please sign in to comment.