Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions crates/factor-outbound-mqtt/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ impl v3::HostConnectionWithStore for crate::MqttFactorData {
}

#[instrument(name = "spin_outbound_mqtt.publish", skip(accessor, connection, payload), err(level = Level::INFO),
fields(otel.kind = "producer", otel.name = format!("{} publish", topic), messaging.operation = "publish",
messaging.system = "mqtt"))]
fields(
otel.kind = "producer",
otel.name = "publish",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

publish seems too general. I don't understand why using the "spin_outbound_mqtt.publish" name field would be inappropriate here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that would probably be fine. I was just going for minimal changes: "{topic} publish" -> "publish". 🤷

messaging.operation = "publish",
messaging.system = "mqtt",
messaging.destination.name = topic,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved topic here (per otel semantic conventions)

))]
async fn publish<T: Send>(
accessor: &Accessor<T, Self>,
connection: Resource<v3::Connection>,
Expand Down Expand Up @@ -218,8 +223,13 @@ impl v2::HostConnection for InstanceState {
/// current trace context into the payload yourself.
/// https://w3c.github.io/trace-context-mqtt/#mqtt-v3-recommendation.
#[instrument(name = "spin_outbound_mqtt.publish", skip(self, connection, payload), err(level = Level::INFO),
fields(otel.kind = "producer", otel.name = format!("{} publish", topic), messaging.operation = "publish",
messaging.system = "mqtt"))]
fields(
otel.kind = "producer",
otel.name = "publish",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

messaging.operation = "publish",
messaging.system = "mqtt",
messaging.destination.name = topic,
))]
async fn publish(
&mut self,
connection: Resource<v2::Connection>,
Expand Down
9 changes: 6 additions & 3 deletions crates/factor-outbound-mysql/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@ impl<C: Client> v3::HostConnectionWithStore for MysqlFactorData<C> {
impl<C: Client> v2::Host for InstanceState<C> {}

impl<C: Client> v2::HostConnection for InstanceState<C> {
#[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))]
#[instrument(name = "spin_outbound_mysql.open", skip(self, address), err(level = Level::INFO),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: shouldn't we use skip_all instead of skip(self, address)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds fine but I don't really want to audit all arguments in this PR.

fields(otel.kind = "client", db.system = "mysql", db.address = Empty, server.port = Empty, db.namespace = Empty))]
async fn open(&mut self, address: String) -> Result<Resource<v2::Connection>, v2::Error> {
let mut state = self.0.lock().await;
state.otel.reparent_tracing_span();
state.open_connection(&address).await.map(Resource::new_own)
}

#[instrument(name = "spin_outbound_mysql.execute", skip(self, connection, params), 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 = spin_telemetry::db::sql_span_name(&statement)))]
Comment on lines +170 to +171
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I'm not convinced that using some sort of simplified query representation is better than name being "spin_outbound_mysql.execute" and the statement being captured...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends a lot on your tooling. It doesn't really matter for something like Honeycomb which gives you a lot of flexibility in how you visualize traces, but for e.g. Jaeger you only see a few specific attributes at the top level and span name is a big one.

async fn execute(
&mut self,
connection: Resource<v2::Connection>,
Expand All @@ -184,7 +186,8 @@ impl<C: Client> v2::HostConnection for InstanceState<C> {
.map_err(track_db_error_on_span)
}

#[instrument(name = "spin_outbound_mysql.query", skip(self, connection, params), 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 = spin_telemetry::db::sql_span_name(&statement)))]
async fn query(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that otel consumers lose the knowledge that this comes from the query method.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, though there is quiet a bit of other info available:

code.filepath: [...SNIP...]/crates/factor-outbound-mysql/src/host.rs
code.lineno: 57
code.namespace: spin_factor_outbound_mysql::host

&mut self,
connection: Resource<v2::Connection>,
Expand Down
36 changes: 24 additions & 12 deletions crates/factor-outbound-pg/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ fn v3_params_to_v4(params: Vec<v3::ParameterValue>) -> Vec<v4::ParameterValue> {
}

impl<CF: ClientFactory> v3::HostConnection for InstanceState<CF> {
#[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))]
#[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))]
async fn open(&mut self, address: String) -> Result<Resource<v3::Connection>, v3::Error> {
spin_factor_outbound_networking::record_address_fields(&address);

Expand All @@ -97,7 +98,8 @@ impl<CF: ClientFactory> v3::HostConnection for InstanceState<CF> {
.map_err(v3::Error::from)
}

#[instrument(name = "spin_outbound_pg.execute", skip(self, connection, params), 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 = spin_telemetry::db::sql_span_name(&statement)))]
async fn execute(
&mut self,
connection: Resource<v3::Connection>,
Expand All @@ -113,7 +115,8 @@ impl<CF: ClientFactory> v3::HostConnection for InstanceState<CF> {
.map_err(track_db_error_on_span_v3)
}

#[instrument(name = "spin_outbound_pg.query", skip(self, connection, params), 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 = spin_telemetry::db::sql_span_name(&statement)))]
async fn query(
&mut self,
connection: Resource<v3::Connection>,
Expand Down Expand Up @@ -190,7 +193,8 @@ impl<CF: ClientFactory> v4::HostConnectionBuilder for InstanceState<CF> {
}

impl<CF: ClientFactory> v4::HostConnection for InstanceState<CF> {
#[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))]
#[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))]
async fn open(&mut self, address: String) -> Result<Resource<v4::Connection>, v4::Error> {
spin_factor_outbound_networking::record_address_fields(&address);

Expand All @@ -201,7 +205,8 @@ impl<CF: ClientFactory> v4::HostConnection for InstanceState<CF> {
self.open_connection(&address, None).await
}

#[instrument(name = "spin_outbound_pg.execute", skip(self, connection, params), 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 = spin_telemetry::db::sql_span_name(&statement)))]
async fn execute(
&mut self,
connection: Resource<v4::Connection>,
Expand All @@ -215,7 +220,8 @@ impl<CF: ClientFactory> v4::HostConnection for InstanceState<CF> {
.map_err(track_db_error_on_span_v4)
}

#[instrument(name = "spin_outbound_pg.query", skip(self, connection, params), 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 = spin_telemetry::db::sql_span_name(&statement)))]
async fn query(
&mut self,
connection: Resource<v4::Connection>,
Expand All @@ -238,7 +244,8 @@ impl<CF: ClientFactory> v4::HostConnection for InstanceState<CF> {
impl<CF: ClientFactory> spin_world::spin::postgres4_2_0::postgres::HostConnectionWithStore
for crate::PgFactorData<CF>
{
#[instrument(name = "spin_outbound_pg.open_async", skip(accessor, address), err(level = Level::INFO), fields(otel.kind = "client", db.system = "postgresql", db.address = Empty, server.port = Empty, db.namespace = Empty))]
#[instrument(name = "spin_outbound_pg.open_async", skip(accessor, address), err(level = Level::INFO),
fields(otel.kind = "client", db.system = "postgresql", db.address = Empty, server.port = Empty, db.namespace = Empty))]
async fn open_async<T>(
accessor: &Accessor<T, Self>,
address: String,
Expand All @@ -251,7 +258,8 @@ impl<CF: ClientFactory> spin_world::spin::postgres4_2_0::postgres::HostConnectio
Self::open_connection_async(accessor, &address, None).await
}

#[instrument(name = "spin_outbound_pg.execute", skip(accessor, connection, params), err(level = Level::INFO), fields(otel.kind = "client", db.system = "postgresql", otel.name = statement))]
#[instrument(name = "spin_outbound_pg.execute", skip(accessor, connection, params), err(level = Level::INFO),
fields(otel.kind = "client", db.system = "postgresql", otel.name = spin_telemetry::db::sql_span_name(&statement)))]
async fn execute_async<T>(
accessor: &Accessor<T, Self>,
connection: Resource<v4::Connection>,
Expand All @@ -270,7 +278,8 @@ impl<CF: ClientFactory> spin_world::spin::postgres4_2_0::postgres::HostConnectio
}

#[allow(clippy::type_complexity)] // blame bindgen, clippy, blame bindgen
#[instrument(name = "spin_outbound_pg.query_async", skip(accessor, params), err(level = Level::INFO), fields(otel.kind = "client", db.system = "postgresql", otel.name = statement))]
#[instrument(name = "spin_outbound_pg.query_async", skip(accessor, params), err(level = Level::INFO),
fields(otel.kind = "client", db.system = "postgresql", otel.name = spin_telemetry::db::sql_span_name(&statement)))]
async fn query_async<T>(
accessor: &Accessor<T, Self>,
connection: Resource<v4::Connection>,
Expand Down Expand Up @@ -446,7 +455,8 @@ macro_rules! delegate {
impl<CF: ClientFactory> v2::Host for InstanceState<CF> {}

impl<CF: ClientFactory> v2::HostConnection for InstanceState<CF> {
#[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))]
#[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))]
async fn open(&mut self, address: String) -> Result<Resource<v2::Connection>, v2::Error> {
self.otel.reparent_tracing_span();
spin_factor_outbound_networking::record_address_fields(&address);
Expand All @@ -460,7 +470,8 @@ impl<CF: ClientFactory> v2::HostConnection for InstanceState<CF> {
.map_err(v2::Error::from)
}

#[instrument(name = "spin_outbound_pg.execute", skip(self, connection, params), 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 = spin_telemetry::db::sql_span_name(&statement)))]
async fn execute(
&mut self,
connection: Resource<v2::Connection>,
Expand All @@ -480,7 +491,8 @@ impl<CF: ClientFactory> v2::HostConnection for InstanceState<CF> {
.map_err(track_db_error_on_span_v2)
}

#[instrument(name = "spin_outbound_pg.query", skip(self, connection, params), 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 = spin_telemetry::db::sql_span_name(&statement)))]
async fn query(
&mut self,
connection: Resource<v2::Connection>,
Expand Down
Loading
Loading