diff --git a/CHANGELOG.md b/CHANGELOG.md index ad6b1bfe8d5..641e0da140a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- docs: linked the examples with their github source code location and added Prometheus example + ([#4728](https://github.com/open-telemetry/opentelemetry-python/pull/4728)) + ## Version 1.36.0/0.57b0 (2025-07-29) - Add missing Prometheus exporter documentation diff --git a/docs/examples/django/README.rst b/docs/examples/django/README.rst index 1dd8999c036..4f1771fbe68 100644 --- a/docs/examples/django/README.rst +++ b/docs/examples/django/README.rst @@ -4,7 +4,7 @@ Django Instrumentation This shows how to use ``opentelemetry-instrumentation-django`` to automatically instrument a Django app. -For more user convenience, a Django app is already provided in this directory. +The source files of these examples are available :scm_web:`here `. Preparation ----------- diff --git a/docs/examples/error_handler/README.rst b/docs/examples/error_handler/README.rst index b879e53e9bf..178a0b889f9 100644 --- a/docs/examples/error_handler/README.rst +++ b/docs/examples/error_handler/README.rst @@ -6,6 +6,7 @@ Overview This example shows how to use the global error handler. +The source files of these examples are available :scm_web:`here `. Preparation ----------- diff --git a/docs/examples/fork-process-model/README.rst b/docs/examples/fork-process-model/README.rst index 2f33bcf500a..a154fc1249a 100644 --- a/docs/examples/fork-process-model/README.rst +++ b/docs/examples/fork-process-model/README.rst @@ -10,6 +10,8 @@ get around this limitation of the span processor. Please see http://bugs.python.org/issue6721 for the problems about Python locks in (multi)threaded context with fork. +The source code for the examples with Flask app are available :scm_web:`here `. + Gunicorn post_fork hook ----------------------- @@ -61,6 +63,3 @@ uWSGI postfork decorator OTLPSpanExporter(endpoint="http://localhost:4317") ) trace.get_tracer_provider().add_span_processor(span_processor) - - -The source code for the examples with Flask app are available :scm_web:`here `. diff --git a/docs/examples/logs/README.rst b/docs/examples/logs/README.rst index e3cd86362b2..d58c575bac4 100644 --- a/docs/examples/logs/README.rst +++ b/docs/examples/logs/README.rst @@ -6,6 +6,8 @@ OpenTelemetry Logs SDK :mod:`opentelemetry.sdk._logs` are subject to change in minor/patch releases and make no backward compatibility guarantees at this time. +The source files of these examples are available :scm_web:`here `. + Start the Collector locally to see data being exported. Write the following file: .. code-block:: yaml diff --git a/docs/examples/metrics/instruments/README.rst b/docs/examples/metrics/instruments/README.rst index bbc9f457bb7..dffdd02657b 100644 --- a/docs/examples/metrics/instruments/README.rst +++ b/docs/examples/metrics/instruments/README.rst @@ -1,6 +1,8 @@ OpenTelemetry Metrics SDK ========================= +The source files of these examples are available :scm_web:`here `. + Start the Collector locally to see data being exported. Write the following file: .. code-block:: yaml diff --git a/docs/examples/metrics/prometheus-grafana/README.rst b/docs/examples/metrics/prometheus-grafana/README.rst new file mode 100644 index 00000000000..649317c4dc8 --- /dev/null +++ b/docs/examples/metrics/prometheus-grafana/README.rst @@ -0,0 +1,63 @@ +Prometheus Instrumentation +========================== + +This shows how to use ``opentelemetry-exporter-prometheus`` to automatically generate Prometheus metrics. + +The source files of these examples are available :scm_web:`here `. + +Preparation +----------- + +This example will be executed in a separate virtual environment: + +.. code-block:: + + $ mkdir prometheus_auto_instrumentation + $ virtualenv prometheus_auto_instrumentation + $ source prometheus_auto_instrumentation/bin/activate + + +Installation +------------ + +.. code-block:: + + $ pip install -r requirements.txt + + +Execution +--------- + +.. code-block:: + + $ python ./prometheus-monitor.py + $ Server is running at http://localhost:8000 + +Now you can visit http://localhost:8000/metrics to see Prometheus metrics. +You should see something like: + +.. code-block:: + + # HELP python_gc_objects_collected_total Objects collected during gc + # TYPE python_gc_objects_collected_total counter + python_gc_objects_collected_total{generation="0"} 320.0 + python_gc_objects_collected_total{generation="1"} 58.0 + python_gc_objects_collected_total{generation="2"} 0.0 + # HELP python_gc_objects_uncollectable_total Uncollectable objects found during GC + # TYPE python_gc_objects_uncollectable_total counter + python_gc_objects_uncollectable_total{generation="0"} 0.0 + python_gc_objects_uncollectable_total{generation="1"} 0.0 + python_gc_objects_uncollectable_total{generation="2"} 0.0 + # HELP python_gc_collections_total Number of times this generation was collected + # TYPE python_gc_collections_total counter + python_gc_collections_total{generation="0"} 61.0 + python_gc_collections_total{generation="1"} 5.0 + python_gc_collections_total{generation="2"} 0.0 + # HELP python_info Python platform information + # TYPE python_info gauge + python_info{implementation="CPython",major="3",minor="8",patchlevel="5",version="3.8.5"} 1.0 + # HELP MyAppPrefix_my_counter_total + # TYPE MyAppPrefix_my_counter_total counter + MyAppPrefix_my_counter_total 964.0 + +``MyAppPrefix_my_counter_total`` is the custom counter created in the application with the custom prefix ``MyAppPrefix``. diff --git a/docs/examples/metrics/prometheus-grafana/prometheus-monitor.py b/docs/examples/metrics/prometheus-grafana/prometheus-monitor.py index 17a837d5a58..709b0b9e758 100644 --- a/docs/examples/metrics/prometheus-grafana/prometheus-monitor.py +++ b/docs/examples/metrics/prometheus-grafana/prometheus-monitor.py @@ -18,6 +18,8 @@ my_counter = meter.create_counter("my.counter") +print("Server is running at http://localhost:8000") + while 1: my_counter.add(random.randint(1, 10)) time.sleep(random.random())