Skip to content

Commit d486cdb

Browse files
Incorporate review feedback
1 parent 78ffee2 commit d486cdb

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/metrics/MetricsClientStreamTracers.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
final class MetricsClientStreamTracers {
4949
private static final Supplier<Stopwatch> STOPWATCH_SUPPLIER = Stopwatch::createUnstarted;
5050
private final Supplier<Stopwatch> stopwatchSupplier;
51+
private static final String INSTRUMENTATION_SOURCE_TAG_KEY = "instrumentation_source";
52+
private static final String INSTRUMENTATION_VERSION_TAG_KEY = "instrumentation_version";
5153

5254
MetricsClientStreamTracers() {
5355
this(STOPWATCH_SUPPLIER);
@@ -130,8 +132,8 @@ void recordFinishedAttempt() {
130132
Tags attemptMetricTags =
131133
Tags.of("grpc.method", fullMethodName,
132134
"grpc.status", statusCode.toString(),
133-
"instrumentation_source", Constants.INSTRUMENTATION_SOURCE_TAG_VALUE,
134-
"instrumentation_version", Constants.PROJECT_VERSION);
135+
INSTRUMENTATION_SOURCE_TAG_KEY, Constants.LIBRARY_NAME,
136+
INSTRUMENTATION_VERSION_TAG_KEY, Constants.VERSION);
135137
this.metricsClientMeters.getClientAttemptDuration()
136138
.withTags(attemptMetricTags)
137139
.record(attemptNanos, TimeUnit.NANOSECONDS);
@@ -173,8 +175,8 @@ static final class CallAttemptsTracerFactory extends ClientStreamTracer.Factory
173175
// Record here in case newClientStreamTracer() would never be called.
174176
this.metricsClientMeters.getAttemptCounter()
175177
.withTags(Tags.of("grpc.method", fullMethodName,
176-
"instrumentation_source", Constants.INSTRUMENTATION_SOURCE_TAG_VALUE,
177-
"instrumentation_version", Constants.PROJECT_VERSION))
178+
INSTRUMENTATION_SOURCE_TAG_KEY, Constants.LIBRARY_NAME,
179+
INSTRUMENTATION_VERSION_TAG_KEY, Constants.VERSION))
178180
.increment();
179181
}
180182

@@ -195,8 +197,8 @@ public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata metada
195197
if (attemptsPerCall.get() > 0) {
196198
this.metricsClientMeters.getAttemptCounter()
197199
.withTags((Tags.of("grpc.method", fullMethodName,
198-
"instrumentation_source", Constants.INSTRUMENTATION_SOURCE_TAG_VALUE,
199-
"instrumentation_version", Constants.PROJECT_VERSION)))
200+
INSTRUMENTATION_SOURCE_TAG_KEY, Constants.LIBRARY_NAME,
201+
INSTRUMENTATION_VERSION_TAG_KEY, Constants.VERSION)))
200202
.increment();
201203
}
202204
if (!info.isTransparentRetry()) {
@@ -258,8 +260,8 @@ void recordFinishedCall() {
258260
Tags clientCallMetricTags =
259261
Tags.of("grpc.method", this.fullMethodName,
260262
"grpc.status", status.getCode().toString(),
261-
"instrumentation_source", Constants.INSTRUMENTATION_SOURCE_TAG_VALUE,
262-
"instrumentation_version", Constants.PROJECT_VERSION);
263+
INSTRUMENTATION_SOURCE_TAG_KEY, Constants.LIBRARY_NAME,
264+
INSTRUMENTATION_VERSION_TAG_KEY, Constants.VERSION);
263265
this.metricsClientMeters.getClientCallDuration()
264266
.withTags(clientCallMetricTags)
265267
.record(callLatencyNanos, TimeUnit.NANOSECONDS);

grpc-client-spring-boot-starter/src/test/java/net/devh/boot/grpc/client/metrics/MetricsClientStreamTracersTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class MetricsClientStreamTracersTest {
6363
private static final String GRPC_STATUS_TAG_KEY = "grpc.status";
6464
private static final String FULL_METHOD_NAME = "package1.service1/method1";
6565
private static final String INSTRUMENTATION_SOURCE_TAG_KEY = "instrumentation_source";
66-
private static final String INSTRUMENTATION_SOURCE_TAG_VALUE = Constants.INSTRUMENTATION_SOURCE_TAG_VALUE;
66+
private static final String INSTRUMENTATION_SOURCE_TAG_VALUE = Constants.LIBRARY_NAME;
6767
private static final String INSTRUMENTATION_VERSION_TAG_KEY = "instrumentation_version";
68-
private static final String INSTRUMENTATION_VERSION_TAG_VALUE = Constants.PROJECT_VERSION;
68+
private static final String INSTRUMENTATION_VERSION_TAG_VALUE = Constants.VERSION;
6969

7070
private static class StringInputStream extends InputStream {
7171
final String string;

grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/util/Constants.java.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public final class Constants {
2424
/**
2525
* A constant that defines the current version of the library.
2626
*/
27-
public static final String PROJECT_VERSION = "@versionStringPlaceholder@";
27+
public static final String VERSION = "@versionStringPlaceholder@";
2828

2929

3030
/**
3131
* A constant that defines the instrumentation_source metric tag value
3232
*/
33-
public static final String INSTRUMENTATION_SOURCE_TAG_VALUE = "grpc-spring";
33+
public static final String LIBRARY_NAME = "grpc-spring";
3434

3535

3636
private Constants() {}

grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/metrics/MetricsServerStreamTracers.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public final class MetricsServerStreamTracers {
4646

4747
private static final Supplier<Stopwatch> STOPWATCH_SUPPLIER = Stopwatch::createUnstarted;
4848
private final Supplier<Stopwatch> stopwatchSupplier;
49+
private static final String INSTRUMENTATION_SOURCE_TAG_KEY = "instrumentation_source";
50+
private static final String INSTRUMENTATION_VERSION_TAG_KEY = "instrumentation_version";
4951

5052
public MetricsServerStreamTracers() {
5153
this(STOPWATCH_SUPPLIER);
@@ -102,8 +104,8 @@ private static final class ServerTracer extends ServerStreamTracer {
102104
public void serverCallStarted(ServerCallInfo<?, ?> callInfo) {
103105
this.metricsServerMeters.getServerCallCounter()
104106
.withTags(Tags.of("grpc.method", this.fullMethodName,
105-
"instrumentation_source", Constants.INSTRUMENTATION_SOURCE_TAG_VALUE,
106-
"instrumentation_version", Constants.PROJECT_VERSION))
107+
INSTRUMENTATION_SOURCE_TAG_KEY, Constants.LIBRARY_NAME,
108+
INSTRUMENTATION_VERSION_TAG_KEY, Constants.VERSION))
107109
.increment();
108110
}
109111

@@ -127,8 +129,8 @@ public void streamClosed(Status status) {
127129
Tags serverMetricTags =
128130
Tags.of("grpc.method", this.fullMethodName,
129131
"grpc.status", status.getCode().toString(),
130-
"instrumentation_source", Constants.INSTRUMENTATION_SOURCE_TAG_VALUE,
131-
"instrumentation_version", Constants.PROJECT_VERSION);
132+
INSTRUMENTATION_SOURCE_TAG_KEY, Constants.LIBRARY_NAME,
133+
INSTRUMENTATION_VERSION_TAG_KEY, Constants.VERSION);
132134
this.metricsServerMeters.getServerCallDuration()
133135
.withTags(serverMetricTags)
134136
.record(callLatencyNanos, TimeUnit.NANOSECONDS);

grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/metrics/MetricsServerStreamTracersTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class MetricsServerStreamTracersTest {
5656
private static final String GRPC_METHOD_TAG_KEY = "grpc.method";
5757
private static final String GRPC_STATUS_TAG_KEY = "grpc.status";
5858
private static final String INSTRUMENTATION_SOURCE_TAG_KEY = "instrumentation_source";
59-
private static final String INSTRUMENTATION_SOURCE_TAG_VALUE = Constants.INSTRUMENTATION_SOURCE_TAG_VALUE;
59+
private static final String INSTRUMENTATION_SOURCE_TAG_VALUE = Constants.LIBRARY_NAME;
6060
private static final String INSTRUMENTATION_VERSION_TAG_KEY = "instrumentation_version";
61-
private static final String INSTRUMENTATION_VERSION_TAG_VALUE = Constants.PROJECT_VERSION;
61+
private static final String INSTRUMENTATION_VERSION_TAG_VALUE = Constants.VERSION;
6262

6363

6464
private static class StringInputStream extends InputStream {

0 commit comments

Comments
 (0)