Skip to content

Commit 4dbbb47

Browse files
authored
Merge branch 'main' into mut-cred-example
2 parents f0cd9c0 + 40ac6e4 commit 4dbbb47

File tree

28 files changed

+863
-37
lines changed

28 files changed

+863
-37
lines changed

.github/workflows/sdk-platform-java-dependency_compatibility_test.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ jobs:
6969

7070
# Set up local showcase server to run the showcase ITs
7171
- name: Parse showcase version
72-
working-directory: sdk-plaform-java/java-showcase/gapic-showcase
72+
working-directory: sdk-platform-java/java-showcase/gapic-showcase
7373
run: echo "SHOWCASE_VERSION=$(mvn help:evaluate -Dexpression=gapic-showcase.version -q -DforceStdout)" >> "$GITHUB_ENV"
74-
working-directory: sdk-platform-java
7574
- name: Install showcase server
7675
run: |
7776
sudo mkdir -p /usr/src/showcase

.github/workflows/sdk-platform-java-downstream_protobuf_compatibility_check_nightly.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ jobs:
3030
- 'sdk-platform-java/**'
3131
downstream-protobuf-test:
3232
needs: filter
33-
if: ${{ needs.filter.outputs.library == 'true' }}
3433
# This job runs if any of the three conditions match:
3534
# 1. PR is raised from Release-Please (PR comes from branch: release-please--branches-main)
3635
# 2. Job is invoked by the nightly job (scheduled event)
3736
# 3. Job is manually invoked via Github UI (workflow_dispatch event)
38-
if: github.head_ref == 'release-please--branches--main' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
37+
if: needs.filter.outputs.library == 'true' && (github.head_ref == 'release-please--branches--main' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
3938
runs-on: ubuntu-22.04
4039
strategy:
4140
fail-fast: false

.github/workflows/sdk-platform-java-shared_dependencies.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ jobs:
2525
- 'sdk-platform-java/**'
2626
upper-bound-check:
2727
needs: filter
28-
if: ${{ needs.filter.outputs.library == 'true' }}
28+
if: needs.filter.outputs.library == 'true' && github.repository_owner == 'googleapis'
2929
name: Shared Dependencies BOM upper-bound check
3030
runs-on: ubuntu-latest
31-
if: github.repository_owner == 'googleapis'
3231
steps:
3332
- uses: actions/checkout@v4
3433
- uses: actions/setup-java@v4

.github/workflows/sdk-platform-java-sonar.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ jobs:
2222
- 'sdk-platform-java/**'
2323
build:
2424
needs: filter
25-
if: ${{ needs.filter.outputs.library == 'true' }}
25+
if: needs.filter.outputs.library == 'true' && (github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request')
2626
name: Build
27-
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request'
2827
runs-on: ubuntu-22.04
2928
steps:
3029
- uses: actions/checkout@v3

.github/workflows/sdk-platform-java-verify_library_generation.yaml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ jobs:
5555
head_repo_name: ${{ github.event.pull_request.head.repo.full_name }}
5656
base_repo: ${{ github.repository }}
5757
library-generation-unit-tests:
58-
needs: filter
59-
if: ${{ needs.filter.outputs.library == 'true' }}
58+
needs: [filter, should-run-library-generation-tests]
59+
if: needs.filter.outputs.library == 'true' && needs.should-run-library-generation-tests.outputs.should_run == 'true'
6060
runs-on: ubuntu-22.04
61-
needs: should-run-library-generation-tests
62-
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
6361
steps:
6462
- uses: actions/checkout@v4
6563
- uses: actions/setup-python@v5
@@ -85,11 +83,9 @@ jobs:
8583
set -x
8684
python -m unittest discover -s hermetic_build -p "*unit_tests.py"
8785
library-generation-lint-shell:
88-
needs: filter
89-
if: ${{ needs.filter.outputs.library == 'true' }}
86+
needs: [filter, should-run-library-generation-tests]
87+
if: needs.filter.outputs.library == 'true' && needs.should-run-library-generation-tests.outputs.should_run == 'true'
9088
runs-on: ubuntu-22.04
91-
needs: should-run-library-generation-tests
92-
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
9389
steps:
9490
- uses: actions/checkout@v4
9591
- name: Run ShellCheck
@@ -101,11 +97,9 @@ jobs:
10197
ignore_paths:
10298
.kokoro
10399
library-generation-lint-python:
104-
needs: filter
105-
if: ${{ needs.filter.outputs.library == 'true' }}
100+
needs: [filter, should-run-library-generation-tests]
101+
if: needs.filter.outputs.library == 'true' && needs.should-run-library-generation-tests.outputs.should_run == 'true'
106102
runs-on: ubuntu-22.04
107-
needs: should-run-library-generation-tests
108-
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
109103
steps:
110104
- uses: actions/checkout@v4
111105
- uses: actions/setup-python@v5

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/telemetry/HttpTracingRequestInitializer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import io.opentelemetry.api.common.AttributeKey;
2424
import io.opentelemetry.api.trace.Span;
2525
import io.opentelemetry.api.trace.Tracer;
26+
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
27+
import io.opentelemetry.context.Context;
2628
import java.io.IOException;
2729

2830
/**
@@ -76,6 +78,10 @@ public void initialize(HttpRequest request) throws IOException {
7678
// No active span to exists, skip instrumentation
7779
return;
7880
}
81+
// propagate the W3C Trace Context (traceID and spanID) from the active span in headers
82+
W3CTraceContextPropagator.getInstance()
83+
.inject(Context.current(), request.getHeaders(), HttpHeaders::set);
84+
7985
addInitialHttpAttributesToSpan(span, request);
8086

8187
HttpResponseInterceptor originalInterceptor = request.getResponseInterceptor();

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/telemetry/HttpTracingRequestInitializerTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,23 @@ public void testNoSpanIsCreatedIfNoActiveSpan() throws IOException {
145145
verify(delegateInitializer, times(1)).initialize(any(HttpRequest.class));
146146
}
147147

148+
@Test
149+
public void testTraceContextIsPropagatedInHeaders() throws IOException {
150+
HttpTransport transport = createTransport();
151+
HttpRequest request = buildGetRequest(transport, initializer, BASE_URL);
152+
153+
HttpResponse response = request.execute();
154+
response.disconnect();
155+
156+
assertEquals(
157+
String.format(
158+
"00-%s-%s-%s",
159+
parentSpan.getSpanContext().getTraceId(),
160+
parentSpan.getSpanContext().getSpanId(),
161+
parentSpan.getSpanContext().getTraceFlags().asHex()),
162+
request.getHeaders().get("traceparent"));
163+
}
164+
148165
@Test
149166
public void testDelegateInitializerIsCalled() throws IOException {
150167
HttpRequestInitializer delegateInitializer = mock(HttpRequestInitializer.class);

sdk-platform-java/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.google.api.client.json.JsonObjectParser;
4545
import com.google.api.client.json.gson.GsonFactory;
4646
import com.google.api.client.util.GenericData;
47+
import com.google.api.gax.tracing.ApiTracer;
4748
import com.google.auth.Credentials;
4849
import com.google.auth.http.HttpCredentialsAdapter;
4950
import com.google.auto.value.AutoValue;
@@ -188,6 +189,11 @@ HttpRequest createHttpRequest() throws IOException {
188189
}
189190
}
190191

192+
ApiTracer tracer = httpJsonCallOptions.getTracer();
193+
if (tracer != null) {
194+
tracer.requestUrlResolved(url.build());
195+
}
196+
191197
HttpRequest httpRequest = buildRequest(requestFactory, url, jsonHttpContent);
192198

193199
for (Map.Entry<String, Object> entry : headers.getHeaders().entrySet()) {

sdk-platform-java/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpRequestRunnableTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.google.api.client.http.EmptyContent;
3333
import com.google.api.client.http.HttpRequest;
3434
import com.google.api.client.testing.http.MockHttpTransport;
35+
import com.google.api.gax.tracing.ApiTracer;
3536
import com.google.common.truth.Truth;
3637
import com.google.longrunning.ListOperationsRequest;
3738
import com.google.protobuf.Empty;
@@ -123,6 +124,32 @@ void testRequestUrl() throws IOException {
123124
Truth.assertThat(httpRequest.getUrl().toString()).isEqualTo(expectedUrl);
124125
}
125126

127+
@Test
128+
void testApiTracerRequestUrlResolved() throws IOException {
129+
ApiTracer tracer = Mockito.mock(ApiTracer.class);
130+
ApiMethodDescriptor<Field, Empty> methodDescriptor =
131+
ApiMethodDescriptor.<Field, Empty>newBuilder()
132+
.setFullMethodName("house.cat.get")
133+
.setHttpMethod(null)
134+
.setRequestFormatter(requestFormatter)
135+
.setResponseParser(responseParser)
136+
.build();
137+
138+
HttpRequestRunnable<Field, Empty> httpRequestRunnable =
139+
new HttpRequestRunnable<>(
140+
requestMessage,
141+
methodDescriptor,
142+
ENDPOINT,
143+
HttpJsonCallOptions.newBuilder().setTracer(tracer).build(),
144+
new MockHttpTransport(),
145+
HttpJsonMetadata.newBuilder().build(),
146+
(result) -> {});
147+
148+
httpRequestRunnable.createHttpRequest();
149+
String expectedUrl = ENDPOINT + "/name/feline" + "?food=bird&food=mouse&size=small";
150+
Mockito.verify(tracer).requestUrlResolved(expectedUrl);
151+
}
152+
126153
@Test
127154
void testRequestUrlUnnormalized() throws IOException {
128155
ApiMethodDescriptor<Field, Empty> methodDescriptor =

sdk-platform-java/gax-java/gax/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
<configuration>
140140
<argLine>@{argLine} -Djava.util.logging.SimpleFormatter.format="%1$tY %1$tl:%1$tM:%1$tS.%1$tL %2$s %4$s: %5$s%6$s%n"</argLine>
141141
<!-- These tests require an Env Var to be set. Use -PenvVarTest to ONLY run these tests -->
142-
<test>!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet+endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority,!LoggingEnabledTest</test>
142+
<test>!EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet+endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority,!LoggingEnabledTest,!LoggingTracerTest</test>
143143
</configuration>
144144
</plugin>
145145
</plugins>
@@ -154,7 +154,7 @@
154154
<groupId>org.apache.maven.plugins</groupId>
155155
<artifactId>maven-surefire-plugin</artifactId>
156156
<configuration>
157-
<test>EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet+endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority,LoggingEnabledTest</test>
157+
<test>EndpointContextTest#endpointContextBuild_universeDomainEnvVarSet+endpointContextBuild_multipleUniverseDomainConfigurations_clientSettingsHasPriority,LoggingEnabledTest,LoggingTracerTest</test>
158158
</configuration>
159159
</plugin>
160160
</plugins>

0 commit comments

Comments
 (0)