Code Monkey home page Code Monkey logo

grafana-opentelemetry-getting-started's Introduction

How to get started with OpenTelemetry and Grafana

This repository contains the sample application which is used in the Grafana webinar How to get started with OpenTelemetry and Grafana. It consists of a minimal Python Flask web application and is based on the OpenTelemetry Getting Started guide for Python.

You can find instructions of how to run the sample application application locally or via Docker.

Run the sample application locally

Requirements

Instructions

  1. Set up a local project directory:

    mkdir otel-getting-started
    cd otel-getting-started
    python3 -m venv venv
    source ./venv/bin/activate

    See Creating Virtual Environments in the official Python documentation for more information.

  2. Install Flask:

    pip install flask
  3. Copy the file app.py from this repository into your project directory.

  4. From your project directory, run the application:

    flask run -p 8080

    With the application running, you should be able to see random dice rolls at http://localhost:8080/rolldice.

  5. Install the OpenTelemetry distro and instrumentation:

    pip install opentelemetry-distro
    opentelemetry-bootstrap -a install
  6. Run the instrumented application with telemetry exported to the console:

    export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
    opentelemetry-instrument \
      --traces_exporter console \
      --metrics_exporter console \
      --logs_exporter console \
      --service_name dice-server \
      flask run -p 8080

    With the application running, you should be able to see random dice rolls at http://localhost:8080/rolldice. On the console, you will see telemetry (metrics, logs, and traces) that is created by your application.

  7. Install the OTLP exporter:

    pip install opentelemetry-exporter-otlp-proto-http
  8. Obtain and set up environment variables to send telemetry data to Grafana Cloud via OTLP.

    Follow the steps below to obtain the environment variable values necessary to send data to your Grafana Cloud stack:

    • Navigate to the Grafana Cloud Portal page.

    • Click Configure in the OpenTelemetry section.

    • Click Generate to generate a new API token.

    • Copy the pre-set environment variables to the console:

      export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
      export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-us-east-0.grafana.net/otlp"
      export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20..." 
  9. Run the instrumented application with telemetry exported to Grafana Cloud:

    export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
    export OTEL_LOGS_EXPORTER=otlp
    opentelemetry-instrument \
      --service_name dice-server \
      flask run -p 8080

After doing some dice rolls via http://localhost:8080/rolldice, metrics, logs, and traces should be visible in Grafana Cloud.

Run the sample application via Docker

Requirements

Instructions

  1. Clone this repository, and from its root directory build the included Dockerfile:

    docker build --tag grafana-otel-webinar .
  2. Run the Docker image with OTLP environment variables set:

    docker run \
      -e OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" \
      -e OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-us-east-0.grafana.net/otlp" 
      -e OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20..." \
      -p 8080:8080 \
      grafana-otel-webinar

    Follow the steps below to obtain the environment variable values necessary to send data to your Grafana Cloud stack:

    • Navigate to the Grafana Cloud Portal page.
    • Click Configure in the OpenTelemetry section.
    • Click Generate to generate a new API token.
    • Use the pre-set environment variables in the command above.

    After doing some dice rolls via http://localhost:8080/rolldice, metrics, logs, and traces should be visible in Grafana Cloud.

grafana-opentelemetry-getting-started's People

Contributors

pyohannes 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.