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(telemetry): add opentelemetry support #346

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Michael-Preibisch
Copy link

No description provided.

telemetry/src/lib.rs Outdated Show resolved Hide resolved
telemetry/src/lib.rs Outdated Show resolved Hide resolved
telemetry/src/lib.rs Outdated Show resolved Hide resolved
telemetry/src/lib.rs Outdated Show resolved Hide resolved
telemetry/src/lib.rs Outdated Show resolved Hide resolved
telemetry/src/lib.rs Outdated Show resolved Hide resolved
@TheButlah TheButlah changed the title Introduce Opentelemetry feat(telemetry): add opentelemetry support Jan 3, 2025
Comment on lines +49 to +51
service_name: String,
service_version: String,
environment: String,
Copy link
Collaborator

Choose a reason for hiding this comment

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

these three fields seem like they should be a part of the OpenTelemetryConfig struct instead of the main telemetry struct. They won't be used by anything other than opentelemetry.


/// Initialize the OpenTelemetry TracerProvider and set it globally.
fn init_opentelemetry(&self)
-> Result<(trace::TracerProvider, trace::Tracer), Box<dyn std::error::Error>>
Copy link
Collaborator

@TheButlah TheButlah Jan 8, 2025

Choose a reason for hiding this comment

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

FYI: always use eyre::Report instead of Box<dyn std::error::Error>, except in extremely niche scenarios (can't think of any off the top of my head).

But in reality, instead of using eyre::Report or Box<dyn std::error::Error>, lets use the thiserror crate since enum based errors are more suitable for library code than trait object errors.

KeyValue::new("deployment.environment", self.environment.clone()),
]);

let config = self.otel.as_ref().expect("OpenTelemetry config must be present");
Copy link
Collaborator

@TheButlah TheButlah Jan 8, 2025

Choose a reason for hiding this comment

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

perhaps this is a code smell that indicates we should actually have this as a method on OpenTelemetryConfig instead of TelemetryConfig. If we do that, otel will never be None, and its also more clear that this function only should be called when OpenTelemetryConfig is available. Alternatively, it could be a free function (not a method) that takes an OpenTelemetryConfig as an argument, since its just a helper function.


/// Try to initialize telemetry (journald/stderr + optional OTLP).
/// Returns an error if something goes wrong setting up the subscriber stack.
pub fn try_init(self) -> Result<(TelemetryShutdownHandler, Result<(), tracing_subscriber::util::TryInitError>), Box<dyn std::error::Error>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ths type is quite strange. I think you can simplify it by using thiserror for your error type, and the type signature then becomes:

pub fn try_init(self) -> Result<TelemetryShutdownHandler, OrbTelemetryErr> {
    // ...
}


impl Drop for TelemetryShutdownHandler {
fn drop(&mut self) {
global::shutdown_tracer_provider();
Copy link
Collaborator

Choose a reason for hiding this comment

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

what happens if we aren't using opentelemetry at all (for example, if we only did with_journald but did not do with_opentelemetry)? Will this panic?

orb_telemetry::TelemetryConfig::new()
let _telemetry_guard = orb_telemetry::TelemetryConfig::new(
SYSLOG_IDENTIFIER,
env!("CARGO_PKG_VERSION"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

use orb-build-info crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants