Skip to content

Commit

Permalink
Merge branch 'main' into surface-http-status-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas committed Jan 23, 2024
2 parents dce8f87 + 5b456dd commit c0fbb84
Show file tree
Hide file tree
Showing 6 changed files with 339 additions and 9 deletions.
21 changes: 18 additions & 3 deletions opentelemetry-otlp/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl OtlpPipeline {
OtlpLogPipeline {
log_config: None,
exporter_builder: NoExporterConfig(()),
batch_config: None,
}
}
}
Expand Down Expand Up @@ -124,6 +125,7 @@ impl opentelemetry_sdk::export::logs::LogExporter for LogExporter {
pub struct OtlpLogPipeline<EB> {
exporter_builder: EB,
log_config: Option<opentelemetry_sdk::logs::Config>,
batch_config: Option<opentelemetry_sdk::logs::BatchConfig>,
}

impl<EB> OtlpLogPipeline<EB> {
Expand All @@ -132,6 +134,12 @@ impl<EB> OtlpLogPipeline<EB> {
self.log_config = Some(log_config);
self
}

/// Set the batch log processor configuration, and it will override the env vars.
pub fn with_batch_config(mut self, batch_config: opentelemetry_sdk::logs::BatchConfig) -> Self {
self.batch_config = Some(batch_config);
self
}
}

impl OtlpLogPipeline<NoExporterConfig> {
Expand All @@ -143,6 +151,7 @@ impl OtlpLogPipeline<NoExporterConfig> {
OtlpLogPipeline {
exporter_builder: pipeline.into(),
log_config: self.log_config,
batch_config: self.batch_config,
}
}
}
Expand All @@ -160,7 +169,7 @@ impl OtlpLogPipeline<LogExporterBuilder> {
))
}

/// Install the configured log exporter and a batch span processor using the
/// Install the configured log exporter and a batch log processor using the
/// specified runtime.
///
/// Returns a [`Logger`] with the name `opentelemetry-otlp` and the current crate version.
Expand All @@ -174,6 +183,7 @@ impl OtlpLogPipeline<LogExporterBuilder> {
self.exporter_builder.build_log_exporter()?,
self.log_config,
runtime,
self.batch_config,
))
}
}
Expand Down Expand Up @@ -202,9 +212,14 @@ fn build_batch_with_exporter<R: RuntimeChannel>(
exporter: LogExporter,
log_config: Option<opentelemetry_sdk::logs::Config>,
runtime: R,
batch_config: Option<opentelemetry_sdk::logs::BatchConfig>,
) -> opentelemetry_sdk::logs::Logger {
let mut provider_builder =
opentelemetry_sdk::logs::LoggerProvider::builder().with_batch_exporter(exporter, runtime);
let mut provider_builder = opentelemetry_sdk::logs::LoggerProvider::builder();
let batch_processor = opentelemetry_sdk::logs::BatchLogProcessor::builder(exporter, runtime)
.with_batch_config(batch_config.unwrap_or_default())
.build();
provider_builder = provider_builder.with_log_processor(batch_processor);

if let Some(config) = log_config {
provider_builder = provider_builder.with_config(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ pub mod span {
#[cfg_attr(feature = "with-schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with-serde", serde(rename_all = "camelCase"))]
#[cfg_attr(feature = "with-serde", serde(default))]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Event {
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-proto/tests/grpc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ fn build_tonic() {
"trace.v1.ResourceSpans",
"common.v1.InstrumentationScope",
"resource.v1.Resource",
"trace.v1.Span.Event",
"trace.v1.Span.Status",
] {
builder = builder.type_attribute(
path,
Expand Down
15 changes: 15 additions & 0 deletions opentelemetry-proto/tests/json_deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod json_deserialize {
use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
use opentelemetry_proto::tonic::common::v1::any_value::Value;
use opentelemetry_proto::tonic::common::v1::KeyValue;
use opentelemetry_proto::tonic::trace::v1::span::Event;

// copied from example json file
// see https://github.com/open-telemetry/opentelemetry-proto/blob/v1.0.0/examples/trace.json
Expand Down Expand Up @@ -69,6 +70,13 @@ mod json_deserialize {
}
"#;

const EVENT_JSON: &str = r#"
{
"name": "my_event",
"time_unix_nano": 1234567890
}
"#;

#[test]
fn test_deserialize_traces() {
let request: ExportTraceServiceRequest = serde_json::from_str(TRACES_JSON).unwrap();
Expand Down Expand Up @@ -139,4 +147,11 @@ mod json_deserialize {
Value::StringValue("my.service".to_string())
);
}

#[test]
fn test_event() {
let event_json: Event = serde_json::from_str(EVENT_JSON).unwrap();
assert_eq!(event_json.name, "my_event".to_string());
assert_eq!(event_json.attributes.len(), 0);
}
}
1 change: 1 addition & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- [#1410](https://github.com/open-telemetry/opentelemetry-rust/pull/1410) Add experimental synchronous gauge
- [#1471](https://github.com/open-telemetry/opentelemetry-rust/pull/1471) Configure batch log record processor via [`OTEL_BLRP_*`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#batch-logrecord-processor) environment variables and via `OtlpLogPipeline::with_batch_config`

### Changed

Expand Down
Loading

0 comments on commit c0fbb84

Please sign in to comment.