Skip to content

Commit 49e7e9f

Browse files
committed
feat(gax): correlate M3 client duration metrics with T3 span exemplars
1 parent 48c4bd5 commit 49e7e9f

1 file changed

Lines changed: 37 additions & 7 deletions

File tree

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.List;
3636
import java.util.Map;
3737
import org.jspecify.annotations.NullMarked;
38+
import org.jspecify.annotations.Nullable;
3839

3940
/**
4041
* A composite implementation of {@link ApiTracer} that delegates all tracing events to a list of
@@ -57,7 +58,10 @@ public Scope inScope() {
5758

5859
try {
5960
for (ApiTracer child : children) {
60-
childScopes.add(child.inScope());
61+
Scope scope = child.inScope();
62+
if (scope != null) {
63+
childScopes.add(scope);
64+
}
6165
}
6266
} catch (RuntimeException e) {
6367
for (int i = childScopes.size() - 1; i >= 0; i--) {
@@ -91,22 +95,48 @@ public Scope inScope() {
9195

9296
@Override
9397
public void operationSucceeded() {
94-
for (int i = children.size() - 1; i >= 0; i--) {
95-
children.get(i).operationSucceeded();
98+
@Nullable Scope scope = null;
99+
try {
100+
scope = inScope();
101+
} catch (RuntimeException e) {
102+
// Ignore to prevent disrupting the lifecycle notification
103+
}
104+
try (Scope s = scope) {
105+
for (int i = children.size() - 1; i >= 0; i--) {
106+
children.get(i).operationSucceeded();
107+
}
96108
}
97109
}
98110

99111
@Override
100112
public void operationCancelled() {
101-
for (int i = children.size() - 1; i >= 0; i--) {
102-
children.get(i).operationCancelled();
113+
@Nullable Scope scope = null;
114+
try {
115+
scope = inScope();
116+
} catch (RuntimeException e) {
117+
// Ignore to prevent disrupting the lifecycle notification
118+
}
119+
try (Scope s = scope) {
120+
for (int i = children.size() - 1; i >= 0; i--) {
121+
children.get(i).operationCancelled();
122+
}
103123
}
104124
}
105125

106126
@Override
107127
public void operationFailed(Throwable error) {
108-
for (int i = children.size() - 1; i >= 0; i--) {
109-
children.get(i).operationFailed(error);
128+
@Nullable Scope scope = null;
129+
try {
130+
scope = inScope();
131+
} catch (RuntimeException e) {
132+
if (error != null) {
133+
error.addSuppressed(e);
134+
}
135+
}
136+
try (Scope s = scope) {
137+
for (int i = children.size() - 1; i >= 0; i--) {
138+
children.get(i).operationFailed(error);
139+
}
110140
}
111141
}
112142

0 commit comments

Comments
 (0)