Skip to content

Commit b48b0e9

Browse files
committed
fix: mark spans volatile and append /attempt to attempt span name
1 parent 8980aa3 commit b48b0e9

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTelemetryTracingTracer.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class OpenTelemetryTracingTracer implements ApiTracer {
5353
private final String attemptSpanName;
5454
private final String operationSpanName;
5555
private final ApiTracerContext apiTracerContext;
56-
private @Nullable Span operationSpan;
57-
private @Nullable Span attemptSpan;
56+
private volatile @Nullable Span operationSpan;
57+
private volatile @Nullable Span attemptSpan;
5858

5959
@Override
6060
public void injectTraceContext(java.util.Map<String, String> carrier) {
@@ -134,21 +134,23 @@ private static String resolveOperationSpanName(String attemptSpanName) {
134134
}
135135

136136
private static String resolveAttemptSpanName(ApiTracerContext apiTracerContext) {
137+
String baseName;
137138
if (apiTracerContext.transport() == ApiTracerContext.Transport.GRPC
138139
&& !Strings.isNullOrEmpty(apiTracerContext.fullMethodName())) {
139140
// gRPC Uses the full method name as span name.
140-
return apiTracerContext.fullMethodName();
141+
baseName = apiTracerContext.fullMethodName();
141142
} else if (apiTracerContext.httpMethod() == null
142143
|| apiTracerContext.httpPathTemplate() == null) {
143144
// HTTP method name without necessary components defaults to the full method name
144-
return apiTracerContext.fullMethodName() != null
145-
? apiTracerContext.fullMethodName()
146-
: "attempt";
145+
baseName =
146+
apiTracerContext.fullMethodName() != null ? apiTracerContext.fullMethodName() : "attempt";
147147
} else {
148148
// We construct the span name with HTTP method and path template.
149-
return String.format(
150-
"%s %s", apiTracerContext.httpMethod(), apiTracerContext.httpPathTemplate());
149+
baseName =
150+
String.format(
151+
"%s %s", apiTracerContext.httpMethod(), apiTracerContext.httpPathTemplate());
151152
}
153+
return "attempt".equals(baseName) ? "attempt" : baseName + "/attempt";
152154
}
153155

154156
private void buildAttributes() {

0 commit comments

Comments
 (0)