Skip to content

chore: upgrade java8 to java21 for analytics folder #10148

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nitesh-55
Copy link

@nitesh-55 nitesh-55 commented Aug 15, 2025

Description

Checklist

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Aug 15, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @nitesh-55, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new App Engine sample for Google Analytics, specifically configured to run on Java 21. It provides a complete setup for tracking events using Google Analytics within an App Engine application, including necessary configuration files and a servlet for event tracking.

Highlights

  • New App Engine Java 21 Sample: Introduces a new Google Analytics sample application under appengine-java21/analytics, demonstrating App Engine integration with Java 21.
  • Google Analytics Event Tracking: The sample includes AnalyticsServlet.java which sends event data to Google Analytics using the Measurement Protocol.
  • Maven Project Setup: A pom.xml is provided, configuring the project for Java 21 compilation, App Engine SDK 2.0.23, and relevant dependencies like httpclient and jstl.
  • App Engine Deployment Configuration: appengine-web.xml is configured to use the java21 runtime and defines an environment variable for the Google Analytics tracking ID.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request upgrades the analytics sample to Java 21. The changes are a good start, but there are a few critical and high-severity issues that need to be addressed. The pom.xml is still configured for Java 1.8, which needs to be updated to 21. Additionally, there are some security concerns, such as using HTTP instead of HTTPS for API calls. I've left specific comments with suggestions for improvement.

Comment on lines +35 to +36
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The maven.compiler.target and maven.compiler.source are set to 1.8. Since this is an upgrade to Java 21, these should be updated to 21.

    <maven.compiler.target>21</maven.compiler.target>
    <maven.compiler.source>21</maven.compiler.source>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually correct because this sample is using

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

String trackingId = System.getenv("GA_TRACKING_ID");
URIBuilder builder = new URIBuilder();
builder
.setScheme("http")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For security best practices, you should use https instead of http when communicating with the Google Analytics API.

Suggested change
.setScheme("http")
.setScheme("https")

.addParameter("tid", trackingId) // Tracking ID / Property ID.
// Anonymous Client Identifier. Ideally, this should be a UUID that
// is associated with particular user, device, or browser instance.
.addParameter("cid", "555")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment on the preceding lines suggests that the client ID (cid) should ideally be a UUID. Hardcoding it to "555" is not ideal for a sample. Consider generating a random UUID to better demonstrate the intended usage.

Suggested change
.addParameter("cid", "555")
.addParameter("cid", java.util.UUID.randomUUID().toString())

Comment on lines 17 to 24
<runtime>java21</runtime>
<app-engine-apis>true</app-engine-apis>
<system-properties>
<property name="appengine.use.EE8" value="true"/>
</system-properties>
<env-variables>
<env-var name="GA_TRACKING_ID" value="YOUR-GA-TRACKING-ID" />
</env-variables>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The XML indentation in this file is inconsistent, which makes it harder to read. Please format it with consistent indentation (e.g., 2 spaces per level).

  <runtime>java21</runtime>
  <app-engine-apis>true</app-engine-apis>
  <system-properties>
    <property name="appengine.use.EE8" value="true"/>
  </system-properties>
  <env-variables>
    <env-var name="GA_TRACKING_ID" value="YOUR-GA-TRACKING-ID" />
  </env-variables>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitesh-55 I know this was as is existing in the file, can you address this one so it's consistent?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@@ -0,0 +1,136 @@
<!--
Copyright 2017 Google LLC.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitesh-55 no . after LLC.

For others reading this, this is migrating an existing sample over to java 21 and so the year 2017 is correct.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


package com.example.appengine.analytics;

// [START analytics_track]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitesh-55 please fix the region tag here. Since this is already a migration, you don't have to keep the invalid region tag. you can create updated as this file isn't in use. Talk to Fran about how to construct a valid more helpful one here please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the region tag

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing the update. It should start with gae_

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

-->
<!-- [END_EXCLUDE] -->
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<runtime>java21</runtime>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file looks to have the correct syntax that Ludo provided as guidance for the migration.

<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<groupId>com.example.appengine</groupId>
<artifactId>appengine-analytics-j21</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is one of the areas that ludo gave guidance of needing to change and looks correct.

@@ -16,7 +16,7 @@

package com.example.appengine.analytics;

// [START analytics_track]
// [START analytics_track_j21]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you did, you updated the existing java8 file. Don't do this, update the java21 version above and remove this change from your commit. also a valid region tag would start with gae in this case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry,my bad. Updated region tag name

@iennae
Copy link
Contributor

iennae commented Aug 21, 2025

as discussed, let's add a subdirectory of ee8 under the runtime version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants