Skip to content

Commit f49cd9a

Browse files
WIP
1 parent 012a2f7 commit f49cd9a

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.springframework.data</groupId>
77
<artifactId>spring-data-mongodb-parent</artifactId>
8-
<version>3.4.0-SNAPSHOT</version>
8+
<version>4.0.0-SNAPSHOT</version>
99
<packaging>pom</packaging>
1010

1111
<name>Spring Data MongoDB</name>
@@ -15,7 +15,7 @@
1515
<parent>
1616
<groupId>org.springframework.data.build</groupId>
1717
<artifactId>spring-data-parent</artifactId>
18-
<version>2.7.0-GH-1617-SNAPSHOT</version>
18+
<version>3.0.0-GH-1617-SNAPSHOT</version>
1919
</parent>
2020

2121
<modules>
@@ -26,7 +26,7 @@
2626
<properties>
2727
<project.type>multi</project.type>
2828
<dist.id>spring-data-mongodb</dist.id>
29-
<springdata.commons>2.7.0-SNAPSHOT</springdata.commons>
29+
<springdata.commons>3.0.0-SNAPSHOT</springdata.commons>
3030
<mongo>4.4.1</mongo>
3131
<mongo.reactivestreams>${mongo}</mongo.reactivestreams>
3232
<jmh.version>1.19</jmh.version>

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/observability/MicrometerMongoCommandListener.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public final class MicrometerMongoCommandListener implements CommandListener {
5858

5959
private final MeterRegistry registry;
6060

61-
MicrometerMongoCommandListener(MeterRegistry registry) {
61+
public MicrometerMongoCommandListener(MeterRegistry registry) {
6262
this.registry = registry;
6363
}
6464

@@ -89,9 +89,12 @@ private void setupObservability(CommandStartedEvent event, RequestContext reques
8989
String commandName = event.getCommandName();
9090
BsonDocument command = event.getCommand();
9191
String collectionName = getCollectionName(command, commandName);
92-
String metricName = getMetricName(commandName, collectionName);
93-
Timer.Builder timerBuilder = Timer.builder(metricName);
92+
Timer.Builder timerBuilder = Timer.builder("mongodb.command");
9493
MongoHandlerContext mongoHandlerContext = new MongoHandlerContext(event) {
94+
@Override public String getSimpleName() {
95+
return getMetricName(commandName, collectionName);
96+
}
97+
9598
@Override public Tags getLowCardinalityTags() {
9699
Tags tags = Tags.empty();
97100
if (collectionName != null) {
@@ -109,7 +112,8 @@ private void setupObservability(CommandStartedEvent event, RequestContext reques
109112
}
110113
};
111114
Timer.Sample child = Timer.start(this.registry, mongoHandlerContext);
112-
requestContext.put(mongoHandlerContext, MongoHandlerContext.class);
115+
requestContext.put(Timer.Sample.class, child);
116+
requestContext.put(MongoHandlerContext.class, mongoHandlerContext);
113117
requestContext.put(Timer.Builder.class, timerBuilder);
114118
if (log.isDebugEnabled()) {
115119
log.debug("Created a child sample [" + child

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/observability/MongoHandlerContext.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.mongodb.event.CommandSucceededEvent;
2222
import io.micrometer.core.instrument.Timer;
2323

24-
public class MongoHandlerContext extends Timer.HandlerContext {
24+
public abstract class MongoHandlerContext extends Timer.HandlerContext {
2525

2626
private final CommandStartedEvent commandStartedEvent;
2727

@@ -34,22 +34,24 @@ public MongoHandlerContext(CommandStartedEvent commandStartedEvent) {
3434
}
3535

3636
public CommandStartedEvent getCommandStartedEvent() {
37-
return commandStartedEvent;
37+
return this.commandStartedEvent;
3838
}
3939

4040
public CommandSucceededEvent getCommandSucceededEvent() {
41-
return commandSucceededEvent;
41+
return this.commandSucceededEvent;
4242
}
4343

4444
public void setCommandSucceededEvent(CommandSucceededEvent commandSucceededEvent) {
4545
this.commandSucceededEvent = commandSucceededEvent;
4646
}
4747

4848
public CommandFailedEvent getCommandFailedEvent() {
49-
return commandFailedEvent;
49+
return this.commandFailedEvent;
5050
}
5151

5252
public void setCommandFailedEvent(CommandFailedEvent commandFailedEvent) {
5353
this.commandFailedEvent = commandFailedEvent;
5454
}
55+
56+
public abstract String getSimpleName();
5557
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/observability/MongoTracingRecordingHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@ private void setRemoteIpAndPort(CommandStartedEvent event, Span.Builder spanBuil
7979
@Override public void onStop(Timer.Sample sample, MongoHandlerContext context, Timer timer, Duration duration) {
8080
TracingContext tracingContext = getTracingContext(context);
8181
Span span = tracingContext.getSpan();
82-
span.name(timer.getId().getName());
82+
span.name(context.getSimpleName());
8383
tagSpan(context, timer.getId(), span);
8484
span.end();
8585
}
8686

87+
@Override public boolean supportsContext(Timer.HandlerContext context) {
88+
return context instanceof MongoHandlerContext;
89+
}
90+
8791
public boolean isSetRemoteIpAndPortEnabled() {
8892
return this.setRemoteIpAndPortEnabled;
8993
}

0 commit comments

Comments
 (0)