-
Notifications
You must be signed in to change notification settings - Fork 289
Upgrade OTel to stop Tokio being pinned #2932
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ use std::{ascii::escape_default, sync::OnceLock, time::Duration}; | |
|
|
||
| use anyhow::bail; | ||
| use opentelemetry::logs::{LogRecord, Logger, LoggerProvider}; | ||
| use opentelemetry_otlp::LogExporterBuilder; | ||
| use opentelemetry_sdk::{ | ||
| logs::{BatchConfigBuilder, BatchLogProcessor, Logger as SdkLogger}, | ||
| resource::{EnvResourceDetector, TelemetryResourceDetector}, | ||
|
|
@@ -86,21 +85,22 @@ pub(crate) fn init_otel_logging_backend(spin_version: String) -> anyhow::Result< | |
| // currently default to using the HTTP exporter but in the future we could select off of the | ||
| // combination of OTEL_EXPORTER_OTLP_PROTOCOL and OTEL_EXPORTER_OTLP_LOGS_PROTOCOL to | ||
| // determine whether we should use http/protobuf or grpc. | ||
| let exporter_builder: LogExporterBuilder = match OtlpProtocol::logs_protocol_from_env() { | ||
| OtlpProtocol::Grpc => opentelemetry_otlp::new_exporter().tonic().into(), | ||
| OtlpProtocol::HttpProtobuf => opentelemetry_otlp::new_exporter().http().into(), | ||
| let exporter = match OtlpProtocol::logs_protocol_from_env() { | ||
|
Collaborator
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. All these log changes seem correct to me. |
||
| OtlpProtocol::Grpc => opentelemetry_otlp::LogExporter::builder() | ||
| .with_tonic() | ||
| .build()?, | ||
| OtlpProtocol::HttpProtobuf => opentelemetry_otlp::LogExporter::builder() | ||
| .with_http() | ||
| .build()?, | ||
| OtlpProtocol::HttpJson => bail!("http/json OTLP protocol is not supported"), | ||
| }; | ||
|
|
||
| let provider = opentelemetry_sdk::logs::LoggerProvider::builder() | ||
| .with_resource(resource) | ||
| .with_log_processor( | ||
| BatchLogProcessor::builder( | ||
| exporter_builder.build_log_exporter()?, | ||
| opentelemetry_sdk::runtime::Tokio, | ||
| ) | ||
| .with_batch_config(BatchConfigBuilder::default().build()) | ||
| .build(), | ||
| BatchLogProcessor::builder(exporter, opentelemetry_sdk::runtime::Tokio) | ||
| .with_batch_config(BatchConfigBuilder::default().build()) | ||
| .build(), | ||
| ) | ||
| .build(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,8 @@ use std::time::Duration; | |
|
|
||
| use anyhow::{bail, Result}; | ||
| use opentelemetry::global; | ||
| use opentelemetry_otlp::MetricsExporterBuilder; | ||
| use opentelemetry_sdk::{ | ||
| metrics::{ | ||
| reader::{DefaultAggregationSelector, DefaultTemporalitySelector}, | ||
| PeriodicReader, SdkMeterProvider, | ||
| }, | ||
| metrics::{PeriodicReader, SdkMeterProvider}, | ||
| resource::{EnvResourceDetector, TelemetryResourceDetector}, | ||
| runtime, Resource, | ||
| }; | ||
|
|
@@ -42,15 +38,15 @@ pub(crate) fn otel_metrics_layer<S: Subscriber + for<'span> LookupSpan<'span>>( | |
| // currently default to using the HTTP exporter but in the future we could select off of the | ||
| // combination of OTEL_EXPORTER_OTLP_PROTOCOL and OTEL_EXPORTER_OTLP_TRACES_PROTOCOL to | ||
| // determine whether we should use http/protobuf or grpc. | ||
| let exporter_builder: MetricsExporterBuilder = match OtlpProtocol::metrics_protocol_from_env() { | ||
| OtlpProtocol::Grpc => opentelemetry_otlp::new_exporter().tonic().into(), | ||
| OtlpProtocol::HttpProtobuf => opentelemetry_otlp::new_exporter().http().into(), | ||
| let exporter = match OtlpProtocol::metrics_protocol_from_env() { | ||
|
Collaborator
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. Metrics changes also make sense to me. |
||
| OtlpProtocol::Grpc => opentelemetry_otlp::MetricExporter::builder() | ||
| .with_tonic() | ||
| .build()?, | ||
| OtlpProtocol::HttpProtobuf => opentelemetry_otlp::MetricExporter::builder() | ||
| .with_http() | ||
| .build()?, | ||
| OtlpProtocol::HttpJson => bail!("http/json OTLP protocol is not supported"), | ||
| }; | ||
| let exporter = exporter_builder.build_metrics_exporter( | ||
| Box::new(DefaultTemporalitySelector::new()), | ||
| Box::new(DefaultAggregationSelector::new()), | ||
| )?; | ||
|
|
||
| let reader = PeriodicReader::builder(exporter, runtime::Tokio).build(); | ||
| let meter_provider = SdkMeterProvider::builder() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ use std::time::Duration; | |
|
|
||
| use anyhow::bail; | ||
| use opentelemetry::{global, trace::TracerProvider}; | ||
| use opentelemetry_otlp::SpanExporterBuilder; | ||
| use opentelemetry_sdk::{ | ||
| resource::{EnvResourceDetector, TelemetryResourceDetector}, | ||
| Resource, | ||
|
|
@@ -35,17 +34,26 @@ pub(crate) fn otel_tracing_layer<S: Subscriber + for<'span> LookupSpan<'span>>( | |
| ); | ||
|
|
||
| // This will configure the exporter based on the OTEL_EXPORTER_* environment variables. | ||
| let exporter_builder: SpanExporterBuilder = match OtlpProtocol::traces_protocol_from_env() { | ||
| OtlpProtocol::Grpc => opentelemetry_otlp::new_exporter().tonic().into(), | ||
| OtlpProtocol::HttpProtobuf => opentelemetry_otlp::new_exporter().http().into(), | ||
| let exporter = match OtlpProtocol::traces_protocol_from_env() { | ||
|
Collaborator
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. You also get a ✅ here to 😄 |
||
| OtlpProtocol::Grpc => opentelemetry_otlp::SpanExporter::builder() | ||
| .with_tonic() | ||
| .build()?, | ||
| OtlpProtocol::HttpProtobuf => opentelemetry_otlp::SpanExporter::builder() | ||
| .with_http() | ||
| .build()?, | ||
| OtlpProtocol::HttpJson => bail!("http/json OTLP protocol is not supported"), | ||
| }; | ||
|
|
||
| let tracer_provider = opentelemetry_otlp::new_pipeline() | ||
| .tracing() | ||
| .with_exporter(exporter_builder) | ||
| .with_trace_config(opentelemetry_sdk::trace::Config::default().with_resource(resource)) | ||
| .install_batch(opentelemetry_sdk::runtime::Tokio)?; | ||
| let span_processor = opentelemetry_sdk::trace::BatchSpanProcessor::builder( | ||
| exporter, | ||
| opentelemetry_sdk::runtime::Tokio, | ||
| ) | ||
| .build(); | ||
|
|
||
| let tracer_provider = opentelemetry_sdk::trace::TracerProvider::builder() | ||
| .with_config(opentelemetry_sdk::trace::Config::default().with_resource(resource)) | ||
| .with_span_processor(span_processor) | ||
| .build(); | ||
|
|
||
| global::set_tracer_provider(tracer_provider.clone()); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to get this working