Skip to content

Commit 8980aa3

Browse files
committed
refactor: derive operationSpanName directly from attemptSpanName
1 parent c769a57 commit 8980aa3

1 file changed

Lines changed: 3 additions & 14 deletions

File tree

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public Scope inScope() {
108108
this.tracer = tracer;
109109
this.apiTracerContext = apiTracerContext;
110110
this.attemptSpanName = attemptSpanName;
111-
this.operationSpanName = resolveOperationSpanName(apiTracerContext, attemptSpanName);
111+
this.operationSpanName = resolveOperationSpanName(attemptSpanName);
112112
this.attemptAttributes = new HashMap<>();
113113
buildAttributes();
114114
startOperationSpan();
@@ -122,19 +122,8 @@ private void startOperationSpan() {
122122
this.operationSpan = operationSpanBuilder.startSpan();
123123
}
124124

125-
private static String resolveOperationSpanName(
126-
ApiTracerContext apiTracerContext, String attemptSpanName) {
127-
if (apiTracerContext.transport() == ApiTracerContext.Transport.GRPC
128-
&& !Strings.isNullOrEmpty(apiTracerContext.fullMethodName())) {
129-
return apiTracerContext.fullMethodName();
130-
} else if (apiTracerContext.transport() == ApiTracerContext.Transport.HTTP
131-
&& !Strings.isNullOrEmpty(apiTracerContext.httpMethod())
132-
&& !Strings.isNullOrEmpty(apiTracerContext.httpPathTemplate())) {
133-
return String.format(
134-
"%s %s", apiTracerContext.httpMethod(), apiTracerContext.httpPathTemplate());
135-
} else if (!Strings.isNullOrEmpty(apiTracerContext.fullMethodName())) {
136-
return apiTracerContext.fullMethodName();
137-
} else if (!Strings.isNullOrEmpty(attemptSpanName)) {
125+
private static String resolveOperationSpanName(String attemptSpanName) {
126+
if (!Strings.isNullOrEmpty(attemptSpanName)) {
138127
if (attemptSpanName.endsWith("/attempt")) {
139128
String name = attemptSpanName.substring(0, attemptSpanName.length() - "/attempt".length());
140129
return name.isEmpty() ? "operation" : name;

0 commit comments

Comments
 (0)