Git Product home page Git Product logo

oh_libhoney_webapp's Introduction

libhoney-java-example-webapp

This application demonstrates a simple Honeycomb instrumentation of a Spring Boot application. It is CRUD interface for managing a TODOs list. The backend is an in-memory H2 database.

Events are created per-HTTP-request (following the Honeycomb one event per unit of work model) using a Spring Handler Interceptor to capture request/response data and use the libhoney-java SDK to send events to HoneyComb. A request context is propagated throughout the app (using Spring's request scope) allowing other parts of the request processing to be instrumented. Calls to the SQL backend are instrumented as an example. This is a straightforward approach to context propagation which you can enhance using other parts of the Spring framework. For example, the Spring Data repository calls could be instrumented using AOP (as in this example given by Spring).

Run locally

Required configuration

Set your HoneyComb write key and the dataset you want to report to by using the application.properties file.

This application requires Java 8.

Run commands

You can build an executable jar in the module target directory using gradle wapper:

./gradlew build

open console and execute command to run .jar file created:

java -jar PATH_PROJECT/build/libs/libhoney-java-example-webapp-1.0.2-capsule.jar

open browser:

http://localhost:8080

The project is running.

Global fields

You can set other 'global' SDK properties in the application.properties file, including setting any 'global fields'. These are fields that will be included in any event sent (unless overridden at a more specific scope, e.g. the event level). See the SDK documentation for more detail on how 'global fields' are resolved.

The default configuration adds two global fields as follows:

honeycomb.global-fields.app.name: example-web-app
honeycomb.global-fields.app.region: us-west-1

This creates these global fields:

app.name: example-web-app
app.region: us-west-1

Response Observer

A simple Response Observer is registered with the HoneyComb SDK. This logs into the console a response to each HoneyComb event submitted to the SDK. A more mature application might monitor/alert on these responses in order to ensure that the HoneyComb integration is working well.

API

A basic REST API for todos is exposed on port 8080 (see the application.properties if you would like to override this):

$ curl \
    -H 'Content-Type: application/json' \
    -X POST -d '{"description": "Walk the dog", "due": 1518816723}' \
    localhost:8080/todos/
...

$ curl localhost:8080/todos/
[
  {
    "completed": false,
    "description": "Walk the dog",
    "due": "Fri, 16 Feb 2018 21:32:03 GMT",
    "id": 1
  }
]

$ curl -X PUT \
    -H 'Content-Type: application/json' \
    -d '{"description": "Walk the cat"}' \
    localhost:8080/todos/1/
{
  "completed": false,
  "description": "Walk the cat",
  "due": "Fri, 16 Feb 2018 21:32:03 GMT",
  "id": 1
}

$ curl -X DELETE localhost:8080/todos/1/
{
  "id": 1,
  "success": true
}

$ curl localhost:8080/todos/
[]

Event fields

The following fields will be sent to HoneyComb:

Name Description Example Value
errors.message Message in the error encountered, if applicable undefined
request.method HTTP method POST
request.path Request path /todos
request.user_agent.browser Web browser the request was served to chrome
request.user_agent.platform OS of the user agent macos
request.user_agent.string Literal user agent string curl/7.54.0
request.user_agent.version Version of the user agent 64.0.3282.186
response.status_code HTTP status code of the response 404
timers.db.delete_todo Time in milliseconds for DB call to delete a todo 23
timers.db.insert_todo_ms Time in milliseconds for DB call to insert a todo 50
timers.db.select_all_todos Time in millisconds for DB call to select all todos 11
timers.db.update_todo Time in milliseconds for DB call to update a todo 50
timers.total_time_ms Total time in milliseconds spent serving the request 75
app.name An example global field example-web-app
app.region Another example global field us-west-1

Example Query In the Honeycomb UI

Example Honeycomb UI Query

oh_libhoney_webapp's People

Contributors

chritian92 avatar pipo411 avatar omar-limbert avatar

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.