Skip to content

Telemetry fixes #2857

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

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/factor-outbound-mysql/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<C: Client> v2::HostConnection for InstanceState<C> {
self.open_connection(&address).await
}

#[instrument(name = "spin_outbound_mysql.execute", skip(self, connection), err(level = Level::INFO), fields(otel.kind = "client", db.system = "mysql", otel.name = statement))]
#[instrument(name = "spin_outbound_mysql.execute", skip(self, connection, params), err(level = Level::INFO), fields(otel.kind = "client", db.system = "mysql", otel.name = statement))]
async fn execute(
&mut self,
connection: Resource<Connection>,
Expand All @@ -66,7 +66,7 @@ impl<C: Client> v2::HostConnection for InstanceState<C> {
.await?)
}

#[instrument(name = "spin_outbound_mysql.query", skip(self, connection), err(level = Level::INFO), fields(otel.kind = "client", db.system = "mysql", otel.name = statement))]
#[instrument(name = "spin_outbound_mysql.query", skip(self, connection, params), err(level = Level::INFO), fields(otel.kind = "client", db.system = "mysql", otel.name = statement))]
async fn query(
&mut self,
connection: Resource<Connection>,
Expand Down
4 changes: 2 additions & 2 deletions crates/factor-outbound-pg/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<C: Send + Sync + Client> v2::HostConnection for InstanceState<C> {
self.open_connection(&address).await
}

#[instrument(name = "spin_outbound_pg.execute", skip(self, connection), err(level = Level::INFO), fields(otel.kind = "client", db.system = "postgresql", otel.name = statement))]
#[instrument(name = "spin_outbound_pg.execute", skip(self, connection, params), err(level = Level::INFO), fields(otel.kind = "client", db.system = "postgresql", otel.name = statement))]
async fn execute(
&mut self,
connection: Resource<Connection>,
Expand All @@ -91,7 +91,7 @@ impl<C: Send + Sync + Client> v2::HostConnection for InstanceState<C> {
.await?)
}

#[instrument(name = "spin_outbound_pg.query", skip(self, connection), err(level = Level::INFO), fields(otel.kind = "client", db.system = "postgresql", otel.name = statement))]
#[instrument(name = "spin_outbound_pg.query", skip(self, connection, params), err(level = Level::INFO), fields(otel.kind = "client", db.system = "postgresql", otel.name = statement))]
async fn query(
&mut self,
connection: Resource<Connection>,
Expand Down
2 changes: 1 addition & 1 deletion crates/factor-sqlite/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl v2::HostConnection for InstanceState {
.map(Resource::new_own)
}

#[instrument(name = "spin_sqlite.execute", skip(self, connection), err(level = Level::INFO), fields(otel.kind = "client", db.system = "sqlite", otel.name = query, sqlite.backend = Empty))]
#[instrument(name = "spin_sqlite.execute", skip(self, connection, parameters), err(level = Level::INFO), fields(otel.kind = "client", db.system = "sqlite", otel.name = query, sqlite.backend = Empty))]
async fn execute(
&mut self,
connection: Resource<v2::Connection>,
Expand Down
3 changes: 3 additions & 0 deletions crates/telemetry/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::Duration;

use anyhow::{bail, Result};
use opentelemetry::global;
use opentelemetry_otlp::MetricsExporterBuilder;
use opentelemetry_sdk::{
metrics::{
Expand Down Expand Up @@ -57,6 +58,8 @@ pub(crate) fn otel_metrics_layer<S: Subscriber + for<'span> LookupSpan<'span>>(
.with_resource(resource)
.build();

global::set_meter_provider(meter_provider.clone());

Ok(MetricsLayer::new(meter_provider))
}

Expand Down
13 changes: 6 additions & 7 deletions crates/telemetry/src/traces.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use anyhow::bail;
use opentelemetry::trace::TracerProvider;
use opentelemetry::{global, trace::TracerProvider};
use opentelemetry_otlp::SpanExporterBuilder;
use opentelemetry_sdk::{
resource::{EnvResourceDetector, TelemetryResourceDetector},
Expand Down Expand Up @@ -34,22 +34,21 @@ pub(crate) fn otel_tracing_layer<S: Subscriber + for<'span> LookupSpan<'span>>(
],
);

// This will configure the exporter based on the OTEL_EXPORTER_* environment variables. We
// 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: SpanExporterBuilder = match OtlpProtocol::traces_protocol_from_env() {
// 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(),
OtlpProtocol::HttpJson => bail!("http/json OTLP protocol is not supported"),
};

let tracer_provider = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(exporter)
.with_exporter(exporter_builder)
.with_trace_config(opentelemetry_sdk::trace::Config::default().with_resource(resource))
.install_batch(opentelemetry_sdk::runtime::Tokio)?;

global::set_tracer_provider(tracer_provider.clone());

let env_filter = match EnvFilter::try_from_env("SPIN_OTEL_TRACING_LEVEL") {
Ok(filter) => filter,
// If it isn't set or it fails to parse default to info
Expand Down
Loading