Package com.tnsai.quality.observability
Class SpanNaming
java.lang.Object
com.tnsai.quality.observability.SpanNaming
Canonical span-name and metric-name builder for TnsAI OpenTelemetry data.
All framework spans and metric counters use the form
tnsai.<module>.<operation> — e.g. tnsai.agent.chat,
tnsai.llm.stream, tnsai.tool.execute. Low-cardinality by
design: providers, models, user IDs, tool names, and other variable values
belong on span attributes, not in the span name. Names that carry
cardinality break dashboards (one series per model) and alerting
(can't group by provider without regex).
Usage
Span span = tracer.spanBuilder(SpanNaming.of("agent", "chat"))
.setAttribute("agent.id", id)
.setAttribute("llm.provider", "openai")
.setAttribute("llm.model", "gpt-4o")
.startSpan();
Exception — provider-scoped LLM spans
LlmInstrumentation predates this convention and uses
<provider>.<operation> <model> to preserve existing dashboards.
New code should prefer SpanNaming.of("llm", "chat") with
llm.provider / llm.model attributes.- Since:
- 0.3.0
-
Field Summary
Fields -
Method Summary
-
Field Details
-
PREFIX
Required prefix for every TnsAI-convention span / metric name.- See Also:
-
-
Method Details
-
of
Builds a canonical nametnsai.<module>.<operation>.Both segments are lower-cased (Locale.ROOT) and validated against
SEGMENT. Upper-case input is tolerated and converted; whitespace, dots, or other punctuation fail fast so malformed names never reach the exporter.- Parameters:
module- short framework module identifier (e.g."agent","llm","tool")operation- the verb being traced (e.g."chat","execute","stream")- Returns:
- canonical name in the form
tnsai.<module>.<operation> - Throws:
IllegalArgumentException- if either segment is null, blank, or contains disallowed characters
-
isCanonical
Returns true ifnamematches the canonical formtnsai.<segment>.<segment>[.<segment>...].Useful for test assertions and ArchUnit rules.
- Parameters:
name- span or metric name to validate- Returns:
- true when name follows the TnsAI convention
-