Skip to content

WIP Micrometer feedback #1940

Draft
nhachicha wants to merge 6 commits intomongodb:mainfrom
nhachicha:nh/micrometer_spring_feedback
Draft

WIP Micrometer feedback #1940
nhachicha wants to merge 6 commits intomongodb:mainfrom
nhachicha:nh/micrometer_spring_feedback

Conversation

@nhachicha
Copy link
Copy Markdown
Collaborator

The driver used a single observation name ("mongodb") for both operation-level and command-level spans, which have different sets of low-cardinality tag keys. Prometheus requires all meters sharing a name to have identical tag key sets, causing the second observation type to be silently dropped.
Split MongodbObservation.MONGODB_OBSERVATION into MONGODB_OPERATION (name "mongodb.operation") and MONGODB_COMMAND (name "mongodb.command"), each declaring its own low-cardinality key set. Updated Tracer and TracingManager to pass the observation type through span creation.
@nhachicha nhachicha self-assigned this Apr 13, 2026
  Connection IDs, cursor IDs, session IDs, transaction numbers, and exception details were tagged as low-cardinality, causing unbounded
  Prometheus metric cardinality since their values change per-connection, per-cursor, or per-error. Moved CLIENT_CONNECTION_ID, SERVER_CONNECTION_ID, CURSOR_ID,TRANSACTION_NUMBER, SESSION_ID, EXCEPTION_MESSAGE, EXCEPTION_TYPE, and EXCEPTION_STACKTRACE from CommandLowCardinalityKeyNames to HighCardinalityKeyNames so they appear only in traces, not in metrics.
  Added tagHighCardinality(KeyValue) and tagHighCardinality(KeyValues) to the Span interface to support string-valued high-cardinality tags alongside the existing BsonDocument overload.
The query text max length configuration constant was stored in every Observation.Context and extracted back in the MicrometerSpan constructor. This value never changes between observations and is not output as any signal. Pass it directly via constructor parameter instead.
Observations were created with Micrometer's generic SenderContext, preventing users from filtering or customizing MongoDB observations
by context type. This blocks the ObservationConvention pattern that Spring Boot needs for tag alignment.
Introduced MongodbContext extending SenderContext<Object> with Kind.CLIENT, giving users a MongoDB-specific type
to register ObservationHandler<MongodbContext> or ObservationConvention<MongodbContext>
instances scoped to only MongoDB observations.
…f TracingManager

Replaced all imperative tagLowCardinality/tagHighCardinality calls with a convention-based approach. TracingManager and InternalStreamConnection now populate domain fields on MongodbContext, and DefaultMongodbObservationConvention reads those fields at stop time to produce the final key-values.

This decouples tag naming from span creation, enabling users to register
a GlobalObservationConvention<MongodbContext> to customize tag names for
their environment (e.g. Spring Boot tag alignment with their existing
DefaultMongoCommandTagsProvider).

Added domain fields to MongodbContext: observationType, commandName,
databaseName, collectionName, serverAddress, connectionId, cursorId,
transactionNumber, sessionId, queryText, responseStatusCode.

Removed tagLowCardinality/tagHighCardinality from the Span interface
as they are no longer used.
@nhachicha nhachicha force-pushed the nh/micrometer_spring_feedback branch from 9b4b0ad to bf91627 Compare April 14, 2026 09:48
Update attribute name for OpenTelemetry
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.

1 participant