-
Notifications
You must be signed in to change notification settings - Fork 65
feat: user-events logs exporter - add support for Resource attributes #288
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
cijothomas
merged 17 commits into
open-telemetry:main
from
cijothomas:cijothomas/userevents-resource
Jul 17, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c460126
add resource support to user-events
cijothomas 7cd1ddc
try int
cijothomas 4120dd3
Merge branch 'main' into cijothomas/userevents-resource
cijothomas 4dfad92
Merge branch 'main' into cijothomas/userevents-resource
cijothomas eb290ab
PR feedback
cijothomas acc2798
ch
cijothomas 36de1eb
remove println
cijothomas ddac106
Merge branch 'main' into cijothomas/userevents-resource
cijothomas b2f38ba
renames
cijothomas efde7c1
hashset diret
cijothomas 4a717e6
fl;exible api
cijothomas 93166ea
check partc outside loop
cijothomas 96f18d1
better doc
cijothomas 11ac77e
Merge branch 'main' into cijothomas/userevents-resource
cijothomas 58a029d
Merge branch 'main' into cijothomas/userevents-resource
cijothomas 2a85018
use cow
cijothomas 6c895a7
Merge branch 'main' into cijothomas/userevents-resource
cijothomas 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
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 |
---|---|---|
|
@@ -78,6 +78,46 @@ | |
//! | ||
//! This will create a logger provider with the `user_events` exporter enabled. | ||
//! | ||
//! ## Resource Attribute Handling | ||
//! | ||
//! **Important**: By default, resource attributes are NOT exported with log records. | ||
//! The user_events exporter only automatically exports these specific resource attributes: | ||
//! | ||
//! - **`service.name`** → Exported as `cloud.roleName` in PartA of Common Schema | ||
//! - **`service.instance.id`** → Exported as `cloud.roleInstance` in PartA of Common Schema | ||
//! | ||
//! All other resource attributes are ignored unless explicitly specified. | ||
//! | ||
//! ### Opting in to Additional Resource Attributes | ||
//! | ||
//! To export additional resource attributes, use the `with_resource_attributes()` method: | ||
//! | ||
//! ```rust | ||
//! use opentelemetry_sdk::logs::SdkLoggerProvider; | ||
//! use opentelemetry_sdk::Resource; | ||
//! use opentelemetry_user_events_logs::Processor; | ||
//! use opentelemetry::KeyValue; | ||
//! | ||
//! let user_event_processor = Processor::builder("myprovider") | ||
//! // Only export specific resource attributes | ||
//! .with_resource_attributes(["custom_attribute1", "custom_attribute2"]) | ||
//! .build() | ||
//! .unwrap(); | ||
//! | ||
//! let provider = SdkLoggerProvider::builder() | ||
//! .with_resource( | ||
//! Resource::builder_empty() | ||
//! .with_service_name("example") | ||
//! .with_attribute(KeyValue::new("custom_attribute1", "value1")) | ||
//! .with_attribute(KeyValue::new("custom_attribute2", "value2")) | ||
//! .with_attribute(KeyValue::new("custom_attribute2", "value3")) // This won't be exported | ||
//! .build(), | ||
//! ) | ||
//! .with_log_processor(user_event_processor) | ||
//! .build(); | ||
//! ``` | ||
//! | ||
//! | ||
//! ## Listening to Exported Events | ||
//! | ||
//! Tools like `perf` or `ftrace` can be used to listen to the exported events. | ||
|
@@ -101,7 +141,7 @@ mod tests { | |
use crate::Processor; | ||
use opentelemetry::trace::Tracer; | ||
use opentelemetry::trace::{TraceContextExt, TracerProvider}; | ||
use opentelemetry::Key; | ||
use opentelemetry::{Key, KeyValue}; | ||
use opentelemetry_appender_tracing::layer; | ||
use opentelemetry_sdk::Resource; | ||
use opentelemetry_sdk::{ | ||
|
@@ -124,10 +164,20 @@ mod tests { | |
|
||
// Basic check if user_events are available | ||
check_user_events_available().expect("Kernel does not support user_events. Verify your distribution/kernel supports user_events: https://docs.kernel.org/trace/user_events.html."); | ||
let user_event_processor = Processor::builder("myprovider").build().unwrap(); | ||
let user_event_processor = Processor::builder("myprovider") | ||
.with_resource_attributes(vec!["resource_attribute1", "resource_attribute2"]) | ||
.build() | ||
.unwrap(); | ||
|
||
let logger_provider = LoggerProviderBuilder::default() | ||
.with_resource(Resource::builder().with_service_name("myrolename").build()) | ||
.with_resource( | ||
Resource::builder() | ||
.with_service_name("myrolename") | ||
.with_attribute(KeyValue::new("resource_attribute1", "v1")) | ||
.with_attribute(KeyValue::new("resource_attribute2", "v2")) | ||
.with_attribute(KeyValue::new("resource_attribute3", "v3")) | ||
.build(), | ||
) | ||
.with_log_processor(user_event_processor) | ||
.build(); | ||
|
||
|
@@ -233,6 +283,12 @@ mod tests { | |
// Validate PartC | ||
let part_c = &event["PartC"]; | ||
assert_eq!(part_c["user_name"].as_str().unwrap(), "otel user"); | ||
assert_eq!(part_c["resource_attribute1"].as_str().unwrap(), "v1"); | ||
assert_eq!(part_c["resource_attribute2"].as_str().unwrap(), "v2"); | ||
assert!( | ||
part_c.get("resource_attribute3").is_none(), | ||
"resource_attribute3 should not be present" | ||
); | ||
assert_eq!( | ||
part_c["user_email"].as_str().unwrap(), | ||
"[email protected]" | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cijothomas is there a typo here?
.with_attribute(KeyValue::new("custom_attribute3", "value3")) // This won't be exported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! yes. Will send a fix