← Back to Pull requests

Python: First pass at updating `getting-started.md` to use the newer declarative, file based configuration #12639

Open
s-sajid-ali opened this pull request with 487 lines diff across 2 files
View on GitHub
s-sajid-ali s-sajid-ali commented on Nov 11, 2026 06:05 UTC
Author

  • I have read and followed the Contributing docs, especially the "First-time contributing?" section.

  • I wrote this PR on my own. I did not use AI to write the PR contents or description. Note the minor exception below

  • [Exception](#exception).
  • I have the experience and knowledge necessary to understand, review, and validate all content in this PR.1
  • Summary

    This PR introduces the declarative configuration method within the getting-started.md page and refreshes the sample outputs from the examples with the most current release of the Python SDK.

    Note that the required version is now Python 3.10+ because that is the minimum version supported by the latest SDK: https://github.com/open-telemetry/opentelemetry-python/blob/v1.45.2/pyproject.toml#L4 . The default version on MacOS is 3.9.6 necessitating the note on asking users to install a newer version of Python.

    Exception


    While all writing was done by me, I disclose that I ran into https://github.com/open-telemetry/opentelemetry-python/issues/5803. In evaluating the root cause of failure and potential fixes, the following config block:
    propagator:
      composite:
        - tracecontext: {}
        - baggage: {}
    

    was used as a hint from a suggestion that I did not come up with directly. I verified that it was a valid schema block by referring to https://opentelemetry.io/docs/specs/otel/configuration/types/#type-propagator and removed the spurious baggage: {} configuration as it was not entirely necessary on a getting started page where no custom baggage was added.

    That block will obsolete (becoming a harmless no-op) once the SDK issue itself is resolved in https://github.com/open-telemetry/opentelemetry-python/pull/5804. This error does not show up when running the example from the SDK docs: https://opentelemetry-python.readthedocs.io/en/latest/examples/declarative-config/README.html so it would be good to have in the documentation for now and can be removed later.

    Let me know if this is the right place for this concept to be introduced! I could have duplicated the split (file config vs cli) at every location, but the explicit nature of the declarative configuration clarifies some of the magic that occurs behind the scenes with the CLI options.

    Partially addresses https://github.com/open-telemetry/opentelemetry.io/issues/10475, except for the demonstration of opentelemetry.sdk.configuration.configure_sdk(...) API which will be addressed based on feedback on this PR.

    Diff: 487 lines (+487 / -0) across 2 files Reviewer: emdneto Review duration: 33658m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.65) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.65 · 487 lines diff across 2 files
    0.65
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.90 · 5 substantive comment(s)
    0.90
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    90%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.370
    Sensitive Paths sensitive_paths
    0.065
    Real PR Conversation Timeline
    16 items
    linux-foundation-easycla[bot] linux-foundation-easycla[bot] commented on Nov 11, 2026 06:06 UTC
    Bot

    <a href="https://easycla.lfx.linuxfoundation.org/#/?version=2"><img src="https://s3.amazonaws.com/cla-project-logo-prod/cla-signed.svg?v=2" alt="CLA Signed" align="left" height="28" width="328" ></a><br >The committers listed above are authorized under a signed CLA.<ul><li>:white_check_mark: login: s-sajid-ali / name: Sajid Ali (8ad5ae30f1d6d5781c575bb889a2ac1857cfce35)</li></ul>

    github-actions[bot] github-actions[bot] commented on Nov 11, 2026 06:06 UTC
    Bot

    Welcome, contributor! Thank you for your contribution to opentelemetry.io.

    Important reminders:

  • Read our Contributing Guidelines.

  • Sign the CLA if you haven't already.

  • Follow the OpenTelemetry Generative AI policy: disclose any AI use in your contribution, and communicate (PR descriptions, review replies) in your own words rather than AI-generated text.

  • Give reviewers at least a few days before pinging them for feedback.

  • If you need help with general setup, development process, or contributor etiquette, ask in #opentelemetry-new-contributors.
  • opentelemetry-pr-dashboard[bot] opentelemetry-pr-dashboard[bot] commented on Nov 11, 2026 06:06 UTC
    Bot

    <!-- pull-request-dashboard-status -->
    <!-- pull-request-dashboard-status-revision:25 -->

    Pull request dashboard status

    Waiting on reviewers · refreshed 2026-12-03 01:12 UTC

    Review the latest changes.

    <details>
    <summary>Status above doesn't look right?</summary>

    <br>

  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.

  • Should this be with the author? Comment /dashboard route:author to route it back.

  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.
  • </details>

    tiffany76 tiffany76 commented on Nov 20, 2026 01:15 UTC
    Contributor

    I'm so glad you followed through on this PR, @s-sajid-ali!

    @open-telemetry/python-approvers, this comes from one of our Contribfest participants at KubeCon NA. PTAL!

    emdneto emdneto requested changes on Nov 20, 2026 14:40 UTC
    Changes Requested Reviewer

    Thanks for the contribution! I believe the declarative configuration for Python SDK deserves a dedicated page instead of mixing it with getting-started. Also, please refer to the package: opentelemetry-configuration in pip commands. The opentelemetry-sdk[file-configuration] is a deprecated alias.

    tammy-baylis-swi tammy-baylis-swi commented on Nov 20, 2026 16:55 UTC
    Contributor

    Thanks @s-sajid-ali ! I agree with above comment; please could you give a dedicated page a try. It will still be great to point to Declarative Config from the existing Getting Started page, so maybe pare those edits down to some concise context then a link to the dedicated page.

    opentelemetry-pr-dashboard[bot] opentelemetry-pr-dashboard[bot] commented on Nov 27, 2026 02:33 UTC
    Bot

    <!-- pull-request-dashboard-author-nudge:08ee24576fd3451d871ae2e02021b665 -->
    Hi @s-sajid-ali — just a friendly reminder that this pull request is waiting on you. The dashboard status comment has the open items and is kept current.

  • Replying is enough to hand it off — answer, explain why no change is needed, or ask a follow-up. The dashboard rechecks who needs to act once nothing on the list is waiting on you.

  • To hand it back for any other reason, including the dashboard getting this wrong, comment /dashboard route:reviewers.
  • <!-- pull-request-dashboard-author-nudge-completed:08ee24576fd3451d871ae2e02021b665 -->

    _Outdated as of 2026-11-27 02:33 UTC: this reminder no longer reflects the current dashboard state. Check the dashboard status comment to see whether action is needed._

    s-sajid-ali s-sajid-ali commented on Dec 02, 2026 04:10 UTC
    Author

    Thanks for the feedback @emdneto & @tammy-baylis-swi : I've added a new page on declarative configuration that cross references the existing language neutral overview for it and the opentelemetry-python docs overview. The getting started page gets an admonition that lets readers know that a page describing this feature is available should they be interested with a link to it.

    Things I'm still unsure about:

  • I'm stating that the v1.43.0 is the first one to support this since it is the first release to honor OTEL_CONFIG_FILE which this example can use, though support for this has been gradually rolling in.

  • https://github.com/open-telemetry/opentelemetry.io/issues/10475 pointed out that the configuration can be done via the opentelemetry.sdk.configuration.configure_sdk(...) API, yet I don't see that API documented at https://opentelemetry-python.readthedocs.io/en/latest/sdk/index.html as of this writing so that might best be addressed in a follow up PR later.
  • Thanks again to @tiffany76 for facilitating this!

    tammy-baylis-swi tammy-baylis-swi commented on code on Dec 02, 2026 17:25 UTC
    Code Review
    content/en/docs/languages/python/configuration.md:1
    @@ -0,0 +1,469 @@
    +---
    +title: Declarative Configuration
    +weight: 100
    +cSpell:ignore: diceroller randint rolldice
    +---
    +
    +Since the `v1.43.0` release of `opentelemetry-sdk`, the SDK supports
    +[declarative configuration](https://opentelemetry-python.readthedocs.io/en/latest/sdk/configuration.html#)
    +as an experimental feature. This page provides an overview of harnessing it. For

    Good call on mentioning that this is experimental. Could you add a few more cautionary words to this intro paragraph? The declarative config file spec is stable, but we want to additionally warn that there could be breaking changes across minor releases.

    tammy-baylis-swi tammy-baylis-swi commented on code on Dec 02, 2026 17:30 UTC
    Code Review
    content/en/docs/languages/python/configuration.md:1
    @@ -0,0 +1,469 @@
    +---
    +title: Declarative Configuration
    +weight: 100
    +cSpell:ignore: diceroller randint rolldice
    +---
    +
    +Since the `v1.43.0` release of `opentelemetry-sdk`, the SDK supports
    +[declarative configuration](https://opentelemetry-python.readthedocs.io/en/latest/sdk/configuration.html#)
    +as an experimental feature. This page provides an overview of harnessing it. For
    +more context on the specification and motivation for using this, please refer
    +[to this page](/docs/languages/sdk-configuration/declarative-configuration.md).
    +
    +> [!NOTE]
    +>
    +> The `v1.43.0` and newer releases of `opentelemetry-sdk` require Python 3.10 or
    +> newer. If your system Python3 installation is older than that, please install
    +> a newer version. One way to maintain multiple installations of Python on your
    +> system is by using [uv](https://docs.astral.sh/uv/guides/install-python/)
    +
    +We will be reusing the application developed in the
    +[Getting Started](./getting-started.md) page which uses the
    +[Flask](https://flask.palletsprojects.com/) framework and has already been
    +manually instrumented. For setup instructions, please refer back to the
    +[Getting Started](./getting-started.md) page. For reference, the source code
    +that we will be using is:
    +
    +<details>
    +<summary>Manually instrumented Flask application</summary>
    +
    +```python
    +# These are the necessary import declarations
    +from opentelemetry import trace
    +from opentelemetry import metrics
    +
    +from random import randint
    +from flask import Flask, request
    +import logging
    +
    +# Acquire a tracer
    +tracer = trace.get_tracer("diceroller.tracer")
    +# Acquire a meter.
    +meter = metrics.get_meter("diceroller.meter")
    +
    +# Now create a counter instrument to make measurements with
    +roll_counter = meter.create_counter(
    +    "dice.rolls",
    +    description="The number of rolls by roll value",
    +)
    +
    +app = Flask(__name__)
    +logging.basicConfig(level=logging.INFO)
    +logger = logging.getLogger(__name__)
    +
    +@app.route("/rolldice")
    +def roll_dice():
    +    # This creates a new span that's the child of the current one
    +    with tracer.start_as_current_span("roll") as roll_span:
    +        player = request.args.get('player', default = None, type = str)
    +        result = str(roll())
    +        roll_span.set_attribute("roll.value", result)
    +        # This adds 1 to the counter for the given roll value
    +        roll_counter.add(1, {"roll.value": result})
    +        if player:
    +            logger.warning("%s is rolling the dice: %s", player, result)
    +        else:
    +            logger.warning("Anonymous player is rolling the dice: %s", result)
    +        return result
    +
    +def roll():
    +    return randint(1, 6)
    +```
    +
    +</details>
    +
    +## Define the exporter configuration
    +
    +Once the application has been setup, opt-in to using the declarative
    +configuration by adding the `opentelemetry-configuration` package with:
    +
    +```shell
    +pip install opentelemetry-configuration
    +```
    +
    +Let us define a minimal configuration for the SDK as shown below in a file

    Here would be a good place to highlight some benefits of using opentelemetry-configuration instead of the kwargs in the Getting Started page, or regular env vars like OTEL_TRACES_EXPORTER.

    tammy-baylis-swi tammy-baylis-swi commented on Dec 02, 2026 17:43 UTC
    Contributor

    Thanks for another pass @s-sajid-ali !

    I'm stating that the v1.43.0 is the first one to support this since it is the first release to honor OTEL_CONFIG_FILE which this example can use, though support for this has been gradually rolling in.

    Yes this version works.

    [[python] Document declarative (file-based) configuration #10475](https://github.com/open-telemetry/opentelemetry.io/issues/10475) pointed out that the configuration can be done via the opentelemetry.sdk.configuration.configure_sdk(...) API, yet I don't see that API documented at https://opentelemetry-python.readthedocs.io/en/latest/sdk/index.html as of this writing so that might best be addressed in a follow up PR later.

    Yes it's totally fine to follow up later 😃 Feel free to update any Python-side docs if you're interested and notice what could be better!

    We have two existing similar pages that I had to dig to find! OpenTelemetry Python SDK > Declarative Configuration is sourced from this RST. Examples > Declarative Configuration is sourced from this RST. Both are similar to your new page but a little tucked away.

    configure_sdk is documented here but I don't think it's set up to render out to readthedocs.

    s-sajid-ali s-sajid-ali commented on code on Dec 03, 2026 01:12 UTC
    Code Review
    content/en/docs/languages/python/configuration.md:1
    @@ -0,0 +1,469 @@
    +---
    +title: Declarative Configuration
    +weight: 100
    +cSpell:ignore: diceroller randint rolldice
    +---
    +
    +Since the `v1.43.0` release of `opentelemetry-sdk`, the SDK supports
    +[declarative configuration](https://opentelemetry-python.readthedocs.io/en/latest/sdk/configuration.html#)
    +as an experimental feature. This page provides an overview of harnessing it. For
    +more context on the specification and motivation for using this, please refer
    +[to this page](/docs/languages/sdk-configuration/declarative-configuration.md).
    +
    +> [!NOTE]
    +>
    +> The `v1.43.0` and newer releases of `opentelemetry-sdk` require Python 3.10 or
    +> newer. If your system Python3 installation is older than that, please install
    +> a newer version. One way to maintain multiple installations of Python on your
    +> system is by using [uv](https://docs.astral.sh/uv/guides/install-python/)
    +
    +We will be reusing the application developed in the
    +[Getting Started](./getting-started.md) page which uses the
    +[Flask](https://flask.palletsprojects.com/) framework and has already been
    +manually instrumented. For setup instructions, please refer back to the
    +[Getting Started](./getting-started.md) page. For reference, the source code
    +that we will be using is:
    +
    +<details>
    +<summary>Manually instrumented Flask application</summary>
    +
    +```python
    +# These are the necessary import declarations
    +from opentelemetry import trace
    +from opentelemetry import metrics
    +
    +from random import randint
    +from flask import Flask, request
    +import logging
    +
    +# Acquire a tracer
    +tracer = trace.get_tracer("diceroller.tracer")
    +# Acquire a meter.
    +meter = metrics.get_meter("diceroller.meter")
    +
    +# Now create a counter instrument to make measurements with
    +roll_counter = meter.create_counter(
    +    "dice.rolls",
    +    description="The number of rolls by roll value",
    +)
    +
    +app = Flask(__name__)
    +logging.basicConfig(level=logging.INFO)
    +logger = logging.getLogger(__name__)
    +
    +@app.route("/rolldice")
    +def roll_dice():
    +    # This creates a new span that's the child of the current one
    +    with tracer.start_as_current_span("roll") as roll_span:
    +        player = request.args.get('player', default = None, type = str)
    +        result = str(roll())
    +        roll_span.set_attribute("roll.value", result)
    +        # This adds 1 to the counter for the given roll value
    +        roll_counter.add(1, {"roll.value": result})
    +        if player:
    +            logger.warning("%s is rolling the dice: %s", player, result)
    +        else:
    +            logger.warning("Anonymous player is rolling the dice: %s", result)
    +        return result
    +
    +def roll():
    +    return randint(1, 6)
    +```
    +
    +</details>
    +
    +## Define the exporter configuration
    +
    +Once the application has been setup, opt-in to using the declarative
    +configuration by adding the `opentelemetry-configuration` package with:
    +
    +```shell
    +pip install opentelemetry-configuration
    +```
    +
    +Let us define a minimal configuration for the SDK as shown below in a file

    Added a paragraph above.

    s-sajid-ali s-sajid-ali commented on code on Dec 03, 2026 01:15 UTC
    Code Review
    content/en/docs/languages/python/configuration.md:1
    @@ -0,0 +1,469 @@
    +---
    +title: Declarative Configuration
    +weight: 100
    +cSpell:ignore: diceroller randint rolldice
    +---
    +
    +Since the `v1.43.0` release of `opentelemetry-sdk`, the SDK supports
    +[declarative configuration](https://opentelemetry-python.readthedocs.io/en/latest/sdk/configuration.html#)
    +as an experimental feature. This page provides an overview of harnessing it. For

    Added as requested. Just to confirm, did you mean that the schema for the spec can change or that the way opentelemerty-python processes this can change?

    herin049 herin049 commented on code on Dec 03, 2026 01:24 UTC
    Code Review
    content/en/docs/languages/python/configuration.md:1
    @@ -0,0 +1,469 @@
    +---
    +title: Declarative Configuration
    +weight: 100
    +cSpell:ignore: diceroller randint rolldice
    +---
    +
    +Since the `v1.43.0` release of `opentelemetry-sdk`, the SDK supports
    +[declarative configuration](https://opentelemetry-python.readthedocs.io/en/latest/sdk/configuration.html#)
    +as an experimental feature. This page provides an overview of harnessing it. For

    This just means that the opentelemetry-configuration Python package is not yet stable. That is, its public API methods or behavior may change in a non-SemVer compatible way across minor releases.

    s-sajid-ali s-sajid-ali commented on code on Dec 03, 2026 21:43 UTC
    Code Review
    content/en/docs/languages/python/configuration.md:1
    @@ -0,0 +1,469 @@
    +---
    +title: Declarative Configuration
    +weight: 100
    +cSpell:ignore: diceroller randint rolldice
    +---
    +
    +Since the `v1.43.0` release of `opentelemetry-sdk`, the SDK supports
    +[declarative configuration](https://opentelemetry-python.readthedocs.io/en/latest/sdk/configuration.html#)
    +as an experimental feature. This page provides an overview of harnessing it. For

    Thanks for the explanation, I've clarified that in the most recent commit.

    Reviewers
    Assignees
    s-sajid-ali s-sajid-ali
    Labels
    risk: low confidence: 90.9% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 64.7% (MEDIUM) · Higher = larger blast radius
    64.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.9% · Lower = rushed or shallow review
    90.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.9% · Safe to merge
    5.9%