Coder Social home page Coder Social logo

java-logging-servlet-initializer's Introduction

Google Cloud Logging Servlet Initializer for Java

Java EE idiomatic servlet container initializer to capture Http request context.

Maven Stability

NOTE: This client is a work-in-progress, and may occasionally make backwards-incompatible changes.

Quickstart

If you are using Maven, add this to your pom.xml file:

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-logging-servlet-initializer</artifactId>
</dependency>

If you are using Gradle without BOM, add this to your dependencies

implementation 'com.google.cloud:google-cloud-logging-servlet-initializer'

If you are using SBT, add this to your dependencies

libraryDependencies += "com.google.cloud" % "google-cloud-logging-servlet-initializer"

Getting Started

Installation and setup

You'll need to obtain the google-cloud-logging-servlet-initializer library. See the Quickstart section to add google-cloud-logging-servlet-initializer as a dependency in your code.

About Cloud Logging Servlet Initializer

Cloud Logging Servlet Initializer saves you an effort to capture the logging context of the servlet request. The captured context includes Http request and tracing information such as trace and span Ids. The initializer is registered using Service Provider Interface with the Java EE Servlet Container and adds a listener for servlet request events to capture the current context of the servlet requests.

Using Cloud Logging Servlet Initializer developers can enrich logs they write to Cloud Logging with Http request and tracing information without adding a single line of code.

Usage

Add the library to your pom.xml in addition to google-cloud-logging or google-cloud-logging-logback. If you use asynchronous execution to process servlet requests and need to propogate the context to child threads (threads that are forked from the request handler's thread) you would need to set the useInheritedContext property in the logging configuration to true. Remember to provide the path to the configuration file as a system property: -Djava.util.logging.config.file=/path/to/logging.properties.

com.google.cloud.logging.ContextHandler.useInheritedContext=true

When the useInheritedContext property is set to true, the context stored for the request handler's thread will be inherited by all child threads that the thread creates.

NOTE: If child threads are not disposed at the end of the request handling, consider avoiding context inheritance. Context clean up removes the context for the request handler's thread ONLY.

By default the context is saved for the request handler's thread only. If you do not use the useInheritedContext property, you can set the context for other threads explicitly using the com.google.cloud.logging.ContextHandler class.

Samples

Samples are in the samples/ directory.

Troubleshooting

To get help, follow the instructions in the shared Troubleshooting document.

Supported Java Versions

Java 8 or above is required for using this client.

Google's Java client libraries, Google Cloud Client Libraries follow the Oracle Java SE support roadmap (see the Oracle Java SE Product Releases section).

Other dependencies

The library uses Jakarta Servlet package version 4.0.4. Older versions of javax.servlet are not supported.

For new development

In general, new feature development occurs with support for the lowest Java LTS version covered by Oracle's Premier Support (which typically lasts 5 years from initial General Availability). If the minimum required JVM for a given library is changed, it is accompanied by a semver major release.

Java 11 and (in September 2021) Java 17 are the best choices for new development.

Keeping production systems current

Google tests its client libraries with all current LTS versions covered by Oracle's Extended Support (which typically lasts 8 years from initial General Availability).

Legacy support

Google's client libraries support legacy versions of Java runtimes with long term stable libraries that don't receive feature updates on a best efforts basis as it may not be possible to backport all patches.

Google provides updates on a best efforts basis to apps that continue to use Java 7, though apps might need to upgrade to current versions of the library that supports their JVM.

Where to find specific information

The latest versions and the supported Java versions are identified on the individual GitHub repository github.com/GoogleAPIs/java-SERVICENAME and on google-cloud-java.

Versioning

This library follows Semantic Versioning.

It is currently in major version zero (0.y.z-alpha), which means that anything may change at any time and the public API should not be considered stable.

Contributing

Contributions to this library are always welcome and highly encouraged.

See CONTRIBUTING for more information how to get started.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Code of Conduct for more information.

License

Apache 2.0 - See LICENSE for more information.

CI Status

Java Version Status
Java 8 Kokoro CI
Java 8 OSX Kokoro CI
Java 8 Windows Kokoro CI
Java 11 Kokoro CI

Java is a registered trademark of Oracle and/or its affiliates.

java-logging-servlet-initializer's People

Contributors

chingor13 avatar cindy-peng avatar gcf-owl-bot[bot] avatar losalex avatar minherz avatar mpeddada1 avatar neenu1995 avatar release-please[bot] avatar renovate-bot avatar suztomo avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-logging-servlet-initializer's Issues

Add support for Spring Boot applications

Is your feature request related to a problem? Please describe.
The auto-initialization mechanism does not work when used with Spring Boot applications.
The testing environment was Java 11 JDK and Spring Boot:

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.7.7</version>
</parent>

The application was composed using https://start.spring.io/

Describe the solution you'd like
Similar to how the package works with Jakarta servlets, Jetty, Tomcat and Undertow web servers, it should work with Spring Boot applications.

Additional context
It looks like the implementation of the hooking to the Java servlet pipeline does not work with Spring Boot applications.

Your .repo-metadata.json file has a problem ๐Ÿค’

You have a problem with your .repo-metadata.json file:

Result of scan ๐Ÿ“ˆ:

  • release_level must be equal to one of the allowed values in .repo-metadata.json

โ˜๏ธ Once you address these problems, you can close this issue.

Need help?

  • Schema definition: lists valid options for each field.
  • API index: for gRPC libraries api_shortname should match the subdomain of an API's hostName.
  • Reach out to go/github-automation if you have any questions.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • build(deps): update dependency org.apache.maven.plugins:maven-deploy-plugin to v3.1.2
  • build(deps): update dependency org.apache.maven.plugins:maven-project-info-reports-plugin to v3.5.0
  • build(deps): update dependency org.codehaus.mojo:build-helper-maven-plugin to v3.6.0
  • test(deps): update dependency com.google.truth:truth to v1.4.2
  • deps: update actions/github-script action to v7
  • deps: update actions/setup-java action to v4
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/approve-readme.yaml
  • actions/github-script v6
.github/workflows/auto-release.yaml
  • actions/github-script v6
.github/workflows/ci.yaml
  • actions/checkout v3
  • actions/setup-java v3
  • actions/checkout v3
  • actions/setup-java v3
  • actions/setup-java v3
  • actions/checkout v3
  • actions/setup-java v3
  • actions/checkout v3
  • actions/setup-java v3
  • actions/checkout v3
  • actions/setup-java v3
  • actions/checkout v3
  • actions/setup-java v3
  • actions/checkout v3
  • actions/setup-java v3
.github/workflows/samples.yaml
  • actions/checkout v3
  • actions/setup-java v3
maven
pom.xml
  • com.google.cloud:google-cloud-shared-config 1.5.6
  • com.google.cloud:google-cloud-shared-dependencies 3.11.0
  • com.google.cloud:google-cloud-logging 3.14.6
  • jakarta.servlet:jakarta.servlet-api 4.0.4
  • junit:junit 4.13.2
  • org.easymock:easymock 5.1.0
  • org.eclipse.jetty:jetty-client 9.4.51.v20230217
  • org.eclipse.jetty:jetty-server 9.4.51.v20230217
  • org.eclipse.jetty:jetty-servlet 9.4.51.v20230217
  • org.apache.tomcat.embed:tomcat-embed-core 9.0.76
  • io.undertow:undertow-core 2.2.24.Final
  • io.undertow:undertow-servlet 2.2.24.Final
  • org.apache.maven.plugins:maven-project-info-reports-plugin 3.4.5
  • org.apache.maven.plugins:maven-javadoc-plugin 3.5.0
samples/install-without-bom/pom.xml
  • com.google.cloud.samples:shared-configuration 1.2.0
  • com.google.cloud:google-cloud-logging-servlet-initializer 0.2.13-alpha
  • junit:junit 4.13.2
  • com.google.truth:truth 1.1.5
  • org.codehaus.mojo:build-helper-maven-plugin 3.4.0
samples/pom.xml
  • com.google.cloud.samples:shared-configuration 1.2.0
  • org.apache.maven.plugins:maven-deploy-plugin 3.1.1
  • org.sonatype.plugins:nexus-staging-maven-plugin 1.6.13
samples/snapshot/pom.xml
  • com.google.cloud.samples:shared-configuration 1.2.0
  • com.google.cloud:google-cloud-logging-servlet-initializer 0.2.14-alpha-SNAPSHOT
  • junit:junit 4.13.2
  • com.google.truth:truth 1.1.5
  • org.codehaus.mojo:build-helper-maven-plugin 3.4.0
samples/snippets/pom.xml
  • com.google.cloud.samples:shared-configuration 1.2.0
  • com.google.cloud:google-cloud-logging-servlet-initializer 0.2.13-alpha
  • junit:junit 4.13.2
  • com.google.truth:truth 1.1.5

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.