FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

docs: Create OpenTelemetry Quickstart Sample by sydney-munro · Pull Request #2861 · googleapis/java-storage · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) .xml  (3) All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 10 additions & 0 deletions samples/install-without-bom/pom.xml
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
Expand Up @@ -76,6 +76,16 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-trace</artifactId>
<version>0.31.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>propagators-gcp</artifactId>
<version>0.33.0-alpha</version>
</dependency>
</dependencies>

<!-- compile and run all snippet tests -->
Expand Down
10 changes: 10 additions & 0 deletions samples/snapshot/pom.xml
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
Expand Up @@ -68,6 +68,16 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-trace</artifactId>
<version>0.31.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>propagators-gcp</artifactId>
<version>0.33.0-alpha</version>
</dependency>
Comment thread
BenWhitehead marked this conversation as resolved.
</dependencies>

<!-- compile and run all snippet tests -->
Expand Down
10 changes: 10 additions & 0 deletions samples/snippets/pom.xml
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
Expand Up @@ -79,6 +79,16 @@
<version>1.136.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-trace</artifactId>
<version>0.31.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>propagators-gcp</artifactId>
<version>0.33.0-alpha</version>
</dependency>
<dependency>
<!-- tests jars aren't in the bom, manually include the version here -->
<groupId>com.google.cloud</groupId>
Expand Down
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,60 @@
/*
* Copyright 2024 Google Inc.
*
* 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.example.storage;



import com.google.cloud.opentelemetry.propagators.XCloudTraceContextPropagator;
import com.google.cloud.opentelemetry.trace.TraceExporter;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.sdk.trace.samplers.Sampler;

// [START storage_enable_otel_tracing]
public class QuickstartOpenTelemetrySample {
public static void main(String... args) throws Exception {
SpanExporter spanExporter = TraceExporter.createWithDefaultConfiguration();
TextMapPropagator propagators = TextMapPropagator.composite(
W3CTraceContextPropagator.getInstance(),
new XCloudTraceContextPropagator(/*oneway=*/true));

OpenTelemetrySdk openTelemetry =
OpenTelemetrySdk.builder()
.setPropagators(ContextPropagators.create(propagators))
.setTracerProvider(
SdkTracerProvider.builder()
// Sample Rate is set to alwaysOn
// It is recommended to sample based on a ratio for standard use ie.
// .setSampler(Sampler.traceIdRatioBased(0.2)) // sample only 20% of trace ids
.setSampler(Sampler.alwaysOn())
Comment thread
sydney-munro marked this conversation as resolved.
.addSpanProcessor(BatchSpanProcessor.builder(spanExporter).build())
.build())
.build();
StorageOptions options = StorageOptions.newBuilder().setOpenTelemetry(openTelemetry).build();
Storage storage = options.getService();
System.out.println("Created an instance of storage with OpenTelemetry configured");

}
}
// [END storage_enable_otel_tracing]
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
Expand Up @@ -86,4 +86,12 @@ public void testQuickstartStorageControl() throws Exception {
"Performed getStorageLayout request for %s",
StorageLayoutName.format("_", bucketName)));
}

@Test
public void testQuickstartOpenTelemetry() throws Exception {
QuickstartOpenTelemetrySample.main();
String got = stdOutCaptureRule.getCapturedOutputAsUtf8String();
assertThat(got)
.contains("Created an instance of storage with OpenTelemetry configured");
}
}

Back | FazBrowse Home | New Git URL