Skip to content

Add rolldice reference application (FastAPI) - #5244

Closed
reggied wants to merge 11 commits into
open-telemetry:mainfrom
reggied:reference_app
Closed

reggied wants to merge 11 commits into
open-telemetry:mainfrom
reggied:reference_app

Conversation

@reggied

@reggied reggied commented May 21, 2026 •

Copy link
Copy Markdown

Description

Implements the OpenTelemetry reference application specification [1] with both uninstrumented and instrumented versions of a FastAPI dice-rolling service. The instrumented version uses declarative (file-based) YAML configuration for the telemetry pipeline with OTLP HTTP and console exporters for all three signal types (traces, metrics, logs).

[1] https://opentelemetry.io/docs/getting-started/reference-application-specification/

Fixes # #5167

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla

linux-foundation-easycla Bot commented May 21, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

Implements the OpenTelemetry reference application specification [1] with
both uninstrumented and instrumented versions of a FastAPI dice-rolling
service. The instrumented version uses declarative (file-based) YAML
configuration for the telemetry pipeline with OTLP HTTP and console
exporters for all three signal types (traces, metrics, logs).

[1] https://opentelemetry.io/docs/getting-started/reference-application-specification/

Assisted-by: Claude Opus 4.6
reggied and others added 2 commits May 28, 2026 08:34
Add OS resource detector, OTEL_LOG_LEVEL diagnostic verbosity control,
dynamic OTEL_SERVICE_NAME support via env var substitution, and a CI
workflow that smoke-tests both the instrumented and uninstrumented
variants of the rolldice application.

Co-Authored-By: Claude Opus 4.6 (1M context)
Update all license headers to the SPDX two-line format, fix import
sorting and formatting per ruff, and add a towncrier changelog fragment.
@reggied
reggied marked this pull request as ready for review May 28, 2026 17:48
@reggied
reggied requested a review from a team as a code owner May 28, 2026 17:48
@reggied

reggied commented Jun 8, 2026

Copy link
Copy Markdown
Author

@MikeGoldsmith , could you take a look at this when you get a chance?

@tammy-baylis-swi tammy-baylis-swi moved this to Ready for review in Python PR digest Jun 11, 2026
@tammy-baylis-swi

Copy link
Copy Markdown
Contributor

Thank you for this @reggied ! Have we considered putting it in docs/examples instead? https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples

@reggied

reggied commented Jun 11, 2026

Copy link
Copy Markdown
Author

Thank you for this @reggied ! Have we considered putting it in docs/examples instead? https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples

Hi @tammy-baylis-swi ! I'm new to this repo, so the current location was a best guess. I didn't put it in docs/examples because the modules in there seemed like simple one-file examples whereas this is an entire example application, but if you think that is more appropriate, I can move it. How would you name it?

@tammy-baylis-swi

Copy link
Copy Markdown
Contributor

Hi @tammy-baylis-swi ! I'm new to this repo, so the current location was a best guess. I didn't put it in docs/examples because the modules in there seemed like simple one-file examples whereas this is an entire example application, but if you think that is more appropriate, I can move it. How would you name it?

Nice, welcome 👋

I suggest docs/examples/fastapi-rolldice to align with existing docs/examples/django, and so it will link from https://opentelemetry-python.readthedocs.io/en/stable/examples/ via https://opentelemetry.io/docs/languages/python/. This is definitely a more substantial example than the Django one but I think it's a better fit than say the FastAPI instrumentor source code

@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Jun 30, 2026
reggied added 2 commits July 3, 2026 13:28
In response reviewer feedback, move theI roll dice reference app to
the docs/examples.
@github-actions github-actions Bot removed the Stale label Jul 4, 2026
@reggied

reggied commented Jul 4, 2026

Copy link
Copy Markdown
Author

@tammy-baylis-swi , I've moved the reference app as you suggested, please take a look when you can. Thanks!

@emdneto emdneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. ✌🏻 Left some comments/suggestions

version = "0.1.0"
description = "OpenTelemetry reference application — rolldice (FastAPI)"
license = "Apache-2.0"
requires-python = ">=3.12"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to stick with the supported baseline version, which is 3.10.

@emdneto emdneto Jul 6, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we follow the same approach as other tests and implement the logic in Python code and run it through tox, so anyone can run it locally without relying on the CI feedback. You can take a look at docker-tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use configure_sdk from sdk._configuration module?


.. code-block:: bash

uvicorn app.main:app --host 0.0.0.0 --port 8080

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say we can mention in advance that an OTLP backend needs to be running otherwise, the user will see a lot of failures in the logs. I know we have this instruction later in this guide, but it would be nice to "enforce" the user to have a collector running before executing this command.


.. code-block:: bash

cd instrumentation/opentelemetry-instrumentation-fastapi/examples/rolldice

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a fix in the path here?

sampler:
parent_based:
root:
always_on:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
always_on:
always_on: {}

push:
branches: [main]
paths:
- "instrumentation/opentelemetry-instrumentation-fastapi/examples/rolldice/**"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Needs updating.

@lzchen lzchen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think it might be worth it to wait until configure_sdk is available so we can just simply remove all the duplicate code.

@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Jul 22, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

This PR has been closed due to inactivity. Please reopen if you would like to continue working on it.

@github-actions github-actions Bot closed this Aug 6, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Done in Python PR digest Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants