Skip to content

Commit

Permalink
Merge pull request #81 from OneLiteFeatherNET/feat/opentelemetry
Browse files Browse the repository at this point in the history
Feat/opentelemetry
  • Loading branch information
Randoooom authored Jul 8, 2024
2 parents b7a4810 + e6b3b4d commit 90c4524
Show file tree
Hide file tree
Showing 18 changed files with 465 additions and 112 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ common/target/
codegen/target/
tests/
docs/
Makefile.toml
135 changes: 134 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ notify = { version = "6.1.1", default-features = false, features = [
"macos_kqueue",
] }
openidconnect = "3.5.0"
opentelemetry = { version = "0.23.0", optional = true }
opentelemetry_sdk = { version = "0.23.0", optional = true, features = ["rt-tokio"] }
opentelemetry-otlp = { version = "0.16.0", optional = true }
opentelemetry-semantic-conventions = { version = "0.15.0", optional = true }
opentelemetry-http = { version = "0.12.0", optional = true }
paste = "1.0.14"
prost-types = "0.12.4"
rbatis = "4.5.21"
Expand All @@ -49,6 +54,7 @@ tower = "0.4.13"
tokio-retry = "0.3"
tower-http = { version = "=0.4.4", features = ["trace", "validate-request"] }
tracing = "0.1.39"
tracing-opentelemetry = { version = "0.24.0", optional = true }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
typed-builder = "0.18.1"
validator = { version = "0.18", features = ["derive"] }
Expand All @@ -61,8 +67,16 @@ reqwest = { version = "0.12.3", features = ["json"] }
test-log = "0.2.15"

[features]
default = ["all-databases"]
default = ["all-databases", "otlp"]

otlp = [
"opentelemetry",
"opentelemetry-otlp",
"opentelemetry-semantic-conventions",
"opentelemetry_sdk",
"opentelemetry-http",
"tracing-opentelemetry"
]
all-databases = ["postgres", "mysql", "mssql"]
postgres = ["rbdc-pg"]
mysql = ["rbdc-mysql"]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM rust:slim as build

ARG features=all-databases
ARG features=all-databases,otlp

COPY ./Cargo.toml .
COPY ./Cargo.lock .
Expand Down
12 changes: 10 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ export default defineConfig({
text: "Docs",
items: [
{ text: "Configuration", link: "/docs/configuration" },
{ text: "Deployment", items: [
{
text: "Deployment", items: [
{ text: "Helm", link: "/docs/deployment/helm" },
{ text: "Docker", link: "/docs/deployment/docker" }
{ text: "Docker", link: "/docs/deployment/docker" },
{ text: "Verify deployment", link: "/docs/deployment/verify" }
]
},
{
text: "Observability", items: [
{ text: "Logging", link: "/docs/observability/logging" },
{ text: "Tracing", link: "/docs/observability/tracing" }
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ You can set the following environment variables:
| `OIDC_AUDIENCE` | `String` | `"feedback-fusion"` | The audience for the OIDC tokens. |
| `OIDC_ISSUER` | `Option<String>` | `None` | The optional issuer URL for the OIDC tokens. |
| `CONFIG_PATH` | `Option<String>` | `None` | The optional path to the configuration file. (Not Required using the helm chart) |
| `RUST_LOG` | `String` | `None` | The log level for the application. [Possible values](https://docs.rs/log/latest/log/enum.Level.html) |
| `RUST_LOG` | `String` | `None` | The log level for the application. [Possible values](https://docs.rs/log/latest/log/enum.Level.html) |
| `OTLP_ENDPOINT` | `Option<String>` | `None` | The gRPC OTLP endpoint to send the trace spans to |
| `SERVICE_NAME` | `String` | `"feedback-fusion"` | Service name used in tracing context |

## Database Configuration

Expand Down
20 changes: 20 additions & 0 deletions docs/docs/deployment/verify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Verify the deployment

To verify and test the deployment of FeedbackFusion, you can run the integration tests. The following prerequisites and instructions will guide you through the process.

## Prerequisites

- **Rust** installed on your machine.
- **cargo-make** installed. You can install it using the following command:
```sh
cargo install cargo-make
```
- The FeedbackFusion application must be accessible on port 8000 on the machine where the tests are executed. This can be achieved via port-forwarding if using Kubernetes.
- Override the `OIDC_PROVIDER`, `CLIENT_ID` and `CLIENT_SECRET` in the Makefile.

## Running Integration Tests

To run the integration tests, execute the following command:

```sh
cargo make integration_test
11 changes: 11 additions & 0 deletions docs/docs/observability/logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Logging

FeedbackFusion uses the `RUST_LOG` environment variable to control the default logging level of the process. The following table lists the possible values for `RUST_LOG` and describes what each level typically outputs.

| Level | Description |
|---------|---------------------------------------------------------------------------------------------------|
| ERROR | Logs only error messages. |
| WARN | Logs warnings and error messages. |
| INFO | Logs informational messages, warnings, and error messages. |
| DEBUG | Logs debug information, including database requests, informational messages, warnings, and errors.|
| TRACE | Logs everything, including trace-level information, debug information, database requests, informational messages, warnings, and errors. |
15 changes: 15 additions & 0 deletions docs/docs/observability/tracing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# Distributed Tracing

FeedbackFusion supports distributed tracing using the OpenTelemetry Protocol (OTLP) utilizing the `HeaderExtractor` in order
to resolve trace parents.

For more information regarding the documentation checkout the [Configuration](/docs/configuration)

## Example with Jaeger

To configure FeedbackFusion to use Jaeger for distributed tracing, you need to set the `OTLP_ENDPOINT` to Jaeger's default OTLP port:

```sh
OTLP_ENDPOINT=http://jaeger:4317
```
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub struct Config {
oidc_audience: String,
oidc_issuer: Option<String>,
config_path: Option<String>,
otlp_endpoint: Option<String>,
#[serde(default = "default_service_name")]
service_name: String
}

#[inline]
Expand All @@ -56,6 +59,11 @@ fn default_oidc_audience() -> String {
"feedback-fusion".to_owned()
}

#[inline]
fn default_service_name() -> String {
"feedback-fusion".to_owned()
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct InstanceConfig {
targets: Vec<TargetConfig>,
Expand Down
15 changes: 7 additions & 8 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,14 @@ database_configuration!(

#[macro_export]
macro_rules! database_request {
($expr: expr) => {{
let span = info_span!("Database Request");
let _ = span.enter();
$expr
}};
($expr: expr, $title: expr) => {{
let span = info_span!(concat!("Database Request: ", $title));
let _ = span.enter();
$expr
let span = info_span!(concat!("Database request: ", $title));

async {
$expr
}
.instrument(span)
.await
}};
}

Expand Down
Loading

0 comments on commit 90c4524

Please sign in to comment.