Files
windmill/backend/windmill-common/examples/otlp_smoke.rs
Ruben Fiszel 42d3e8c789 fix: enrich OTEL log records with per-request LogContext (#8812)
* fix: enrich OTEL log records with per-request LogContext

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: add otlp_smoke example for manual OTEL log bridge verification

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: update ee-repo-ref to 5d6b713b74fc46735807f5c32883002e8d976fbc

This commit updates the EE repository reference after PR #529 was merged in windmill-ee-private.

Previous ee-repo-ref: 45959d063bc941c567488d330b5819601cdd2d3d

New ee-repo-ref: 5d6b713b74fc46735807f5c32883002e8d976fbc

Automated by sync-ee-ref workflow.

* refactor: store LogContext in ArcSwap instead of Mutex

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: pin ee-repo-ref to ArcSwap branch commit

* chore: update ee-repo-ref to be2f3d4d11bb7110200524d7157caab3aac53996

This commit updates the EE repository reference after PR #530 was merged in windmill-ee-private.

Previous ee-repo-ref: 45b4d7963a9ebcd583d1a87abe7d07d3d521584a

New ee-repo-ref: be2f3d4d11bb7110200524d7157caab3aac53996

Automated by sync-ee-ref workflow.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
2026-04-13 21:50:50 +00:00

78 lines
2.8 KiB
Rust

//! Manual smoke test for the LogContext → OTLP bridge pipeline.
//!
//! Run a local OTEL collector with:
//! docker run -d --rm --name wm-otelcol --network host \
//! -v /tmp/otel-verify/otelcol-config.yaml:/etc/otelcol-contrib/config.yaml:ro \
//! -v /tmp/otel-verify:/out \
//! otel/opentelemetry-collector-contrib:latest
//!
//! Then run this binary:
//! OTEL_LOGS=1 OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 \
//! cargo run --example otlp_smoke --features enterprise,private,otel \
//! -p windmill-common
//!
//! Inspect the collector's debug output with:
//! docker logs wm-otelcol
//! Or the file sink:
//! cat /tmp/otel-verify/logs.json
use windmill_common::log_context::{update_log_context, with_log_context, LogContext};
use windmill_common::utils::Mode;
#[tokio::main(flavor = "multi_thread")]
async fn main() {
let (_guard, _meter_provider) =
windmill_common::tracing_init::initialize_tracing("otlp-smoke-host", &Mode::Server, "dev");
// Simulate an HTTP request: middleware seeds method/uri, then the auth
// chain adds email/username/workspace_id.
let ctx = LogContext {
method: Some("POST".into()),
uri: Some("/api/w/acme/jobs/run/f/foo".into()),
trace_id: Some("smoke-trace-id-abc-123".into()),
..Default::default()
};
with_log_context(ctx, async {
// Simulate auth middleware running:
update_log_context(|c| LogContext {
email: Some("alice@acme.co".into()),
username: Some("alice".into()),
workspace_id: Some("acme".into()),
..c.clone()
});
// This mimics MyOnResponse::on_response for a 500 error:
tracing::error!(status = 500u16, latency = 123u64, "response");
// And an ad-hoc handler error:
tracing::error!("database connection refused");
})
.await;
// Simulate a worker job context:
let job_ctx = LogContext {
workspace_id: Some("acme".into()),
job_id: Some("00000000-0000-4000-8000-000000000001".into()),
script_path: Some("f/ingest/run".into()),
job_kind: Some("script".into()),
language: Some("python3".into()),
worker: Some("wk-default-smoke".into()),
hostname: Some("otlp-smoke-host".into()),
tag: Some("deno".into()),
..Default::default()
};
with_log_context(job_ctx, async {
tracing::error!("job failed: ValueError: bad input");
})
.await;
// And one event outside any scope to prove it still emits (sans fields):
tracing::error!("background task failure (no context)");
// Give the batch exporter time to flush before we exit.
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
eprintln!("smoke emitted; check `docker logs wm-otelcol` for the debug exporter output");
}