Giter VIP home page Giter VIP logo

otel-distributed-tracing's Introduction

otel-distributed-tracing

Goals

  1. Introduce Distributed Tracing and Context Propagation concepts
  2. See a minimal example of Distributed Tracing in action
  3. Share some resources to learn more about Distributed Tracing

Concepts

  • What is Distributed Tracing?
    • An Observability concept that gives us the big picture of how a myriad of services interact with each other.
  • What is Context Propagation?
    • The mechanism that allows services to share information with each other to identify a request that traverses code within and across services. Context Propagation is what enables Distributed Tracing.
  • What is a span?
    • A span is an operation or a unit of work. A database query would be a good example of a span.
    • Each span has a unique identifier and is connected to a trace.
  • What is a trace?
    • A trace is a collection of spans that tell the story of how a request traverses code within and across services.
    • Each trace has a unique identifier and is connected to a trace.
    • A trace-id should be globally unique and random.
  • What is Trace Context?
    • Trace Context provides a specification so that services have a mutually agreed upon format for sharing traces across service boundaries.

W3C Recommendation

Fortunately, the W3C provides a specification for Trace Context. This specification solves the problem of defining the format that all parties must agree to in order to share trace information across service boundaries.

The W3C recommends using two HTTP headers to share context:

  1. traceparent
  2. tracestate

traceparent

The traceparent header is made up of four fields separated by a -:

  1. version
  2. trace-id
    1. A 16 byte array
  3. parent-id (the span-id of the caller)
    1. An 8 byte array
  4. trace-flags

Here's an example of a traceparent header:

traceparent: 00-82d7195881bcb9de88498cfd59d9a6f7-cd713b8ff16363f4-01

tracestate

The tracestate header provides a mechanism to share additional information about a trace. It's simply a list of key/value pairs.

Here's an example of a tracestate header:

tracestate: foo=bar

Privacy

Please familiarize yourself with the W3C's Privacy Considerations.

Demo

  1. Start the services
  2. Make a call
  3. Add tracing to bands-api
  4. Add Context Propagation to caller
  5. Make a call
  6. Add tracing to reviews-api
  7. Make a call
  8. Debug performance issue
  9. Fix bugs
  10. Make a call

Next Steps

  • Test the documentation
  • Add code comments to explain what the OTel SDK is doing
  • Add trace-id to Response header
  • Add tracestate to demo
  • Add trace log correlation

Setup

python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip3 install black
pip3 install isort
pip3 install fastapi
pip3 install uvicorn
pip3 install opentelemetry-sdk
pip3 install opentelemetry-exporter-otlp-proto-grpc
pip3 install httpx

Jaeger

Start Jaeger

docker run --name jaeger \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  jaegertracing/all-in-one:latest

bands-api

Start bands-api

uvicorn bands.main:app --reload --port 8000

reviews-api

Start reviews-api

uvicorn reviews.main:app --reload --port 8080

Get a band and its reviews

python3 run.py   
{
    "uuid": "553be815-76f3-49db-b9d7-caca4b23cc3e",
    "name": "Fugazi",
    "reviews": [
        {
            "uuid": "ff8e9267-0b4d-47fa-abc7-4f112c533186",
            "body": "This is the review 1 of 3 for this band.",
            "created": "2023-03-30T10:33:58.886900"
        },
        {
            "uuid": "ff8e9267-0b4d-47fa-abc7-4f112c533186",
            "body": "This is the review 2 of 3 for this band.",
            "created": "2023-03-30T10:33:58.886900"
        },
        {
            "uuid": "ff8e9267-0b4d-47fa-abc7-4f112c533186",
            "body": "This is the review 3 of 3 for this band.",
            "created": "2023-03-30T10:33:58.886900"
        }
    ],
    "created": "2023-03-30T10:33:58.897368"
}
http://localhost:16686/trace/46d714dca76ce65b8b13881cf7b1488a

Resources

otel-distributed-tracing's People

Contributors

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