Skip to content

Commit

Permalink
Merge branch 'main' into chore/integration-test-2
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Dec 16, 2024
2 parents 2eb3eba + c726c4d commit 609a158
Show file tree
Hide file tree
Showing 46 changed files with 708 additions and 425 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
Cargo.lock
/.idea/

.cosine
.cosine

opentelemetry-otlp/tests/integration_test/result.json
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ tonic = { version = "0.12.3", default-features = false }
tonic-build = "0.12"
tokio = { version = "1", default-features = false }
tokio-stream = "0.1"
tracing = { version = "0.1", default-features = false }
tracing-core = { version = "0.1", default-features = false }
# Using `tracing 0.1.40` because 0.1.39 (which is yanked) introduces the ability to set event names in macros,
# required for OpenTelemetry's internal logging macros.
tracing = { version = ">=0.1.40", default-features = false }
# `tracing-core >=0.1.33` is required for compatibility with `tracing >=0.1.40`.
tracing-core = { version = ">=0.1.33", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
url = { version = "2.5", default-features = false }
10 changes: 5 additions & 5 deletions examples/logs-basic/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use opentelemetry::KeyValue;
use opentelemetry_appender_tracing::layer;
use opentelemetry_sdk::logs::LoggerProvider;
use opentelemetry_sdk::Resource;
Expand All @@ -8,10 +7,11 @@ use tracing_subscriber::prelude::*;
fn main() {
let exporter = opentelemetry_stdout::LogExporter::default();
let provider: LoggerProvider = LoggerProvider::builder()
.with_resource(Resource::new(vec![KeyValue::new(
"service.name",
"log-appender-tracing-example",
)]))
.with_resource(
Resource::builder()
.with_service_name("log-appender-tracing-example")
.build(),
)
.with_simple_exporter(exporter)
.build();
let layer = layer::OpenTelemetryTracingBridge::new(&provider);
Expand Down
10 changes: 6 additions & 4 deletions examples/metrics-advanced/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
.build();

let reader = PeriodicReader::builder(exporter).build();

let resource = Resource::builder()
.with_service_name("metrics-advanced-example")
.build();

let provider = SdkMeterProvider::builder()
.with_reader(reader)
.with_resource(Resource::new([KeyValue::new(
"service.name",
"metrics-advanced-example",
)]))
.with_resource(resource)
.with_view(my_view_rename_and_unit)
.with_view(my_view_drop_attributes)
.with_view(my_view_change_aggregation)
Expand Down
9 changes: 5 additions & 4 deletions examples/metrics-basic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
let reader = PeriodicReader::builder(exporter).build();
let provider = SdkMeterProvider::builder()
.with_reader(reader)
.with_resource(Resource::new([KeyValue::new(
"service.name",
"metrics-basic-example",
)]))
.with_resource(
Resource::builder()
.with_service_name("metrics-basic-example")
.build(),
)
.build();
global::set_meter_provider(provider.clone());
provider
Expand Down
10 changes: 5 additions & 5 deletions examples/tracing-jaeger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use opentelemetry::{
};
use opentelemetry_sdk::trace::TracerProvider;
use opentelemetry_sdk::{runtime, Resource};
use opentelemetry_semantic_conventions::resource::SERVICE_NAME;

use std::error::Error;

Expand All @@ -16,10 +15,11 @@ fn init_tracer_provider() -> Result<opentelemetry_sdk::trace::TracerProvider, Tr

Ok(TracerProvider::builder()
.with_batch_exporter(exporter, runtime::Tokio)
.with_resource(Resource::new(vec![KeyValue::new(
SERVICE_NAME,
"tracing-jaeger",
)]))
.with_resource(
Resource::builder()
.with_service_name("tracing-jaeger")
.build(),
)
.build())
}

Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-appender-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,11 +846,11 @@ mod tests {

assert_eq!(logs.len(), 5);
for log in logs {
let body: String = match log.record.body.as_ref().unwrap() {
let body: String = match log.record.body().unwrap() {
super::AnyValue::String(s) => s.to_string(),
_ => panic!("AnyValue::String expected"),
};
assert_eq!(body, log.record.severity_text.unwrap());
assert_eq!(body, log.record.severity_text().unwrap());
}
}

Expand Down
11 changes: 6 additions & 5 deletions opentelemetry-appender-tracing/benches/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use async_trait::async_trait;
use criterion::{criterion_group, criterion_main, Criterion};
use opentelemetry::{InstrumentationScope, KeyValue};
use opentelemetry::InstrumentationScope;
use opentelemetry_appender_tracing::layer as tracing_layer;
use opentelemetry_sdk::export::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::LogResult;
Expand Down Expand Up @@ -126,10 +126,11 @@ fn benchmark_with_ot_layer(c: &mut Criterion, enabled: bool, bench_name: &str) {
let exporter = NoopExporter { enabled };
let processor = NoopProcessor::new(Box::new(exporter));
let provider = LoggerProvider::builder()
.with_resource(Resource::new(vec![KeyValue::new(
"service.name",
"benchmark",
)]))
.with_resource(
Resource::builder_empty()
.with_service_name("benchmark")
.build(),
)
.with_log_processor(processor)
.build();
let ot_layer = tracing_layer::OpenTelemetryTracingBridge::new(&provider);
Expand Down
10 changes: 5 additions & 5 deletions opentelemetry-appender-tracing/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! run with `$ cargo run --example basic
use opentelemetry::KeyValue;
use opentelemetry_appender_tracing::layer;
use opentelemetry_sdk::{logs::LoggerProvider, Resource};
use tracing::error;
Expand All @@ -9,10 +8,11 @@ use tracing_subscriber::prelude::*;
fn main() {
let exporter = opentelemetry_stdout::LogExporter::default();
let provider: LoggerProvider = LoggerProvider::builder()
.with_resource(Resource::new(vec![KeyValue::new(
"service.name",
"log-appender-tracing-example",
)]))
.with_resource(
Resource::builder()
.with_service_name("log-appender-tracing-example")
.build(),
)
.with_simple_exporter(exporter)
.build();
let layer = layer::OpenTelemetryTracingBridge::new(&provider);
Expand Down
38 changes: 14 additions & 24 deletions opentelemetry-appender-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ mod tests {

// Validate common fields
assert_eq!(log.instrumentation.name(), "opentelemetry-appender-tracing");
assert_eq!(log.record.severity_number, Some(Severity::Error));
assert_eq!(log.record.severity_number(), Some(Severity::Error));

// Validate trace context is none.
assert!(log.record.trace_context.is_none());
assert!(log.record.trace_context().is_none());

// Validate attributes
#[cfg(not(feature = "experimental_metadata_attributes"))]
Expand Down Expand Up @@ -428,25 +428,20 @@ mod tests {

// validate common fields.
assert_eq!(log.instrumentation.name(), "opentelemetry-appender-tracing");
assert_eq!(log.record.severity_number, Some(Severity::Error));
assert_eq!(log.record.severity_number(), Some(Severity::Error));

// validate trace context.
assert!(log.record.trace_context.is_some());
assert!(log.record.trace_context().is_some());
assert_eq!(
log.record.trace_context.as_ref().unwrap().trace_id,
log.record.trace_context().unwrap().trace_id,
trace_id_expected
);
assert_eq!(
log.record.trace_context.as_ref().unwrap().span_id,
log.record.trace_context().unwrap().span_id,
span_id_expected
);
assert_eq!(
log.record
.trace_context
.as_ref()
.unwrap()
.trace_flags
.unwrap(),
log.record.trace_context().unwrap().trace_flags.unwrap(),
TraceFlags::SAMPLED
);

Expand Down Expand Up @@ -526,10 +521,10 @@ mod tests {

// Validate common fields
assert_eq!(log.instrumentation.name(), "opentelemetry-appender-tracing");
assert_eq!(log.record.severity_number, Some(Severity::Error));
assert_eq!(log.record.severity_number(), Some(Severity::Error));

// Validate trace context is none.
assert!(log.record.trace_context.is_none());
assert!(log.record.trace_context().is_none());

// Attributes can be polluted when we don't use this feature.
#[cfg(feature = "experimental_metadata_attributes")]
Expand Down Expand Up @@ -605,25 +600,20 @@ mod tests {

// validate common fields.
assert_eq!(log.instrumentation.name(), "opentelemetry-appender-tracing");
assert_eq!(log.record.severity_number, Some(Severity::Error));
assert_eq!(log.record.severity_number(), Some(Severity::Error));

// validate trace context.
assert!(log.record.trace_context.is_some());
assert!(log.record.trace_context().is_some());
assert_eq!(
log.record.trace_context.as_ref().unwrap().trace_id,
log.record.trace_context().unwrap().trace_id,
trace_id_expected
);
assert_eq!(
log.record.trace_context.as_ref().unwrap().span_id,
log.record.trace_context().unwrap().span_id,
span_id_expected
);
assert_eq!(
log.record
.trace_context
.as_ref()
.unwrap()
.trace_flags
.unwrap(),
log.record.trace_context().unwrap().trace_flags.unwrap(),
TraceFlags::SAMPLED
);

Expand Down
7 changes: 3 additions & 4 deletions opentelemetry-otlp/examples/basic-otlp-http/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;

static RESOURCE: Lazy<Resource> = Lazy::new(|| {
Resource::new(vec![KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
"basic-otlp-example",
)])
Resource::builder()
.with_service_name("basic-otlp-example")
.build()
});

fn init_logs() -> Result<sdklogs::LoggerProvider, opentelemetry_sdk::logs::LogError> {
Expand Down
7 changes: 3 additions & 4 deletions opentelemetry-otlp/examples/basic-otlp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;

static RESOURCE: Lazy<Resource> = Lazy::new(|| {
Resource::new(vec![KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
"basic-otlp-example",
)])
Resource::builder()
.with_service_name("basic-otlp-example")
.build()
});

fn init_traces() -> Result<sdktrace::TracerProvider, TraceError> {
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
//! .with_max_events_per_span(64)
//! .with_max_attributes_per_span(16)
//! .with_max_events_per_span(16)
//! .with_resource(Resource::new(vec![KeyValue::new("service.name", "example")])),
//! .with_resource(Resource::builder_empty().with_attributes([KeyValue::new("service.name", "example")]).build()),
//! ).build();
//! global::set_tracer_provider(tracer_provider);
//! let tracer = global::tracer("tracer-name");
Expand All @@ -186,7 +186,7 @@
//!
//! let provider = opentelemetry_sdk::metrics::SdkMeterProvider::builder()
//! .with_reader(reader)
//! .with_resource(Resource::new(vec![KeyValue::new("service.name", "example")]))
//! .with_resource(Resource::builder_empty().with_attributes([KeyValue::new("service.name", "example")]).build())
//! .build();
//! # }
//!
Expand Down
10 changes: 5 additions & 5 deletions opentelemetry-otlp/tests/integration_test/tests/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use ctor::dtor;
use integration_test_runner::logs_asserter::{read_logs_from_json, LogsAsserter};
use integration_test_runner::test_utils;
use log::{info, Level};
use opentelemetry::KeyValue;
use opentelemetry_appender_log::OpenTelemetryLogBridge;
use opentelemetry_otlp::LogExporter;
use opentelemetry_sdk::logs::{LogError, LoggerProvider};
Expand All @@ -31,10 +30,11 @@ fn init_logs() -> Result<sdklogs::LoggerProvider> {

Ok(LoggerProvider::builder()
.with_batch_exporter(exporter, runtime::Tokio)
.with_resource(Resource::new(vec![KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
"logs-integration-test",
)]))
.with_resource(
Resource::builder_empty()
.with_service_name("logs-integration-test")
.build(),
)
.build())
}

Expand Down
9 changes: 5 additions & 4 deletions opentelemetry-otlp/tests/integration_test/tests/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> {

Ok(opentelemetry_sdk::trace::TracerProvider::builder()
.with_batch_exporter(exporter, runtime::Tokio)
.with_resource(Resource::new(vec![KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
"basic-otlp-tracing-example",
)]))
.with_resource(
Resource::builder_empty()
.with_service_name("basic-otlp-tracing-example")
.build(),
)
.build())
}

Expand Down
Loading

0 comments on commit 609a158

Please sign in to comment.