|
45 | 45 | import com.google.showcase.v1beta1.EchoClient; |
46 | 46 | import com.google.showcase.v1beta1.EchoRequest; |
47 | 47 | import com.google.showcase.v1beta1.EchoSettings; |
| 48 | +import com.google.showcase.v1beta1.GetUserRequest; |
| 49 | +import com.google.showcase.v1beta1.IdentityClient; |
48 | 50 | import com.google.showcase.v1beta1.it.util.TestClientInitializer; |
49 | 51 | import com.google.showcase.v1beta1.stub.EchoStub; |
50 | 52 | import com.google.showcase.v1beta1.stub.EchoStubSettings; |
@@ -92,20 +94,24 @@ void tearDown() { |
92 | 94 | } |
93 | 95 |
|
94 | 96 | @Test |
95 | | - void testTracing_successfulEcho_grpc() throws Exception { |
| 97 | + void testTracing_successfulIdentityGetUser_grpc() throws Exception { |
96 | 98 | SpanTracerFactory tracingFactory = new SpanTracerFactory(openTelemetrySdk); |
97 | 99 |
|
98 | | - try (EchoClient client = |
99 | | - TestClientInitializer.createGrpcEchoClientOpentelemetry(tracingFactory)) { |
| 100 | + try (IdentityClient client = |
| 101 | + TestClientInitializer.createGrpcIdentityClientOpentelemetry(tracingFactory)) { |
100 | 102 |
|
101 | | - client.echo(EchoRequest.newBuilder().setContent("tracing-test").build()); |
| 103 | + try { |
| 104 | + client.getUser(GetUserRequest.newBuilder().setName("users/test-user").build()); |
| 105 | + } catch (Exception e) { |
| 106 | + // Ignored, the showcase server may not have this user, but trace is still generated. |
| 107 | + } |
102 | 108 |
|
103 | 109 | List<SpanData> spans = spanExporter.getFinishedSpanItems(); |
104 | 110 | assertThat(spans).isNotEmpty(); |
105 | 111 |
|
106 | 112 | SpanData attemptSpan = |
107 | 113 | spans.stream() |
108 | | - .filter(span -> span.getName().equals("google.showcase.v1beta1.Echo/Echo")) |
| 114 | + .filter(span -> span.getName().equals("google.showcase.v1beta1.Identity/GetUser")) |
109 | 115 | .findFirst() |
110 | 116 | .orElseThrow(() -> new AssertionError("Incorrect span name")); |
111 | 117 | assertThat(attemptSpan.getKind()).isEqualTo(SpanKind.CLIENT); |
@@ -143,35 +149,46 @@ void testTracing_successfulEcho_grpc() throws Exception { |
143 | 149 | attemptSpan |
144 | 150 | .getAttributes() |
145 | 151 | .get(AttributeKey.stringKey(ObservabilityAttributes.GRPC_RPC_METHOD_ATTRIBUTE))) |
146 | | - .isEqualTo("google.showcase.v1beta1.Echo/Echo"); |
| 152 | + .isEqualTo("google.showcase.v1beta1.Identity/GetUser"); |
147 | 153 | // {x-version-update-start:gapic-showcase:current} |
148 | 154 | assertThat( |
149 | 155 | attemptSpan |
150 | 156 | .getAttributes() |
151 | 157 | .get(AttributeKey.stringKey(ObservabilityAttributes.VERSION_ATTRIBUTE))) |
152 | 158 | .isEqualTo("0.0.0-SNAPSHOT"); |
153 | 159 | // {x-version-update-end} |
| 160 | + assertThat( |
| 161 | + attemptSpan |
| 162 | + .getAttributes() |
| 163 | + .get( |
| 164 | + AttributeKey.stringKey( |
| 165 | + ObservabilityAttributes.DESTINATION_RESOURCE_ID_ATTRIBUTE))) |
| 166 | + .isEqualTo("users/test-user"); |
154 | 167 | } |
155 | 168 | } |
156 | 169 |
|
157 | 170 | @Test |
158 | | - void testTracing_successfulEcho_httpjson() throws Exception { |
| 171 | + void testTracing_successfulIdentityGetUser_httpjson() throws Exception { |
159 | 172 | SpanTracerFactory tracingFactory = new SpanTracerFactory(openTelemetrySdk); |
160 | 173 |
|
161 | | - try (EchoClient client = |
162 | | - TestClientInitializer.createHttpJsonEchoClientOpentelemetry(tracingFactory)) { |
| 174 | + try (IdentityClient client = |
| 175 | + TestClientInitializer.createHttpJsonIdentityClientOpentelemetry(tracingFactory)) { |
163 | 176 |
|
164 | | - client.echo(EchoRequest.newBuilder().setContent("tracing-test").build()); |
| 177 | + try { |
| 178 | + client.getUser(GetUserRequest.newBuilder().setName("users/test-user").build()); |
| 179 | + } catch (Exception e) { |
| 180 | + // Ignored, the showcase server may not have this user, but trace is still generated. |
| 181 | + } |
165 | 182 |
|
166 | 183 | List<SpanData> spans = spanExporter.getFinishedSpanItems(); |
167 | 184 | assertThat(spans).isNotEmpty(); |
168 | 185 |
|
169 | 186 | SpanData attemptSpan = |
170 | 187 | spans.stream() |
171 | | - .filter(span -> span.getName().equals("POST v1beta1/echo:echo")) |
| 188 | + .filter(span -> span.getName().equals("GET v1beta1/{name=users/*}")) |
172 | 189 | .findFirst() |
173 | 190 | .orElseThrow( |
174 | | - () -> new AssertionError("Attempt span 'POST v1beta1/echo:echo' not found")); |
| 191 | + () -> new AssertionError("Attempt span 'GET v1beta1/{name=users/*}' not found")); |
175 | 192 | assertThat(attemptSpan.getKind()).isEqualTo(SpanKind.CLIENT); |
176 | 193 | assertThat( |
177 | 194 | attemptSpan |
@@ -202,12 +219,19 @@ void testTracing_successfulEcho_httpjson() throws Exception { |
202 | 219 | attemptSpan |
203 | 220 | .getAttributes() |
204 | 221 | .get(AttributeKey.stringKey(ObservabilityAttributes.HTTP_METHOD_ATTRIBUTE))) |
205 | | - .isEqualTo("POST"); |
| 222 | + .isEqualTo("GET"); |
206 | 223 | assertThat( |
207 | 224 | attemptSpan |
208 | 225 | .getAttributes() |
209 | 226 | .get(AttributeKey.stringKey(ObservabilityAttributes.HTTP_URL_TEMPLATE_ATTRIBUTE))) |
210 | | - .isEqualTo("v1beta1/echo:echo"); |
| 227 | + .isEqualTo("v1beta1/{name=users/*}"); |
| 228 | + assertThat( |
| 229 | + attemptSpan |
| 230 | + .getAttributes() |
| 231 | + .get( |
| 232 | + AttributeKey.stringKey( |
| 233 | + ObservabilityAttributes.DESTINATION_RESOURCE_ID_ATTRIBUTE))) |
| 234 | + .isEqualTo("users/test-user"); |
211 | 235 | } |
212 | 236 | } |
213 | 237 |
|
|
0 commit comments