open-telemetry / open-telemetry/opentelemetry-python-contrib

Tracing for stdlib http.HTTPServer

Open
#3,059 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Describe your environment

OS: Fedora 41
Python version: 3.13
Package version: 0.49b2 / latest

What happened?

A simple app is not instrumented properly

from http.server import BaseHTTPRequestHandler, HTTPServer

class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/':
            self.send_response(200)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
            self.wfile.write(b'Hello')
        else:
            self.send_response(404)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
            self.wfile.write(b'not found')

def run(server_class=HTTPServer, handler_class=RequestHandler, port=8080):
    server_address = ('', port)
    httpd = server_class(server_address, handler_class)
    print(f'Starting server on: {port}')
    httpd.serve_forever()

if __name__ == '__main__':
    run()
Steps to Reproduce

And instrument

pip install opentelemetry-distro opentelemetry-exporter-otlp
~/.local/bin/opentelemetry-bootstrap -a install
~/.local/bin/opentelemetry-instrument  --service_name python-example  --exporter_otlp_endpoint localhost:4317 --traces_exporter console,otlp --metrics_exporter console python helloworld.py
...
Starting httpd server on port 8080
127.0.0.1 - - [02/Dec/2024 13:59:40] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [02/Dec/2024 13:59:40] "GET / HTTP/1.1" 200 -

Follow steps in https://github.com/pavolloffay/otel-python-bug-03969593

Expected Result

See traces from HTTP server

Actual Result

No traces reported, no logged error in the app.

Additional context

https://github.com/pavolloffay/otel-python-bug-03969593

Would you like to implement a fix?

None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the linked repository and its helloworld.py HTTPServer example; start at the opentelemetry-instrument entry point and Python's stdlib HTTPServer. Compare the run with the expected console or OTLP output, and consider it done when HTTP requests produce traces without application errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.