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

update opentelemetry #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 7 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,17 @@ serde = { version = "1", optional = true }
serde_json = { version = "1", optional = true }
tower = { version = "0.4", optional = true }
tower-http = { version = "0.6", optional = true, features = ["normalize-path"] }
opentelemetry = { version = "0.22", optional = true }
opentelemetry-otlp = { version = "0.15", optional = true, features = [
"grpc-tonic",
] }
axum-tracing-opentelemetry = { version = "0.18", optional = true }
init-tracing-opentelemetry = { version = "0.18", optional = true, features = [
"otlp",
"tracing_subscriber_ext",
] }
tracing-opentelemetry-instrumentation-sdk = { version = "0.18", optional = true }
tracing-subscriber = { version = "0.3.18", optional = true, features = [
"env-filter",
"json",
] }
opentelemetry = { version = "0.27.0", optional = true }
opentelemetry-otlp = { version = "0.27.0", optional = true, features = ["grpc-tonic"] }
axum-tracing-opentelemetry = { version = "0.23.0", optional = true }
init-tracing-opentelemetry = { version = "0.23.0", optional = true, features = ["otlp", "tracing_subscriber_ext"] }
tracing-opentelemetry-instrumentation-sdk = { version = "0.23.0", optional = true }
tracing-subscriber = { version = "0.3.18", optional = true, features = ["env-filter", "json"] }
tracing = { version = "0.1.40", optional = true }
mongodb = { version = "2.8.0", optional = true }

[dependencies.loco-rs]
version = "0.11.1"
version = "0.12.0"
default-features = true
features = ["with-db", "auth_jwt"]

Expand Down
25 changes: 24 additions & 1 deletion src/initializers/opentelemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,31 @@ This initializer is responsible for initializing tracing with opentelemetry and

Because opentelemetry tracing initializer is not compatible with loco's default tracing initialization we must turn off the default logging.

Follow the below steps in order to enable initializer:

1) Add opentelemetry initializer to initializers list
```
async fn initializers(_ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
Ok(vec![
Box::new(loco_extras::initializers::opentelemetry::OpenTelemetryInitializer)
])
}
```

2) Add function that disables initialization of logger
````
fn init_logger(_config: &config::Config, _env: &Environment) -> Result<bool> {
Ok(true)
}
````
````

# Local development:

You can run jaeger locally via docker for development purposes.
```
docker run --rm --name jaeger -d -p 5778:5778 -p 16686:16686 -p 4317:4317 -p 4318:4318 -p 14250:14250 -p 14268:14268 -p 9411:9411 jaegertracing/jaeger:2.0.0 --set receivers.otlp.protocols.http.endpoint=0.0.0.0:4318 --set receivers.otlp.protocols.grpc.endpoint=0.0.0.0:4317
```
You can find more information on jaeger's [documentation](https://www.jaegertracing.io/docs/2.0/getting-started/)

Reference [OpenTelemetry SDK configuration](https://opentelemetry.io/docs/concepts/sdk-configuration/general-sdk-configuration/)
for configuring opentelemetry via environmental variables
9 changes: 4 additions & 5 deletions src/initializers/opentelemetry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use axum::{async_trait, Router as AxumRouter};
use axum_tracing_opentelemetry::middleware::{OtelAxumLayer, OtelInResponseLayer};
use loco_rs::{
app::{AppContext, Initializer},
Error, Result,
};
use async_trait::async_trait;
use axum::Router as AxumRouter;
use loco_rs::prelude::*;

#[allow(clippy::module_name_repetitions)]
pub struct OpenTelemetryInitializer;

#[async_trait]
Expand Down