Skip to content

Instrument api with opentelemetry #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2024
Merged

Instrument api with opentelemetry #23

merged 3 commits into from
Jun 10, 2024

Conversation

GabrielBarberini
Copy link
Collaborator

@GabrielBarberini GabrielBarberini commented Jun 9, 2024

This PR intends to instrument infinity-API with opentelemetry hosting spans on Uptrace.

In terms of cost, Uptrace provides 50GB or 2500 time-series each month for free, which probably will suit our needs for years.

Summary by CodeRabbit

  • New Features

    • Introduced OpenTelemetry tracing for various API routes, enhancing monitoring and performance tracking.
    • Added a configuration file for Gunicorn to improve deployment settings.
  • Updates

    • Updated project version to "1.2.0" and revised description in project metadata.
    • Updated API version to "1.2.0 BETA".
  • Dependencies

    • Added new dependencies: uptrace, opentelemetry.instrumentation.fastapi, opentelemetry-api, and opentelemetry-sdk.
  • Bug Fixes

    • Adjusted import statement formatting to comply with code quality standards.

Copy link
Contributor

coderabbitai bot commented Jun 9, 2024

Walkthrough

The recent updates introduce OpenTelemetry tracing for various functions across the application, enhancing observability. The Dockerfile's CMD instruction is modified to include a configuration file for gunicorn with a 30-second timeout. The project version is updated to "1.2.0 BETA," and new dependencies for telemetry are added. Minor import formatting adjustments and version updates are also made in the codebase.

Changes

Files Change Summary
Dockerfile Updated CMD to use a configuration file and set a timeout of 30 seconds.
lib/__init__.py Adjusted import statement formatting with # noqa.
lib/api.py Updated version in custom_openapi function from "1.1.0 BETA" to "1.2.0 BETA".
lib/routes/environment.py Added OpenTelemetry tracing for environment-related functions.
lib/routes/flight.py Added OpenTelemetry tracing for flight-related functions.
lib/routes/motor.py Added OpenTelemetry tracing for motor-related functions.
lib/routes/rocket.py Added OpenTelemetry tracing for rocket-related functions.
lib/settings/gunicorn.py Introduced post_fork function for configuring OpenTelemetry with Uptrace and instrumenting FastAPI app.
pyproject.toml Updated project version to "1.2.0" and changed description.
requirements.txt Added dependencies: uptrace, opentelemetry.instrumentation.fastapi, opentelemetry-api, opentelemetry-sdk.

Poem

In code's vast and endless sea,
Tracing now sets our functions free,
With OpenTelemetry's gentle touch,
We monitor and learn so much.
Version bumps and imports neat,
Our API's rhythm skips a beat.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@luimot luimot left a comment

Choose a reason for hiding this comment

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

Didn't try it out but seen it in action outside of GH, seems simple so don't have any worries, seems good, good start for opentelemetry on our API

@GabrielBarberini
Copy link
Collaborator Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jun 10, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
Dockerfile (1)

Line range hint 9-9: Pin versions in apt-get install to avoid potential inconsistencies during builds.

- apt-get install -y --no-install-recommends git
+ apt-get install -y --no-install-recommends git=<specific_version>
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ca0eda6 and 1b2116f.

Files selected for processing (10)
  • Dockerfile (1 hunks)
  • lib/init.py (1 hunks)
  • lib/api.py (1 hunks)
  • lib/routes/environment.py (8 hunks)
  • lib/routes/flight.py (10 hunks)
  • lib/routes/motor.py (8 hunks)
  • lib/routes/rocket.py (8 hunks)
  • lib/settings/gunicorn.py (1 hunks)
  • pyproject.toml (1 hunks)
  • requirements.txt (1 hunks)
Files skipped from review due to trivial changes (4)
  • lib/init.py
  • lib/api.py
  • pyproject.toml
  • requirements.txt
Additional context used
Hadolint
Dockerfile

[warning] 9-9: Pin versions in apt get install. Instead of apt-get install <package> use apt-get install <package>=<version> (DL3008)

Additional comments not posted (18)
lib/settings/gunicorn.py (1)

6-17: Ensure that the post_fork function is correctly setting up OpenTelemetry with Uptrace. The configuration appears correct and follows best practices for tracing setup.

Dockerfile (1)

19-19: The updated CMD instruction correctly specifies the gunicorn configuration and other parameters. Ensure that the specified settings meet the application's performance and concurrency requirements.

lib/routes/environment.py (1)

6-6: OpenTelemetry tracing has been correctly integrated into the environment routes. The tracer is properly initialized and used in the respective functions.

Also applies to: 28-28

lib/routes/motor.py (1)

6-6: OpenTelemetry tracing has been correctly integrated into the motor routes. The tracer is properly initialized and used in the respective functions.

Also applies to: 28-28

lib/routes/rocket.py (6)

42-45: The OpenTelemetry tracing integration in create_rocket is correctly implemented.


56-57: The OpenTelemetry tracing integration in read_rocket is correctly implemented.


76-79: The OpenTelemetry tracing integration in update_rocket is correctly implemented.


90-91: The OpenTelemetry tracing integration in delete_rocket is correctly implemented.


102-105: The OpenTelemetry tracing integration in read_rocketpy_rocket is correctly implemented.


116-117: The OpenTelemetry tracing integration in simulate_rocket is correctly implemented.

lib/routes/flight.py (8)

44-47: The OpenTelemetry tracing integration in create_flight is correctly implemented.


58-59: The OpenTelemetry tracing integration in read_flight is correctly implemented.


70-73: The OpenTelemetry tracing integration in read_rocketpy_flight is correctly implemented.


87-90: The OpenTelemetry tracing integration in update_flight_env is correctly implemented.


109-115: The OpenTelemetry tracing integration in update_flight_rocket is correctly implemented.


134-137: The OpenTelemetry tracing integration in update_flight is correctly implemented.


148-149: The OpenTelemetry tracing integration in delete_flight is correctly implemented.


160-161: The OpenTelemetry tracing integration in simulate_flight is correctly implemented.

@GabrielBarberini GabrielBarberini merged commit f6c96e6 into master Jun 10, 2024
2 of 3 checks passed
@GabrielBarberini GabrielBarberini deleted the opentelemetry branch June 10, 2024 16:28
@coderabbitai coderabbitai bot mentioned this pull request Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants