Skip to content
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

feat(ourlogs): Preliminary breadcrumb to log conversion #4479

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## Unreleased

- Allow log ingestion behind a flag, only for internal use currently. ([#4471](https://github.com/getsentry/relay/pull/4471))

**Features**:

- Preliminary breadcrumb to log conversion. ([#4479](https://github.com/getsentry/relay/pull/4479))
- Allow log ingestion behind a flag, only for internal use currently. ([#4471](https://github.com/getsentry/relay/pull/4471))
- Add configuration option to limit the amount of concurrent http connections. ([#4453](https://github.com/getsentry/relay/pull/4453))
- Add flags context to event schema. ([#4458](https://github.com/getsentry/relay/pull/4458))
- Add support for view hierarchy attachment scrubbing. ([#4452](https://github.com/getsentry/relay/pull/4452))
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions relay-dynamic-config/src/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ pub enum Feature {
/// Serialized as `organizations:ourlogs-ingestion`.
#[serde(rename = "organizations:ourlogs-ingestion")]
OurLogsIngestion,

/// Enables extracting logs from breadcrumbs for our log product.
#[serde(rename = "projects:ourlogs-breadcrumb-extraction")]
OurLogsBreadcrumbExtraction,

/// This feature has graduated and is hard-coded for external Relays.
#[doc(hidden)]
#[serde(rename = "projects:profiling-ingest-unsampled-profiles")]
Expand Down
23 changes: 23 additions & 0 deletions relay-dynamic-config/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,29 @@ pub struct Options {
)]
pub span_extraction_sample_rate: Option<f32>,

/// Extract logs from breadrumbs for a fraction of sent breadcrumbs.
///
/// `None` is the default and interpreted as extract nothing.
///
/// Note: Any value below 1.0 will cause the product to break, so use with caution.
#[serde(
rename = "relay.ourlogs-breadcrumb-extraction.sample-rate",
deserialize_with = "default_on_error",
skip_serializing_if = "is_default"
)]
pub ourlogs_breadcrumb_extraction_sample_rate: Option<f32>,

/// The maximum number of breadcrumbs to convert to OurLogs.
///
/// When converting breadcrumbs to OurLogs, only up to this many breadcrumbs will be converted.
/// Defaults to 100.
#[serde(
rename = "relay.ourlogs-breadcrumb-extraction.max-breadcrumbs-converted",
deserialize_with = "default_on_error",
skip_serializing_if = "is_default"
)]
pub ourlogs_breadcrumb_extraction_max_breadcrumbs_converted: usize,

/// List of values on span description that are allowed to be sent to Sentry without being scrubbed.
///
/// At this point, it doesn't accept IP addresses in CIDR format.. yet.
Expand Down
7 changes: 6 additions & 1 deletion relay-event-schema/src/protocol/contexts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod monitor;
mod nel;
mod os;
mod otel;
mod our_logs;
mod performance_score;
mod profile;
mod replay;
Expand All @@ -25,6 +26,7 @@ pub use monitor::*;
pub use nel::*;
pub use os::*;
pub use otel::*;
pub use our_logs::*;
pub use performance_score::*;
pub use profile::*;
pub use replay::*;
Expand Down Expand Up @@ -90,6 +92,9 @@ pub enum Context {
Nel(Box<NelContext>),
/// Performance score information.
PerformanceScore(Box<PerformanceScoreContext>),
/// Ourlogs (logs product) information.
#[metastructure(tag = "sentry_logs")]
OurLogs(Box<OurLogsContext>),
Comment on lines +96 to +97
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these hard to remove later or is the deprecation sticky? If they are I'm probably going to delay this a week until Abhi is back and we can make sure everyone is fine with the context on the sdk side.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the variant from the code is not a problem. After removing it, relay will still forward the context as if it were a user-defined context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

/// Additional arbitrary fields for forwards compatibility.
#[metastructure(fallback_variant)]
Other(#[metastructure(pii = "true")] Object<Value>),
Expand All @@ -109,7 +114,7 @@ impl From<Context> for ContextInner {
/// name is `contexts`.
///
/// The `contexts` type can be used to define arbitrary contextual data on the event. It accepts an
/// object of key/value pairs. The key is the alias of the context and can be freely chosen.
/// object of key/value pairs. The key is the "alias" of the context and can be freely chosen.
/// However, as per policy, it should match the type of the context unless there are two values for
/// a type. You can omit `type` if the key name is the type.
///
Expand Down
68 changes: 68 additions & 0 deletions relay-event-schema/src/protocol/contexts/our_logs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use relay_protocol::{Annotated, Empty, FromValue, IntoValue, Object, Value};

use crate::processor::ProcessValue;

/// Our Logs context.
///
/// The Sentry Logs context contains information about our logging product (ourlogs) for an event.
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
pub struct OurLogsContext {
/// Whether breadcrumbs are being deduplicated.
pub deduplicated_breadcrumbs: Annotated<bool>,

/// Additional arbitrary fields for forwards compatibility.
#[metastructure(additional_properties, retain = true)]
pub other: Object<Value>,
}

impl super::DefaultContext for OurLogsContext {
fn default_key() -> &'static str {
"sentry_logs" // Ourlogs is an internal name, and 'logs' likely has conflicts with user contexts.
}

fn from_context(context: super::Context) -> Option<Self> {
match context {
super::Context::OurLogs(c) => Some(*c),
_ => None,
}
}

fn cast(context: &super::Context) -> Option<&Self> {
match context {
super::Context::OurLogs(c) => Some(c),
_ => None,
}
}

fn cast_mut(context: &mut super::Context) -> Option<&mut Self> {
match context {
super::Context::OurLogs(c) => Some(c),
_ => None,
}
}

fn into_context(self) -> super::Context {
super::Context::OurLogs(Box::new(self))
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::protocol::Context;

#[test]
fn test_our_logs_context() {
let json = r#"{
"deduplicated_breadcrumbs": true,
"type": "sentry_logs"
}"#;
let context = Annotated::new(Context::OurLogs(Box::new(OurLogsContext {
deduplicated_breadcrumbs: Annotated::new(true),
..OurLogsContext::default()
})));

assert_eq!(context, Annotated::from_json(json).unwrap());
assert_eq!(json, context.to_json_pretty().unwrap());
}
}
1 change: 1 addition & 0 deletions relay-ourlogs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ opentelemetry-proto = { workspace = true, features = [
"with-serde",
"logs",
] }
relay-log = { workspace = true }
relay-event-schema = { workspace = true }
relay-protocol = { workspace = true }
serde_json = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions relay-ourlogs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
html_favicon_url = "https://raw.githubusercontent.com/getsentry/relay/master/artwork/relay-icon.png"
)]

pub use crate::ourlog::breadcrumbs_to_ourlogs;
pub use crate::ourlog::otel_to_sentry_log;

pub use opentelemetry_proto::tonic::logs::v1::LogRecord as OtelLog;
Expand Down
Loading
Loading