@@ -54,22 +54,13 @@ public class MicrometerTracer implements Tracer {
5454 private final ObservationRegistry observationRegistry ;
5555 private final boolean allowCommandPayload ;
5656 private final int textMaxLength ;
57- private static final String QUERY_TEXT_LENGTH_CONTEXT_KEY = "QUERY_TEXT_MAX_LENGTH" ;
5857
5958 /**
6059 * Constructs a new {@link MicrometerTracer} instance.
6160 *
6261 * @param observationRegistry The Micrometer {@link ObservationRegistry} to delegate tracing operations to.
63- */
64- public MicrometerTracer (final ObservationRegistry observationRegistry ) {
65- this (observationRegistry , false , 0 );
66- }
67-
68- /**
69- * Constructs a new {@link MicrometerTracer} instance with an option to allow command payloads.
70- *
71- * @param observationRegistry The Micrometer {@link ObservationRegistry} to delegate tracing operations to.
7262 * @param allowCommandPayload Whether to allow command payloads in the trace context.
63+ * @param textMaxLength The maximum length for query text truncation.
7364 */
7465 public MicrometerTracer (final ObservationRegistry observationRegistry , final boolean allowCommandPayload , final int textMaxLength ) {
7566 this .allowCommandPayload = allowCommandPayload ;
@@ -91,7 +82,7 @@ public Span nextSpan(final MongodbObservation observationType, final String name
9182 }
9283 }
9384
94- return new MicrometerSpan (observation .start (), namespace );
85+ return new MicrometerSpan (observation .start (), namespace , textMaxLength );
9586 }
9687
9788 @ Override
@@ -105,11 +96,9 @@ public boolean includeCommandPayload() {
10596 }
10697
10798 private Observation getObservation (final MongodbObservation observationType , final String name ) {
108- Observation observation = observationType .observation (observationRegistry ,
99+ return observationType .observation (observationRegistry ,
109100 () -> new SenderContext <>((carrier , key , value ) -> {}, Kind .CLIENT ))
110101 .contextualName (name );
111- observation .getContext ().put (QUERY_TEXT_LENGTH_CONTEXT_KEY , textMaxLength );
112- return observation ;
113102 }
114103 /**
115104 * Represents a Micrometer-based trace context.
@@ -139,16 +128,14 @@ private static class MicrometerSpan implements Span {
139128 /**
140129 * Constructs a new {@link MicrometerSpan} instance with an associated Observation and MongoDB namespace.
141130 *
142- * @param observation The Micrometer {@link Observation}, or null if none exists.
143- * @param namespace The MongoDB namespace associated with the span.
131+ * @param observation The Micrometer {@link Observation}, or null if none exists.
132+ * @param namespace The MongoDB namespace associated with the span.
133+ * @param queryTextLength The maximum length for query text truncation.
144134 */
145- MicrometerSpan (final Observation observation , @ Nullable final MongoNamespace namespace ) {
135+ MicrometerSpan (final Observation observation , @ Nullable final MongoNamespace namespace , final int queryTextLength ) {
146136 this .namespace = namespace ;
147137 this .observation = observation ;
148- this .queryTextLength = ofNullable (observation .getContext ().get (QUERY_TEXT_LENGTH_CONTEXT_KEY ))
149- .filter (Integer .class ::isInstance )
150- .map (Integer .class ::cast )
151- .orElse (Integer .MAX_VALUE );
138+ this .queryTextLength = queryTextLength ;
152139 }
153140
154141 @ Override
0 commit comments