Skip to content

feat: Apply current scope when finishing transaction #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry-core/src/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ impl Transaction {
.contexts
.insert("trace".into(), inner.context.clone().into());

// TODO: apply the scope to the transaction, whatever that means
Hub::current().with_current_scope(|scope| scope.apply_to_transaction(&mut transaction));
let opts = client.options();
transaction.release = opts.release.clone();
transaction.environment = opts.environment.clone();
Expand Down
17 changes: 16 additions & 1 deletion sentry-core/src/scope/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt;
use std::sync::{Arc, Mutex, PoisonError, RwLock};

use crate::performance::TransactionOrSpan;
use crate::protocol::{Attachment, Breadcrumb, Context, Event, Level, User, Value};
use crate::protocol::{Attachment, Breadcrumb, Context, Event, Level, Transaction, User, Value};
use crate::session::Session;
use crate::Client;

Expand Down Expand Up @@ -302,6 +302,21 @@ impl Scope {
Some(event)
}

/// Applies the contained scoped data to fill a transaction.
pub fn apply_to_transaction(&self, transaction: &mut Transaction<'static>) {
transaction
.extra
.extend(self.extra.iter().map(|(k, v)| (k.to_owned(), v.to_owned())));
transaction
.tags
.extend(self.tags.iter().map(|(k, v)| (k.to_owned(), v.to_owned())));
transaction.contexts.extend(
self.contexts
.iter()
.map(|(k, v)| (k.to_owned(), v.to_owned())),
);
}

/// Set the given [`TransactionOrSpan`] as the active span for this scope.
pub fn set_span(&mut self, span: Option<TransactionOrSpan>) {
self.span = Arc::new(span);
Expand Down