Skip to content

Commit

Permalink
feat: Devmode tracing with OpenTelemetry
Browse files Browse the repository at this point in the history
* Adds a compose with Jaeger and OTELCOL
* Fixes a problem with actix-web tracing
  • Loading branch information
helio-frota committed Jan 23, 2025
1 parent efc14da commit f63bbea
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common/infrastructure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mime = { workspace = true }
openssl = { workspace = true }
opentelemetry = { workspace = true }
opentelemetry-otlp = { workspace = true }
opentelemetry_sdk = { workspace = true, features = ["rt-tokio"] }
opentelemetry_sdk = { workspace = true, features = ["rt-tokio-current-thread"] }
parking_lot = { workspace = true }
prometheus = { workspace = true }
reqwest = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions common/infrastructure/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ fn init_otlp(name: &str) {
"service.name",
name.to_string(),
)]))
.with_batch_exporter(exporter, opentelemetry_sdk::runtime::Tokio)
.with_batch_exporter(exporter, opentelemetry_sdk::runtime::TokioCurrentThread)
.with_sampler(opentelemetry_sdk::trace::Sampler::ParentBased(Box::new(
sampler(),
)))
.build();

println!("Using Jaeger tracing.");
println!("Using OTEL Collector with Jaeger as the back-end.");
println!("{:#?}", provider);

let formatting_layer = tracing_subscriber::fmt::Layer::default();
Expand All @@ -142,6 +142,7 @@ fn init_otlp(name: &str) {
{
eprintln!("Error initializing tracing: {:?}", e);
}
opentelemetry::global::set_tracer_provider(provider);
}

fn init_no_tracing() {
Expand Down
23 changes: 23 additions & 0 deletions docs/design/log_tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,26 @@ However, not all function variants might expose the same behavior. Just because
mean it will panic. For example, the `Option::unwrap_or` function:

![Screenshot of rustdoc for Option::unwrap_or](drawings/log_tracing_2.png)

## Sending traces to OpenTelemetry Collector (devmode)

Jaeger and OTEL Collector:

```shell
podman compose -f etc/dev-traces/compose.yaml up
```

Database:

```shell
podman compose -f etc/deploy/compose/compose.yaml up
```

Trustify with traces:

```shell
OTEL_TRACES_SAMPLER_ARG=1 OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317" cargo run --bin trustd api --db-password trustify --devmode --auth-disabled --tracing enabled
```

Access Trustify at [localhost:8080](http://localhost:8080) and analyze the traces using the [Jaeger UI](http://localhost:16686/)

17 changes: 17 additions & 0 deletions etc/dev-traces/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
jaeger-all-in-one:
hostname: jaeger-all-in-one
image: jaegertracing/all-in-one:1.53.0 # Using this version to align with trustify-helm-charts
ports:
- "16686:16686"
- "14250:14250"
environment:
- COLLECTOR_OTLP_ENABLED=true
collector:
image: ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector:0.115.1 # Using this version to align with trustify-helm-charts https://github.com/TylerHelmuth/opentelemetry-helm-charts/commit/86188fea6022a6424ef6a086e928d0056fb5dfe8#diff-55020f2b796ba5770731a3b4913592732431ff180c7f7473e5f469e92ed00e74R48
command: ["--config=/otel-collector-config.yaml"]
volumes:
- './config.yaml:/otel-collector-config.yaml:z'
ports:
- "4317:4317"
depends_on: [jaeger-all-in-one]
23 changes: 23 additions & 0 deletions etc/dev-traces/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"

exporters:
otlp:
endpoint: jaeger-all-in-one:4317
tls:
insecure: true
debug:
verbosity: detailed

processors:
batch: {}

service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [debug, otlp]

0 comments on commit f63bbea

Please sign in to comment.