-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLATFORM-1471]: Add e2e tests for tracing (#90)
- Loading branch information
Showing
8 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
version: "3" | ||
|
||
services: | ||
app: | ||
user: root | ||
build: . | ||
volumes: | ||
- .:/code | ||
- "app:/home/app/" | ||
- "~/.ssh:/home/app/.ssh" | ||
- "~/.aws:/home/app/.aws" | ||
- "~/.gitconfig:/home/app/.gitconfig" | ||
- "~/.gitignore:/home/app/.gitignore" | ||
working_dir: /code | ||
ports: | ||
- "3000:3000" | ||
depends_on: | ||
- jaeger | ||
environment: | ||
BUILD_ENV: dev | ||
CARGO_HOME: /home/app/.cargo | ||
CARGO_TARGET_DIR: /home/app/target | ||
CARGO_MAKE_DISABLE_UPDATE_CHECK: 1 | ||
networks: | ||
- default | ||
|
||
jaeger: | ||
image: jaegertracing/all-in-one:1.35 | ||
ports: | ||
- "16685:16685" | ||
- "55681:55681" | ||
environment: | ||
COLLECTOR_OTLP_ENABLED: "true" | ||
COLLECTOR_OTLP_HTTP_HOST_PORT: 55681 | ||
|
||
volumes: | ||
app: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use opentelemetry_jaeger::testing::jaeger_api_v2::Span; | ||
use opentelemetry_jaeger::testing::jaeger_client::JaegerTestClient; | ||
use prima_tracing::{builder, configure_subscriber, init_subscriber, Country, Environment}; | ||
use std::time::SystemTime; | ||
|
||
async fn get_spans(f: impl FnOnce()) -> Option<Vec<Span>> { | ||
std::env::set_var("RUST_LOG", "info"); | ||
|
||
// Unique id for this test run | ||
let seed = SystemTime::now() | ||
.duration_since(SystemTime::UNIX_EPOCH) | ||
.unwrap() | ||
.as_millis(); | ||
let service_name = format!("e2e-test-{seed}"); | ||
|
||
let collector_url = "http://jaeger:55681"; | ||
let query_api_url = "http://jaeger:16685"; | ||
|
||
let subscriber = configure_subscriber( | ||
builder(&service_name) | ||
.with_country(Country::Common) | ||
.with_env(Environment::Dev) | ||
.with_telemetry(collector_url.to_string(), service_name.clone()) | ||
.build(), | ||
); | ||
|
||
{ | ||
let _guard = init_subscriber(subscriber); | ||
f() | ||
} | ||
|
||
let mut client = JaegerTestClient::new(query_api_url); | ||
|
||
if !client.contain_service(&service_name).await { | ||
None | ||
} else { | ||
let spans = client.find_traces_from_services(&service_name).await; | ||
Some(spans) | ||
} | ||
} | ||
|
||
#[cfg(feature = "traces")] | ||
#[tokio::test(flavor = "multi_thread")] | ||
async fn it_sends_traces_to_jaeger() { | ||
let log_message = "hello it_sends_traces_to_jaeger"; | ||
|
||
let spans = get_spans(|| { | ||
let span = tracing::info_span!("my span"); | ||
span.in_scope(|| { | ||
tracing::info!("{log_message}"); | ||
}); | ||
}) | ||
.await | ||
.expect("Failed to fetch traces from jaeger"); | ||
|
||
assert_eq!(spans.len(), 1); | ||
assert_eq!(spans[0].logs.len(), 1); | ||
|
||
let msg = spans[0].logs[0].fields[0].v_str.as_str(); | ||
assert_eq!(log_message, msg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod e2e; |