Skip to content

Commit 451b38c

Browse files
committed
Add tests, and fix a case
The existing tests really liked to use inconsistent CallOptions in the same test.
1 parent 248b6be commit 451b38c

File tree

2 files changed

+148
-31
lines changed

2 files changed

+148
-31
lines changed

opentelemetry/src/main/java/io/grpc/opentelemetry/OpenTelemetryMetricsModule.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ static final class CallAttemptsTracerFactory extends ClientStreamTracer.Factory
326326
CallAttemptsTracerFactory(
327327
OpenTelemetryMetricsModule module,
328328
String target,
329+
CallOptions callOptions,
329330
String fullMethodName,
330331
List<OpenTelemetryPlugin.ClientCallPlugin> callPlugins) {
331332
this.module = checkNotNull(module, "module");
@@ -335,9 +336,14 @@ static final class CallAttemptsTracerFactory extends ClientStreamTracer.Factory
335336
this.attemptDelayStopwatch = module.stopwatchSupplier.get();
336337
this.callStopWatch = module.stopwatchSupplier.get().start();
337338

338-
io.opentelemetry.api.common.Attributes attribute = io.opentelemetry.api.common.Attributes.of(
339-
METHOD_KEY, fullMethodName,
340-
TARGET_KEY, target);
339+
AttributesBuilder builder = io.opentelemetry.api.common.Attributes.builder()
340+
.put(METHOD_KEY, fullMethodName)
341+
.put(TARGET_KEY, target);
342+
if (module.customLabelEnabled) {
343+
builder.put(
344+
CUSTOM_LABEL_KEY, callOptions.getOption(Grpc.CALL_OPTION_CUSTOM_LABEL));
345+
}
346+
io.opentelemetry.api.common.Attributes attribute = builder.build();
341347

342348
// Record here in case mewClientStreamTracer() would never be called.
343349
if (module.resource.clientAttemptCountCounter() != null) {
@@ -361,9 +367,14 @@ public ClientStreamTracer newClientStreamTracer(StreamInfo info, Metadata metada
361367
// CallAttemptsTracerFactory constructor. attemptsPerCall will be non-zero after the first
362368
// attempt, as first attempt cannot be a transparent retry.
363369
if (attemptsPerCall.get() > 0) {
364-
io.opentelemetry.api.common.Attributes attribute =
365-
io.opentelemetry.api.common.Attributes.of(METHOD_KEY, fullMethodName,
366-
TARGET_KEY, target);
370+
AttributesBuilder builder = io.opentelemetry.api.common.Attributes.builder()
371+
.put(METHOD_KEY, fullMethodName)
372+
.put(TARGET_KEY, target);
373+
if (module.customLabelEnabled) {
374+
builder.put(
375+
CUSTOM_LABEL_KEY, info.getCallOptions().getOption(Grpc.CALL_OPTION_CUSTOM_LABEL));
376+
}
377+
io.opentelemetry.api.common.Attributes attribute = builder.build();
367378
if (module.resource.clientAttemptCountCounter() != null) {
368379
module.resource.clientAttemptCountCounter().add(1, attribute);
369380
}
@@ -675,7 +686,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
675686
// which is true for all generated methods. Otherwise, programatically
676687
// created methods result in high cardinality metrics.
677688
final CallAttemptsTracerFactory tracerFactory = new CallAttemptsTracerFactory(
678-
OpenTelemetryMetricsModule.this, target,
689+
OpenTelemetryMetricsModule.this, target, callOptions,
679690
recordMethodName(method.getFullMethodName(), method.isSampledToLocalTracing()),
680691
callPlugins);
681692
ClientCall<ReqT, RespT> call =

0 commit comments

Comments
 (0)