GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — java-docs-samples/spanner/opentelemetry_traces at main · fredatgithub/java-docs-samples

Expand file tree

/

opentelemetry_traces

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

opentelemetry_traces

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
src/main/java/com/example/spanner
src/main/java/com/example/spanner
 
 
Readme.md
Readme.md
 
 
pom.xml
pom.xml
 
 

Readme.md

Outline

Cloud Spanner OpenTelemetry Traces

Setup

This sample requires Java and Maven.

  1. Follow the set-up instructions in the documentation.

  2. Enable APIs for your project.

    a. Click here to visit Cloud Platform Console and enable the Google Cloud Spanner API.

    b. Click here to visit Cloud Platform Console and enable the Cloud Trace API.

  3. Create a Cloud Spanner instance and database via the Cloud Plaform Console's Cloud Spanner section.

  4. Enable application default credentials by running the command gcloud auth application-default login.

Run the Example

  1. Set up database configuration in the OpenTelemetryUsage.java class:

    String projectId = "my-project";
    String instanceId = "my-instance";
    String databaseId = "my-database";
    
  2. Configure trace data export. You can use either the OpenTelemetry [Collector](https://opentelemetry.io/docs/collector/quick-start/ with the OTLP Exporter or the Cloud Trace Exporter. By default, the Cloud Trace Exporter is used.

  • To use OTLP Exporter, Set up the OpenTelemetry Collector and update the OTLP endpoint in OpenTelemetryUsage.java class
    boolean useCloudTraceExporter = true; // Replace to false for OTLP
    String otlpEndpoint = "http://localhost:4317"; // Replace with your OTLP endpoint
    
  1. You can also enable API Tracing and SQL Statement Tracing by setting below options. Refer Traces for more details.

    SpannerOptions options = SpannerOptions.newBuilder()
    .setOpenTelemetry(openTelemetry)
    .setEnableExtendedTracing(true)
    .setEnableApiTracing(true)
    .build();
    
  2. Then run the application from command line, after switching to this directory:

    mvn exec:java -Dexec.mainClass="com.example.spanner.OpenTelemetryUsage"
    

You should start seeing traces in Cloud Trace .

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.