Giter Club home page Giter Club logo

opentelemetry-intro-gcf-scala's Introduction

opentelemetry-intro-gcf-scala

This repository contains sample code for configuring OpenTelemetry in Scala Google Cloud Functions. It sets up the metrics client using OpenTelemetry APIs and send the metrics data periodically to Google Monitoring Service backend.

Setup and Build

  • Create a new project with existing resources and use sbt as a build tool in IntelliJ.
  • Open the sbt shell via IntelliJ or command line.
    • run sbt for cli
  • Clean the build directories
    • run clean in sbt shell
  • Build the zip file by running zipTask in sbt shell.

Deploy - UI

  • Go to the Google Cloud Console and go to Cloud Functions.
  • Create a new function named opentelemetry-intro-gcf-scala.
  • Click next
  • After Deployment, a URL will appear at the top that represents the function invocation URL.

Deploy - CLI

  • Upload the zip file containing fat JAR to cloud storage
gcloud storage cp target/opentelemetry-intro-gcf-scala.zip gs://<bucket_name>/functions/opentelemetry-intro-gcf-scala.zip
  • Deploy the google cloud function
gcloud functions deploy opentelemetry-intro-gcf-scala --gen2 --runtime=java11 --region=europe-west1 --source=gs://<bucket_name>/functions/opentelemetry-intro-gcf-scala.zip --entry-point=com.danish.world.HelloWorldScala --memory=256MB --trigger-http
  • Replace <bucket_name> with bucket of your choice.

Testing

  • Running the following curl command invokes the cloud function
curl -m 70 -X POST https://europe-west1-<project_id>.cloudfunctions.net/opentelemetry-intro-gcf-scala -H "Authorization: bearer $(gcloud auth print-identity-token)" -H "Content-Type: application/json" -d '{  "name": "Dino Master" }'
  • Expected output
Hello Dino Master!
  • Replace <project_id> with your project id.

Exploring Metrics in Google Monitoring Service

Data generation

Run the following to generate data

seq 100 | xargs -n 1 -P 10 -I {} curl -m 70 -X POST https://europe-west1-<project_id>.cloudfunctions.net/opentelemetry-intro-gcf-scala -H "Authorization: bearer $(gcloud auth print-identity-token)" -H "Content-Type: application/json" -d '{  "name": "Dino Master" }'

Replace <project_id> with your project id.

Metrics Explorer

Go to Metrics Explorer in Google Monitoring in the cloud console. Change to PromQL and add the following query.

custom_googleapis_com:function_opentelemetry_intro_gcf_scala_danish_requests{monitored_resource="generic_task"}

You may see the following chart.

Note: If the metrics are not visible, see the logs, there might be DEADLINE_EXCEEDED error messages or any other errors from the exporter. They are intermittent and are resolved automatically. If the application is critical, one can use Collector as a proxy between the app and the Google Monitoring Service backend.

opentelemetry-intro-gcf-scala's People

Contributors

damjad avatar

Watchers

 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.