-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add OpenTelemetry Config #101
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @shaidar, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request adds OpenTelemetry configuration to the Learn AI application. It includes the necessary packages and configurations to send OpenTelemetry data to a running container. The changes involve modifying main/apps.py
to initialize OpenTelemetry, adding OpenTelemetry-related settings to main/settings.py
, creating a new file main/telemetry.py
to handle the OpenTelemetry configuration, and adding OpenTelemetry dependencies to pyproject.toml
.
Highlights
- OpenTelemetry Integration: Adds OpenTelemetry to the application to enable tracing and monitoring.
- Configuration: Introduces new settings for configuring OpenTelemetry, such as enabling it, setting the service name, endpoint, batch size, and export timeout.
- Instrumentation: Instruments Django, Psycopg, Redis, Celery, and Requests to automatically collect tracing data.
Changelog
- main/apps.py
- Modified the
ready
method to initialize OpenTelemetry by callingconfigure_opentelemetry
frommain.telemetry
.
- Modified the
- main/settings.py
- Added new settings for OpenTelemetry, including
OPENTELEMETRY_ENABLED
,OPENTELEMETRY_SERVICE_NAME
,OPENTELEMETRY_ENDPOINT
,OPENTELEMETRY_BATCH_SIZE
, andOPENTELEMETRY_EXPORT_TIMEOUT_MS
.
- Added new settings for OpenTelemetry, including
- main/telemetry.py
- Created a new file to configure OpenTelemetry, including setting up the tracer provider, adding console and OTLP exporters, and instrumenting Django, Psycopg, Redis, Celery, and Requests.
- pyproject.toml
- Added dependencies for OpenTelemetry, including
opentelemetry-api
,opentelemetry-sdk
,opentelemetry-instrumentation-*
, andopentelemetry-exporter-otlp
.
- Added dependencies for OpenTelemetry, including
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Did you know?
OpenTelemetry is a Cloud Native Computing Foundation (CNCF) project, joining other graduated projects like Kubernetes and Prometheus.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces OpenTelemetry configuration to the application, including necessary packages and configurations to send telemetry data to a running container. The changes look good overall, but there are a few areas that could be improved for clarity and maintainability.
Summary of Findings
- Settings Naming Convention: Consider using a more consistent naming convention for OpenTelemetry settings in
settings.py
to improve readability and maintainability. For example, prefixing all settings withOPENTELEMETRY_
. - Error Handling in Telemetry Configuration: While the code checks if OpenTelemetry is enabled, it might be beneficial to add more robust error handling or logging for cases where the OTLP exporter configuration fails.
- Missing Instrumentation: The code initializes several instrumentations, but it might be useful to consider adding more instrumentations based on the application's dependencies (e.g., database client, message queue).
Merge Readiness
The pull request is almost ready for merging. Addressing the naming convention and adding more robust error handling would improve the code quality. I am unable to directly approve the pull request, and other reviewers should review and approve this code before merging.
OPENTELEMETRY_ENABLED = get_bool("OPENTELEMETRY_ENABLED", False) # noqa: FBT003 | ||
OPENTELEMETRY_SERVICE_NAME = get_string("OPENTELEMETRY_SERVICE_NAME", "learn-ai") | ||
OPENTELEMETRY_ENDPOINT = get_string("OPENTELEMETRY_ENDPOINT", None) | ||
OPENTELEMETRY_BATCH_SIZE = get_int("OPENTELEMETRY_BATCH_SIZE", 512) | ||
OPENTELEMETRY_EXPORT_TIMEOUT_MS = get_int("OPENTELEMETRY_EXPORT_TIMEOUT_MS", 5000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider prefixing all OpenTelemetry settings with OPENTELEMETRY_
for consistency and clarity. This makes it easier to identify related settings.
For example, OPENTELEMETRY_SERVICE_NAME
is good, but consider renaming OPENTELEMETRY_BATCH_SIZE
to OPENTELEMETRY_TRACES_BATCH_SIZE
to differentiate it from metrics or logs batch sizes.
OPENTELEMETRY_ENABLED = get_bool("OPENTELEMETRY_ENABLED", False) # noqa: FBT003 | |
OPENTELEMETRY_SERVICE_NAME = get_string("OPENTELEMETRY_SERVICE_NAME", "learn-ai") | |
OPENTELEMETRY_ENDPOINT = get_string("OPENTELEMETRY_ENDPOINT", None) | |
OPENTELEMETRY_BATCH_SIZE = get_int("OPENTELEMETRY_BATCH_SIZE", 512) | |
OPENTELEMETRY_EXPORT_TIMEOUT_MS = get_int("OPENTELEMETRY_EXPORT_TIMEOUT_MS", 5000) | |
OPENTELEMETRY_ENABLED = get_bool("OPENTELEMETRY_ENABLED", False) # noqa: FBT003 | |
OPENTELEMETRY_SERVICE_NAME = get_string("OPENTELEMETRY_SERVICE_NAME", "learn-ai") | |
OPENTELEMETRY_ENDPOINT = get_string("OPENTELEMETRY_ENDPOINT", None) | |
OPENTELEMETRY_TRACES_BATCH_SIZE = get_int("OPENTELEMETRY_TRACES_BATCH_SIZE", 512) | |
OPENTELEMETRY_EXPORT_TIMEOUT_MS = get_int("OPENTELEMETRY_EXPORT_TIMEOUT_MS", 5000) |
otlp_endpoint = getattr(settings, "OPENTELEMETRY_ENDPOINT", None) | ||
if otlp_endpoint: | ||
log.info(f"Configuring OTLP exporter to endpoint: {otlp_endpoint}") | ||
|
||
headers = {} | ||
|
||
otlp_exporter = OTLPSpanExporter( | ||
endpoint=otlp_endpoint, | ||
headers=headers, | ||
) | ||
|
||
tracer_provider.add_span_processor( | ||
BatchSpanProcessor( | ||
otlp_exporter, | ||
max_export_batch_size=getattr(settings, "OPENTELEMETRY_BATCH_SIZE", 512), | ||
schedule_delay_millis=getattr(settings, "OPENTELEMETRY_EXPORT_TIMEOUT_MS", 5000), | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be beneficial to add error handling or logging for cases where the OTLP exporter configuration fails. This could help in debugging issues related to telemetry data export.
otlp_endpoint = getattr(settings, "OPENTELEMETRY_ENDPOINT", None)
if otlp_endpoint:
log.info(f"Configuring OTLP exporter to endpoint: {otlp_endpoint}")
headers = {}
try:
otlp_exporter = OTLPSpanExporter(
endpoint=otlp_endpoint,
headers=headers,
)
tracer_provider.add_span_processor(
BatchSpanProcessor(
otlp_exporter,
max_export_batch_size=getattr(settings, "OPENTELEMETRY_BATCH_SIZE", 512),
schedule_delay_millis=getattr(settings, "OPENTELEMETRY_EXPORT_TIMEOUT_MS", 5000),
)
)
except Exception as e:
log.exception("Failed to configure OTLP exporter: %s", e)
What are the relevant tickets?
Part of https://github.com/mitodl/hq/issues/6893
Description (What does it do?)
Adds necessary packages and configs to the app to send OpenTelemetry data to running container.
How can this be tested?
Ran it locally and got the data shipping to Grafana