-
Notifications
You must be signed in to change notification settings - Fork 52
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
Implement journald exporter for OpenTelemetry #84
base: main
Are you sure you want to change the base?
Conversation
@TommyCpp had an question on comparing it with the subscriber provided by Tokio tracing library - https://github.com/tokio-rs/tracing/blob/master/tracing-journald/ -
|
comment the json_format option.
This was motivated by the improved downstream developer experience from being pure Rust, and the simplicity of the journald client protocol. It's not significantly more complicated than FFIing to libsystemd, and it dramatically reduces the sensitivity of downstream crates to build environment issues like missing pkg-config files, linking during cross-compilation, etc. |
Thanks, @Ralith, for the background. The concerns regarding build complexities with FFI to C are valid, and we will consider documenting this for the developers. My motivation for using libsystemd is that it internally handles sending large data through memfd, and so abstracting these low-level details. And hopefully being future-proof with any protocol changes :) |
.identifier("opentelemetry-journal-exporter") | ||
.message_size_limit(4 * 1024) | ||
.attribute_prefix(Some("OTEL_".to_string())) | ||
.json_format(true) //uncomment to log in json format |
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.
The comment is unclear.
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, fixed now.
@lalitb Are you planning to resurrect this? I think it makes sense to have a working prototype and merge it in, and mark the status as alpha. |
Yes, let me fix the CI, and make it ready. This would also help to get community contributions. |
version = "0.1.0" | ||
edition = "2021" | ||
keywords = ["opentelemetry", "journald", "logs", "tracing"] | ||
description = "OpenTelemetry logs exporter for journald" |
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.
description = "OpenTelemetry logs exporter for journald" | |
description = "OpenTelemetry Logs Exporter for journald" |
} | ||
} | ||
|
||
fn get_priority(severity: &Severity) -> i32 { |
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.
fn get_priority(severity: &Severity) -> i32 { | |
const fn get_priority(severity: &Severity) -> i32 { |
.skip_while(|&c| c == '_') | ||
.filter(|&c| c == '_' || c.is_ascii_alphanumeric()) | ||
.collect::<String>() | ||
.to_uppercase() |
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.
I think we could avoid an allocation related to uppercase conversion by mapping the characters to upper case before collecting them into a String
.
name.chars()
.map(|c| if c == '.' { '_' } else { c })
.skip_while(|&c| c == '_')
.filter(|&c| c == '_' || c.is_ascii_alphanumeric())
.map(|c| c.to_ascii_uppercase())
.collect::<String>()
.identifier("opentelemetry-journal-exporter") | ||
.message_size_limit(4 * 1024) | ||
.attribute_prefix(Some("OTEL_".to_string())) | ||
.json_format(true) // uncomment to log in JSON format |
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.
Same as #84 (comment)
let send_result = self.send_to_journald(&iovecs); | ||
|
||
if size_exceeded { | ||
return Err(std::io::Error::new( |
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.
Since the default message size limit is zero, does it mean that for a user who did not configure the message size limit explicitly, this method would always return an error?
@@ -0,0 +1,28 @@ | |||
[package] | |||
name = "opentelemetry-journald-logs" |
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.
name = "opentelemetry-journald-logs" | |
name = "opentelemetry-journald" |
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.
How about opentelemetry-exporter-journald
?
name = "opentelemetry-journald-logs" | |
name = "opentelemetry-exporter-journald" |
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.
I like specific names, so opentelemetry-exporter-journald sounds good
opentelemetry = { workspace = true, features = ["logs"] } | ||
opentelemetry_sdk = { workspace = true, features = ["logs"] } | ||
libc = "0.2" | ||
async-trait = "0.1" |
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.
Is this needed?
Changes
This adds
Journald
log exporter for OpenTelemetry, allowing logs to be sent to Journald. Note that this exporter is experimental, and breaking changes are expected. The performance and stability improvements are required, and contributions are welcome.Features:
memfd
can be used for sending large messages.Dependencies:
This implementation relies on the
libsystemd
library for sending log entries to the journald daemon. It usessd_journal_sendv
API method provided by the library.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes