-
Notifications
You must be signed in to change notification settings - Fork 87
feat: create(Blob) instrumentation #2792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2c1ea26
wip create(Blob) instrumentation
sydney-munro 3856854
fix checkstyle
sydney-munro 8fe835b
linter
sydney-munro d14b892
fix child spans to have rpc.system information and proper formatting
sydney-munro 3543adf
fix up tests
sydney-munro b4d2591
pr comments
sydney-munro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
google-cloud-storage/src/test/java/com/google/cloud/storage/ITGrpcOpenTelemetryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.storage; | ||
|
|
||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
|
||
| import com.google.cloud.NoCredentials; | ||
| import com.google.cloud.storage.it.runner.StorageITRunner; | ||
| import com.google.cloud.storage.it.runner.annotations.Backend; | ||
| import com.google.cloud.storage.it.runner.annotations.Inject; | ||
| import com.google.cloud.storage.it.runner.annotations.SingleBackend; | ||
| import com.google.cloud.storage.it.runner.registry.Generator; | ||
| import com.google.cloud.storage.it.runner.registry.TestBench; | ||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.sdk.OpenTelemetrySdk; | ||
| import io.opentelemetry.sdk.trace.SdkTracerProvider; | ||
| import io.opentelemetry.sdk.trace.data.SpanData; | ||
| import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; | ||
| import io.opentelemetry.sdk.trace.export.SpanExporter; | ||
| import java.util.List; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @RunWith(StorageITRunner.class) | ||
| @SingleBackend(Backend.TEST_BENCH) | ||
| public class ITGrpcOpenTelemetryTest { | ||
| @Inject public TestBench testBench; | ||
| private StorageOptions options; | ||
| private SpanExporter exporter; | ||
| private Storage storage; | ||
| @Inject public Generator generator; | ||
| @Inject public BucketInfo testBucket; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| exporter = new TestExporter(); | ||
| OpenTelemetrySdk openTelemetrySdk = | ||
| OpenTelemetrySdk.builder() | ||
| .setTracerProvider( | ||
| SdkTracerProvider.builder() | ||
| .addSpanProcessor(SimpleSpanProcessor.create(exporter)) | ||
| .build()) | ||
| .build(); | ||
| options = | ||
| StorageOptions.grpc() | ||
| .setHost(testBench.getGRPCBaseUri()) | ||
| .setProjectId("projectId") | ||
| .setCredentials(NoCredentials.getInstance()) | ||
| .setOpenTelemetrySdk(openTelemetrySdk) | ||
| .build(); | ||
| storage = options.getService(); | ||
| } | ||
|
|
||
| @Test | ||
| public void runCreateBucket() { | ||
| String bucket = "random-bucket"; | ||
| storage.create(BucketInfo.of(bucket)); | ||
| TestExporter testExported = (TestExporter) exporter; | ||
| SpanData spanData = testExported.getExportedSpans().get(0); | ||
| Assert.assertEquals("Storage", getAttributeValue(spanData, "gcp.client.service")); | ||
| Assert.assertEquals("googleapis/java-storage", getAttributeValue(spanData, "gcp.client.repo")); | ||
| Assert.assertEquals( | ||
| "com.google.cloud.google-cloud-storage", | ||
| getAttributeValue(spanData, "gcp.client.artifact")); | ||
| Assert.assertEquals("grpc", getAttributeValue(spanData, "rpc.system")); | ||
| } | ||
|
|
||
| @Test | ||
| public void runCreateBlob() { | ||
| byte[] content = "Hello, World!".getBytes(UTF_8); | ||
| BlobId toCreate = BlobId.of(testBucket.getName(), generator.randomObjectName()); | ||
| storage.create(BlobInfo.newBuilder(toCreate).build(), content); | ||
| TestExporter testExported = (TestExporter) exporter; | ||
| List<SpanData> spanData = testExported.getExportedSpans(); | ||
| for (SpanData span : spanData) { | ||
| Assert.assertEquals("Storage", getAttributeValue(span, "gcp.client.service")); | ||
| Assert.assertEquals("googleapis/java-storage", getAttributeValue(span, "gcp.client.repo")); | ||
| Assert.assertEquals( | ||
| "com.google.cloud.google-cloud-storage", getAttributeValue(span, "gcp.client.artifact")); | ||
| Assert.assertEquals("grpc", getAttributeValue(span, "rpc.system")); | ||
| } | ||
| Assert.assertTrue(spanData.stream().anyMatch(x -> x.getName().contains("create"))); | ||
| Assert.assertTrue( | ||
| spanData.stream().anyMatch(x -> x.getName().contains("internalDirectUpload"))); | ||
| Assert.assertEquals(spanData.get(1).getSpanContext(), spanData.get(0).getParentSpanContext()); | ||
| } | ||
|
|
||
| private String getAttributeValue(SpanData spanData, String key) { | ||
| return spanData.getAttributes().get(AttributeKey.stringKey(key)).toString(); | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
google-cloud-storage/src/test/java/com/google/cloud/storage/otel/TestExporter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.storage.otel; | ||
|
|
||
| import io.opentelemetry.sdk.common.CompletableResultCode; | ||
| import io.opentelemetry.sdk.trace.data.SpanData; | ||
| import io.opentelemetry.sdk.trace.export.SpanExporter; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| class TestExporter implements SpanExporter { | ||
|
|
||
| public final List<SpanData> exportedSpans = Collections.synchronizedList(new ArrayList<>()); | ||
|
|
||
| @Override | ||
| public CompletableResultCode export(Collection<SpanData> spans) { | ||
| exportedSpans.addAll(spans); | ||
| return CompletableResultCode.ofSuccess(); | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableResultCode flush() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableResultCode shutdown() { | ||
| return null; | ||
| } | ||
|
|
||
| public List<SpanData> getExportedSpans() { | ||
| return exportedSpans; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.