-
Notifications
You must be signed in to change notification settings - Fork 570
feat: replace OtlpPipeline with exporter builders #2221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
b836ece
98d3e87
dbdc440
fa1cdb8
dadf93b
f8dd808
43d5857
68c0fb1
12ea48b
563c780
6e27d29
8070e45
d6ab3de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,14 @@ use opentelemetry::{ | |
KeyValue, | ||
}; | ||
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; | ||
use opentelemetry_otlp::Protocol; | ||
use opentelemetry_otlp::{HttpExporterBuilder, WithExportConfig}; | ||
use opentelemetry_sdk::trace::{self as sdktrace, Config}; | ||
use opentelemetry_otlp::WithExportConfig; | ||
use opentelemetry_otlp::{LogExporter, MetricsExporter, Protocol, SpanExporter}; | ||
use opentelemetry_sdk::{ | ||
logs::LoggerProvider, | ||
metrics::{PeriodicReader, SdkMeterProvider}, | ||
runtime, | ||
trace::{self as sdktrace, Config, TracerProvider}, | ||
}; | ||
use opentelemetry_sdk::{ | ||
logs::{self as sdklogs}, | ||
Resource, | ||
|
@@ -18,6 +23,9 @@ use tracing::info; | |
use tracing_subscriber::prelude::*; | ||
use tracing_subscriber::EnvFilter; | ||
|
||
#[cfg(feature = "hyper")] | ||
use opentelemetry_otlp::WithHttpConfig; | ||
|
||
#[cfg(feature = "hyper")] | ||
mod hyper; | ||
|
||
|
@@ -28,47 +36,46 @@ static RESOURCE: Lazy<Resource> = Lazy::new(|| { | |
)]) | ||
}); | ||
|
||
fn http_exporter() -> HttpExporterBuilder { | ||
let exporter = opentelemetry_otlp::new_exporter().http(); | ||
fn init_logs() -> Result<sdklogs::LoggerProvider, opentelemetry::logs::LogError> { | ||
let exporter_builder = LogExporter::builder() | ||
.with_http() | ||
.with_endpoint("http://localhost:4318/v1/logs") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible for endpoint, protocol to take defaults, so users does not have to specify this (unless they want nondefaults) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call out, The defaults should already be getting used as they were before, including the I also changed the type of the endpoint field to |
||
.with_protocol(Protocol::HttpBinary); | ||
|
||
#[cfg(feature = "hyper")] | ||
let exporter = exporter.with_http_client(hyper::HyperClient::default()); | ||
exporter | ||
} | ||
let exporter_builder = exporter_builder.with_http_client(hyper::HyperClient::default()); | ||
|
||
fn init_logs() -> Result<sdklogs::LoggerProvider, opentelemetry::logs::LogError> { | ||
opentelemetry_otlp::new_pipeline() | ||
.logging() | ||
let exporter = exporter_builder.build()?; | ||
|
||
Ok(LoggerProvider::builder() | ||
.with_batch_exporter(exporter, runtime::Tokio) | ||
.with_resource(RESOURCE.clone()) | ||
.with_exporter( | ||
http_exporter() | ||
.with_protocol(Protocol::HttpBinary) //can be changed to `Protocol::HttpJson` to export in JSON format | ||
.with_endpoint("http://localhost:4318/v1/logs"), | ||
) | ||
.install_batch(opentelemetry_sdk::runtime::Tokio) | ||
.build()) | ||
} | ||
|
||
fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> { | ||
opentelemetry_otlp::new_pipeline() | ||
.tracing() | ||
.with_exporter( | ||
http_exporter() | ||
.with_protocol(Protocol::HttpBinary) //can be changed to `Protocol::HttpJson` to export in JSON format | ||
.with_endpoint("http://localhost:4318/v1/traces"), | ||
) | ||
.with_trace_config(Config::default().with_resource(RESOURCE.clone())) | ||
.install_batch(opentelemetry_sdk::runtime::Tokio) | ||
let exporter = SpanExporter::builder() | ||
.with_http() | ||
.with_protocol(Protocol::HttpBinary) //can be changed to `Protocol::HttpJson` to export in JSON format | ||
.with_endpoint("http://localhost:4318/v1/traces") | ||
.build()?; | ||
Ok(TracerProvider::builder() | ||
.with_batch_exporter(exporter, runtime::Tokio) | ||
.with_config(Config::default().with_resource(RESOURCE.clone())) | ||
.build()) | ||
} | ||
|
||
fn init_metrics() -> Result<opentelemetry_sdk::metrics::SdkMeterProvider, MetricsError> { | ||
opentelemetry_otlp::new_pipeline() | ||
.metrics(opentelemetry_sdk::runtime::Tokio) | ||
.with_exporter( | ||
http_exporter() | ||
.with_protocol(Protocol::HttpBinary) //can be changed to `Protocol::HttpJson` to export in JSON format | ||
.with_endpoint("http://localhost:4318/v1/metrics"), | ||
) | ||
let exporter = MetricsExporter::builder() | ||
.with_http() | ||
.with_protocol(Protocol::HttpBinary) //can be changed to `Protocol::HttpJson` to export in JSON format | ||
.with_endpoint("http://localhost:4318/v1/metrics") | ||
.build()?; | ||
|
||
Ok(SdkMeterProvider::builder() | ||
.with_reader(PeriodicReader::builder(exporter, runtime::Tokio).build()) | ||
.with_resource(RESOURCE.clone()) | ||
.build() | ||
.build()) | ||
} | ||
|
||
#[tokio::main] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ use opentelemetry::{ | |
KeyValue, | ||
}; | ||
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; | ||
use opentelemetry_otlp::{ExportConfig, WithExportConfig}; | ||
use opentelemetry_otlp::{LogExporter, MetricsExporter, SpanExporter, WithExportConfig}; | ||
use opentelemetry_sdk::logs::LoggerProvider; | ||
use opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider}; | ||
use opentelemetry_sdk::trace::Config; | ||
use opentelemetry_sdk::{runtime, trace as sdktrace, Resource}; | ||
use std::error::Error; | ||
|
@@ -24,43 +26,37 @@ static RESOURCE: Lazy<Resource> = Lazy::new(|| { | |
}); | ||
|
||
fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> { | ||
opentelemetry_otlp::new_pipeline() | ||
.tracing() | ||
.with_exporter( | ||
opentelemetry_otlp::new_exporter() | ||
.tonic() | ||
.with_endpoint("http://localhost:4317"), | ||
) | ||
.with_trace_config(Config::default().with_resource(RESOURCE.clone())) | ||
.install_batch(runtime::Tokio) | ||
let exporter = SpanExporter::builder() | ||
.with_tonic() | ||
.with_endpoint("http://localhost:4317") | ||
.build()?; | ||
Ok(sdktrace::TracerProvider::builder() | ||
.with_config(Config::default().with_resource(RESOURCE.clone())) | ||
.with_batch_exporter(exporter, runtime::Tokio) | ||
.build()) | ||
} | ||
|
||
fn init_metrics() -> Result<opentelemetry_sdk::metrics::SdkMeterProvider, MetricsError> { | ||
let export_config = ExportConfig { | ||
endpoint: "http://localhost:4317".to_string(), | ||
..ExportConfig::default() | ||
}; | ||
opentelemetry_otlp::new_pipeline() | ||
.metrics(runtime::Tokio) | ||
.with_exporter( | ||
opentelemetry_otlp::new_exporter() | ||
.tonic() | ||
.with_export_config(export_config), | ||
) | ||
let exporter = MetricsExporter::builder().with_tonic().build()?; | ||
|
||
let reader = PeriodicReader::builder(exporter, runtime::Tokio).build(); | ||
|
||
Ok(SdkMeterProvider::builder() | ||
.with_reader(reader) | ||
.with_resource(RESOURCE.clone()) | ||
.build() | ||
.build()) | ||
} | ||
|
||
fn init_logs() -> Result<opentelemetry_sdk::logs::LoggerProvider, LogError> { | ||
opentelemetry_otlp::new_pipeline() | ||
.logging() | ||
let exporter = LogExporter::builder() | ||
.with_tonic() | ||
.with_endpoint("http://localhost:4317") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one inconsistency I notice between grpc and http is the end point - one has to append /v1/logs in http, but grpc does not require that. This is something we can address in a follow up. if user wish to change defaults, then they can use methods like with_endpoint, with_protocol etc. Lets come back to this after merging this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good, after my most recent update, the I will however need to look at the spec to see how the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
EDIT: After looking back through the code, this should also already be the case, I made some changes to make it a little more clear |
||
.build()?; | ||
|
||
Ok(LoggerProvider::builder() | ||
.with_resource(RESOURCE.clone()) | ||
.with_exporter( | ||
opentelemetry_otlp::new_exporter() | ||
.tonic() | ||
.with_endpoint("http://localhost:4317"), | ||
) | ||
.install_batch(runtime::Tokio) | ||
.with_batch_exporter(exporter, runtime::Tokio) | ||
.build()) | ||
} | ||
|
||
#[tokio::main] | ||
|
Uh oh!
There was an error while loading. Please reload this page.