-
Notifications
You must be signed in to change notification settings - Fork 104
feat(eap): Produce logs to the items topic #4707
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
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
0aa91e4
feat(eap): Produce logs to the items topic
phacops 3e2b852
Vendor sentry_protos
phacops 5332d1c
Gate sentry_protos dependency behind the processing feature
phacops d5ddc89
Use the proper enum value
phacops a401c2f
Do not use the macro
phacops 697763a
Serialize in the function and return the raw bytes in serialize()
phacops 74e809d
Read the items portion of the config
phacops 1be1453
Generate proper types for Protobuf schema validation
phacops 9a779f8
Remove vendored in favor of installing protoc
phacops 8d21e2b
Enable type_generation for sentry-kafka-schemas
phacops d57223f
Install protoc to all workflows needing it
phacops a4dbeb8
Add missing workflows
phacops ad27999
Add a CHANGELOG entry
phacops 095c26f
Fix some tests
phacops 90462cc
Revert "Add missing workflows"
phacops f53c73a
Revert "Install protoc to all workflows needing it"
phacops dd26cab
Upgrade sentry_protos and sentry-kafka-schemas so we don't need protoc
phacops 08c7886
Fix tests
phacops d78d272
Move some logic to the normalization
phacops 57761af
Fix normalization tests
phacops 86ca4aa
Fix one more test
phacops c9fe378
Remove another installation of protoc in CI
phacops 1e3e6ac
Order crates alphabetically and remove types_generation feature
phacops 6dc69a6
Use to_owned() instead of to_string()
phacops 387b59f
Disable default features again now the crate is fixed
phacops 02f7c1a
Really disable default features for sentry-kafka-schemas
phacops cf2475b
Can't make it with less default features than this
phacops abc0f44
Remove Serialization trait for logs
phacops 79ed892
Move Protobuf encoding to serialize
phacops b7eb2b6
Use to_owned() instead of to_string() where we can
phacops b00ab99
Remove nanoseconds from this timestamp
phacops ba2fdeb
Remove other and add back sentry.timestamp_precise
phacops 0d25ca7
Fix tests
phacops 33ae11f
Fix integration tests
phacops 5633637
Update snapshots
phacops b90d31b
Add a better comment on why we replace the item_id
phacops 1cda6e9
Fix linting
phacops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ use relay_config::Config; | |
| use relay_event_schema::protocol::{EventId, VALID_PLATFORMS}; | ||
|
|
||
| use crate::envelope::{AttachmentType, Envelope, Item, ItemType}; | ||
| use prost::Message as _; | ||
| use prost_types::Timestamp; | ||
| use relay_kafka::{ClientError, KafkaClient, KafkaTopic, Message}; | ||
| use relay_metrics::{ | ||
| Bucket, BucketView, BucketViewValue, BucketsView, ByNamespace, FiniteF64, GaugeValue, | ||
|
|
@@ -28,6 +30,8 @@ use relay_quotas::Scoping; | |
| use relay_statsd::metric; | ||
| use relay_system::{Addr, FromMessage, Interface, NoResponse, Service}; | ||
| use relay_threading::AsyncPool; | ||
| use sentry_protos::snuba::v1::any_value::Value; | ||
| use sentry_protos::snuba::v1::{AnyValue, TraceItem, TraceItemType}; | ||
| use serde::{Deserialize, Serialize}; | ||
| use serde_json::Deserializer; | ||
| use serde_json::value::RawValue; | ||
|
|
@@ -959,7 +963,6 @@ impl StoreService { | |
| let payload_len = payload.len(); | ||
|
|
||
| let d = &mut Deserializer::from_slice(&payload); | ||
|
|
||
| let logs: LogKafkaMessages = match serde_path_to_error::deserialize(d) { | ||
| Ok(logs) => logs, | ||
| Err(error) => { | ||
|
|
@@ -989,18 +992,104 @@ impl StoreService { | |
| } | ||
| }; | ||
|
|
||
| for mut log in logs.items { | ||
| log.organization_id = scoping.organization_id.value(); | ||
| log.project_id = scoping.project_id.value(); | ||
| log.retention_days = retention_days; | ||
| log.received = safe_timestamp(received_at); | ||
| for log in logs.items { | ||
| let timestamp_seconds = log.timestamp_nanos / 1_000_000_000; | ||
| let timestamp_nanos = log.timestamp_nanos % 1_000_000_000; | ||
| let item_id = u128::from_be_bytes( | ||
| *Uuid::new_v7(uuid::Timestamp::from_unix( | ||
| uuid::NoContext, | ||
| timestamp_seconds, | ||
| timestamp_nanos as u32, | ||
| )) | ||
| .as_bytes(), | ||
| ) | ||
| .to_le_bytes() | ||
| .to_vec(); | ||
| let mut trace_item = TraceItem { | ||
| item_type: TraceItemType::Log.into(), | ||
| organization_id: scoping.organization_id.value(), | ||
| project_id: scoping.project_id.value(), | ||
| received: Some(Timestamp { | ||
| seconds: safe_timestamp(received_at) as i64, | ||
| nanos: 0, | ||
| }), | ||
| retention_days: retention_days.into(), | ||
| timestamp: Some(Timestamp { | ||
| seconds: timestamp_seconds as i64, | ||
| nanos: timestamp_nanos as i32, | ||
| }), | ||
phacops marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| trace_id: log.trace_id.to_string(), | ||
| item_id, | ||
| attributes: Default::default(), | ||
| client_sample_rate: 1.0, | ||
| server_sample_rate: 1.0, | ||
| }; | ||
|
|
||
| trace_item.attributes.insert( | ||
| "sentry.timestamp_precise".to_string(), | ||
| AnyValue { | ||
| value: Some(Value::IntValue(log.timestamp_nanos as i64)), | ||
| }, | ||
| ); | ||
| trace_item.attributes.insert( | ||
| "sentry.severity_text".to_string(), | ||
| AnyValue { | ||
| value: Some(Value::StringValue( | ||
| log.severity_text.unwrap_or_else(|| "INFO".into()).into(), | ||
| )), | ||
| }, | ||
| ); | ||
| trace_item.attributes.insert( | ||
| "sentry.severity_number".to_string(), | ||
| AnyValue { | ||
| value: Some(Value::IntValue( | ||
| log.severity_number.unwrap_or_default().into(), | ||
| )), | ||
| }, | ||
| ); | ||
| trace_item.attributes.insert( | ||
| "sentry.body".to_string(), | ||
| AnyValue { | ||
| value: Some(Value::StringValue(log.body.to_string())), | ||
| }, | ||
| ); | ||
|
|
||
| for (name, attribute) in log.attributes.unwrap_or_default() { | ||
| if let Some(attribute_value) = attribute { | ||
| if let Some(v) = attribute_value.value { | ||
| let any_value = match v { | ||
| LogAttributeValue::String(value) => AnyValue { | ||
| value: Some(Value::StringValue(value)), | ||
| }, | ||
| LogAttributeValue::Int(value) => AnyValue { | ||
| value: Some(Value::IntValue(value)), | ||
| }, | ||
|
Comment on lines
+1034
to
+1036
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was already a bug before I think, this will drop logs with an int value > i64::MAX. I'll take care of that. |
||
| LogAttributeValue::Bool(value) => AnyValue { | ||
| value: Some(Value::BoolValue(value)), | ||
| }, | ||
| LogAttributeValue::Double(value) => AnyValue { | ||
| value: Some(Value::DoubleValue(value)), | ||
| }, | ||
| LogAttributeValue::Unknown(_) => continue, | ||
| }; | ||
|
|
||
| trace_item.attributes.insert(name.into(), any_value); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let mut message = vec![]; | ||
phacops marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if trace_item.encode(&mut message).is_err() { | ||
phacops marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return Ok(()); | ||
| }; | ||
|
|
||
| let message = KafkaMessage::Log { | ||
| headers: BTreeMap::from([( | ||
| "project_id".to_string(), | ||
| scoping.project_id.to_string(), | ||
| )]), | ||
| message: log, | ||
| headers: BTreeMap::from([ | ||
| ("project_id".to_string(), scoping.project_id.to_string()), | ||
| ("item_type".to_string(), "3".to_string()), | ||
phacops marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ]), | ||
| message, | ||
| }; | ||
|
|
||
| self.produce(KafkaTopic::OurLogs, message)?; | ||
|
|
@@ -1592,8 +1681,7 @@ enum KafkaMessage<'a> { | |
| Log { | ||
| #[serde(skip)] | ||
| headers: BTreeMap<String, String>, | ||
| #[serde(flatten)] | ||
| message: LogKafkaMessage<'a>, | ||
| message: Vec<u8>, | ||
| }, | ||
| ProfileChunk(ProfileChunkKafkaMessage), | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.