Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
### New Features

- Added [`Dsn::org_id`](https://docs.rs/sentry-types/latest/sentry_types/struct.Dsn.html#method.org_id), which parses the Sentry SaaS organization ID from DSN hosts such as `o123.ingest.sentry.io` ([#1202](https://github.com/getsentry/sentry-rust/pull/1202)).
- Added [`ClientOptions::org_id`](https://docs.rs/sentry-core/latest/sentry_core/struct.ClientOptions.html#method.org_id) and [`ClientOptions::strict_trace_continuation`](https://docs.rs/sentry-core/latest/sentry_core/struct.ClientOptions.html#method.strict_trace_continuation) ([#1203](https://github.com/getsentry/sentry-rust/pull/1203)). These options control how traces are continued and can help prevent traces from third-party services, which happen to be instrumented with Sentry, from being continued.

## 0.48.4

Expand Down
47 changes: 46 additions & 1 deletion sentry-core/src/clientoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;

use crate::constants::USER_AGENT;
use crate::performance::{TracesSampler, TransactionContext};
use crate::protocol::{Breadcrumb, Event, Log, Metric};
use crate::protocol::{Breadcrumb, Event, Log, Metric, OrganizationId};
use crate::types::Dsn;
use crate::{Integration, IntoDsn, TransportFactory};

Expand Down Expand Up @@ -168,6 +168,15 @@ pub struct ClientOptions {
/// [`traces_sampler`](method@ClientOptions::traces_sampler), or can be left at the default
/// disabled value.
pub traces_sampling_strategy: TracesSamplingStrategy,
/// The organization ID used for trace continuation.
///
/// See [`org_id`](method@ClientOptions::org_id) for details.
pub org_id: Option<OrganizationId>,
/// Enables strict trace continuation.
///
/// See [`strict_trace_continuation`](method@ClientOptions::strict_trace_continuation) for
/// details.
pub strict_trace_continuation: bool,
/// Maximum number of breadcrumbs.
///
/// See [`max_breadcrumbs`](method@ClientOptions::max_breadcrumbs) for details.
Expand Down Expand Up @@ -405,6 +414,38 @@ impl ClientOptions {
}
}

/// Sets the [organization ID](field@ClientOptions::org_id) used for trace continuation.
///
/// By default, we infer the organization ID from the DSN when available. Setting this option
/// overrides the DSN-derived organization ID.
///
/// This option should be used in local Relay and self-hosted setups, as the organization ID
/// cannot be inferred from the DSN in these cases.
#[inline]
pub fn org_id(self, org_id: OrganizationId) -> Self {
let org_id = Some(org_id);
Self { org_id, ..self }
}

/// Enables or disables [strict trace continuation](field@ClientOptions::strict_trace_continuation).
///
/// Strict trace continuation helps prevent the SDK from continuing traces that originate from
/// services instrumented with Sentry by another organization.
///
/// By default, the SDK will always continue incoming traces, unless this SDK has an org ID
/// embedded in the DSN or explicitly set with [`Self::org_id`] **and** the incoming trace
/// includes a different org ID.
///
/// When strict trace continuation is enabled, the SDK additionally will not continue traces in
/// the case where one of the SDK's org ID or the incoming trace org ID are missing.
#[inline]
pub fn strict_trace_continuation(self, strict_trace_continuation: bool) -> Self {
Self {
strict_trace_continuation,
..self
}
}

/// Sets the [maximum number of breadcrumbs](field@ClientOptions::max_breadcrumbs).
///
/// Defaults to `100`.
Expand Down Expand Up @@ -778,6 +819,8 @@ impl fmt::Debug for ClientOptions {
.field("before_send_log", &before_send_log)
.field("enable_metrics", &self.enable_metrics)
.field("before_send_metric", &before_send_metric)
.field("org_id", &self.org_id)
.field("strict_trace_continuation", &self.strict_trace_continuation)
.field("user_agent", &self.user_agent)
.finish()
}
Expand All @@ -787,6 +830,8 @@ impl Default for ClientOptions {
fn default() -> ClientOptions {
ClientOptions {
dsn: None,
org_id: None,
strict_trace_continuation: false,
debug: false,
release: None,
environment: None,
Expand Down
Loading