Skip to content

telemetry: Reduce cardinality of some otel span names#3558

Open
lann wants to merge 2 commits into
mainfrom
otel-reduce-span-name-cardinality
Open

telemetry: Reduce cardinality of some otel span names#3558
lann wants to merge 2 commits into
mainfrom
otel-reduce-span-name-cardinality

Conversation

@lann

@lann lann commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

This PR removes a lot of detail from some span names.

https://github.com/open-telemetry/opentelemetry-specification/blob/v1.56.0/specification/trace/api.md#span

The span name SHOULD be the most general string that identifies a (statistically) interesting class of Spans, rather than individual Span instances while still being human-readable. [...] Generality SHOULD be prioritized over human-readability.

Given that a large number of #[instrument(...)] attrs were being touched anyway, I took this opportunity to split most of them across two (or more) lines, including some lines (but not files) that weren't otherwise updated.

@lann lann requested a review from calebschoepp June 4, 2026 19:15
@lann lann force-pushed the otel-reduce-span-name-cardinality branch from d8b23cd to 6165f42 Compare June 4, 2026 19:26
Comment thread crates/telemetry/src/db.rs Outdated
otel.name = "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)

@rylev rylev left a comment

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'm really not sure the query parsing is worth the hassle. I agree with the goal of this PR, but I'm not convinced that we need to be this clever.

Comment thread crates/factor-outbound-mqtt/src/host.rs Outdated
Comment thread crates/factor-outbound-mqtt/src/host.rs Outdated

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.

Comment thread crates/factor-outbound-mysql/src/host.rs Outdated
Comment thread crates/factor-outbound-mysql/src/host.rs

@calebschoepp calebschoepp left a comment

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.

Overall I think this PR is plugging a big gap in our tracing cardinality risk — I could be convinced to approve this ~as is.

However, I'm feeling vaguely uncomfortable about two things.

  1. The implementation of sql_span_name seems like an endlessly deep tunnel of edge cases. It seems like the kind of code we're going to have to keep coming back to time after time to fix little things. I like that it is dependency free, but did we fully rule out that there isn't an existing library that could solve this problem for us?
  2. It feels like we have a mix of OTel convention span names and "spin style" span names. Maybe this is just fine and we can't do much better, but I feel weird about them being mixed. (I'm also aware this is a bit outside the scope of your PR so feel free to ignore this concern)

Comment thread crates/telemetry/src/db.rs Outdated
async fn execute(
&mut self,
connection: Resource<v2::Connection>,
statement: String,

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.

Do we need to do anything to obfuscate the statement in the attribute?

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 one is tricky. There really shouldn't be anything sensitive in the statement, but of course that isn't going to stop people from doing it. My current opinion is that we should leave it up to the user's telemetry pipeline to deal with that.

@lann

lann commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

I'm fine dropping the SQL stuff but if we aren't going to try to converge on otel conventions then we should come up with our own rationale for what we do want to converge on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants