Skip to content

Commit 7652220

Browse files
committed
Hide addresses in telemetry
Signed-off-by: Caleb Schoepp <[email protected]>
1 parent 6143506 commit 7652220

File tree

6 files changed

+34
-3
lines changed

6 files changed

+34
-3
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/factor-outbound-mysql/src/host.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use spin_world::v1::mysql as v1;
55
use spin_world::v2::mysql::{self as v2, Connection};
66
use spin_world::v2::rdbms_types as v2_types;
77
use spin_world::v2::rdbms_types::ParameterValue;
8+
use tracing::field::Empty;
89
use tracing::{instrument, Level};
10+
use url::Url;
911

1012
use crate::client::Client;
1113
use crate::InstanceState;
@@ -38,8 +40,15 @@ impl<C: Client> v2::Host for InstanceState<C> {}
3840

3941
#[async_trait]
4042
impl<C: Client> v2::HostConnection for InstanceState<C> {
41-
#[instrument(name = "spin_outbound_mysql.open_connection", skip(self), err(level = Level::INFO), fields(otel.kind = "client", db.system = "mysql"))]
43+
#[instrument(name = "spin_outbound_mysql.open", skip(self, address), err(level = Level::INFO), fields(otel.kind = "client", db.system = "mysql", db.address = Empty, server.port = Empty, db.namespace = Empty))]
4244
async fn open(&mut self, address: String) -> Result<Resource<Connection>, v2::Error> {
45+
if let Ok(url) = Url::parse(&address) {
46+
let span = tracing::Span::current();
47+
span.record("db.address", url.host_str().unwrap_or_default());
48+
span.record("server.port", url.port().unwrap_or_default());
49+
span.record("db.namespace", url.path().trim_start_matches('/'));
50+
}
51+
4352
if !self
4453
.is_address_allowed(&address)
4554
.await

crates/factor-outbound-pg/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ table = { path = "../table" }
1616
tokio = { version = "1", features = ["rt-multi-thread"] }
1717
tokio-postgres = "0.7"
1818
tracing = { workspace = true }
19+
url = { workspace = true }
1920

2021
[dev-dependencies]
2122
spin-factor-variables = { path = "../factor-variables" }

crates/factor-outbound-pg/src/host.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ use spin_world::v1::rdbms_types as v1_types;
55
use spin_world::v2::postgres::{self as v2, Connection};
66
use spin_world::v2::rdbms_types;
77
use spin_world::v2::rdbms_types::{ParameterValue, RowSet};
8+
use tracing::field::Empty;
89
use tracing::instrument;
910
use tracing::Level;
11+
use url::Url;
1012

1113
use crate::client::Client;
1214
use crate::InstanceState;
@@ -63,8 +65,15 @@ impl<C: Send + Sync + Client> v2::Host for InstanceState<C> {}
6365

6466
#[async_trait]
6567
impl<C: Send + Sync + Client> v2::HostConnection for InstanceState<C> {
66-
#[instrument(name = "spin_outbound_pg.open_connection", skip(self), err(level = Level::INFO), fields(otel.kind = "client", db.system = "postgresql"))]
68+
#[instrument(name = "spin_outbound_pg.open", skip(self, address), err(level = Level::INFO), fields(otel.kind = "client", db.system = "postgresql", db.address = Empty, server.port = Empty, db.namespace = Empty))]
6769
async fn open(&mut self, address: String) -> Result<Resource<Connection>, v2::Error> {
70+
if let Ok(url) = Url::parse(&address) {
71+
let span = tracing::Span::current();
72+
span.record("db.address", url.host_str().unwrap_or_default());
73+
span.record("server.port", url.port().unwrap_or_default());
74+
span.record("db.namespace", url.path().trim_start_matches('/'));
75+
}
76+
6877
if !self
6978
.is_address_allowed(&address)
7079
.await

crates/factor-outbound-redis/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ spin-factors = { path = "../factors" }
1313
spin-world = { path = "../world" }
1414
table = { path = "../table" }
1515
tracing = { workspace = true }
16+
url = { workspace = true }
1617

1718
[dev-dependencies]
1819
spin-factor-variables = { path = "../factor-variables" }

crates/factor-outbound-redis/src/host.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use spin_world::v1::{redis as v1, redis_types};
66
use spin_world::v2::redis::{
77
self as v2, Connection as RedisConnection, Error, RedisParameter, RedisResult,
88
};
9+
use tracing::field::Empty;
910
use tracing::{instrument, Level};
11+
use url::Url;
1012

1113
pub struct InstanceState {
1214
pub allowed_hosts: OutboundAllowedHosts,
@@ -53,8 +55,15 @@ impl v2::Host for crate::InstanceState {
5355

5456
#[async_trait]
5557
impl v2::HostConnection for crate::InstanceState {
56-
#[instrument(name = "spin_outbound_redis.open_connection", skip(self), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis"))]
58+
#[instrument(name = "spin_outbound_redis.open_connection", skip(self, address), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", db.address = Empty, server.port = Empty, db.namespace = Empty))]
5759
async fn open(&mut self, address: String) -> Result<Resource<RedisConnection>, Error> {
60+
if let Ok(url) = Url::parse(&address) {
61+
let span = tracing::Span::current();
62+
span.record("db.address", url.host_str().unwrap_or_default());
63+
span.record("server.port", url.port().unwrap_or_default());
64+
span.record("db.namespace", url.path().trim_start_matches('/'));
65+
}
66+
5867
if !self
5968
.is_address_allowed(&address)
6069
.await

0 commit comments

Comments
 (0)