-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Adds OTEL instrumentation to OpenAI API server #19987
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
base: main
Are you sure you want to change the base?
Conversation
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
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.
Summary of Changes
Hello @bbartels, 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!
This pull request introduces OpenTelemetry (OTEL) instrumentation to the OpenAI API server. The primary goal is to enable distributed tracing for requests processed by the server, enhancing observability and facilitating performance monitoring. This involves adding new OpenTelemetry dependencies, integrating a dedicated observability configuration throughout the engine, and setting up the FastAPI application to export traces via OTLP.
Highlights
- Dependency Management: Added several OpenTelemetry-related Python packages to
requirements/common.txt
, includingopentelemetry-sdk
,opentelemetry-api
,opentelemetry-exporter-otlp
,opentelemetry-semantic-conventions-ai
, andopentelemetry-instrumentation-fastapi
. - Observability Configuration Integration: Introduced a new
ObservabilityConfig
type and integrated its retrieval across various engine components. This includes addingget_observability_config
methods toAsyncLLMEngine
,LLMEngine
, and theMQLLMEngineClient
, as well as defining it as an abstract method in the engineprotocol.py
. - FastAPI OpenTelemetry Instrumentation: Implemented a
setup_otel
function invllm/entrypoints/openai/api_server.py
to configure OpenTelemetry tracing for the FastAPI application. This function sets up aTracerProvider
, anOTLPSpanExporter
(using a configurable OTLP traces endpoint), and instruments the FastAPI app usingFastAPIInstrumentor
. - Dynamic Instrumentation Activation: Modified the
build_app
function inapi_server.py
to accept and utilize theObservabilityConfig
. Thesetup_otel
function is conditionally called withinbuild_app
only if an OTLP traces endpoint is specified in the configuration, allowing for flexible enablement of tracing.
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.
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 instrumentation to the OpenAI API server, enhancing observability by exporting traces to an OTLP endpoint. The changes involve adding necessary dependencies, creating a function to set up OTEL, and integrating it into the FastAPI application. The code appears well-structured and addresses the core objective of adding OTEL support. I've provided some suggestions for improved error handling, documentation, and code clarity.
def setup_otel(app: FastAPI, observability_config: ObservabilityConfig): | ||
from opentelemetry import trace | ||
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import BatchSpanProcessor | ||
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor | ||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource | ||
|
||
trace.set_tracer_provider(TracerProvider(resource=Resource.create())) | ||
|
||
otlp_exporter = OTLPSpanExporter(endpoint=observability_config.otlp_traces_endpoint) | ||
trace.get_tracer_provider().add_span_processor( | ||
BatchSpanProcessor(otlp_exporter) | ||
) | ||
|
||
FastAPIInstrumentor().instrument_app(app) |
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.
This setup_otel
function initializes and configures OpenTelemetry. It would be beneficial to add a docstring explaining its purpose, parameters, and any potential side effects (e.g., setting global tracer provider).
def setup_otel(app: FastAPI, observability_config: ObservabilityConfig):
"""Initializes and configures OpenTelemetry for the FastAPI application.
Args:
app: The FastAPI application instance.
observability_config: The ObservabilityConfig containing OTEL settings.
"""
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
trace.set_tracer_provider(TracerProvider(resource=Resource.create()))
otlp_exporter = OTLPSpanExporter(endpoint=observability_config.otlp_traces_endpoint)
trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(otlp_exporter)
)
FastAPIInstrumentor().instrument_app(app)
|
||
trace.set_tracer_provider(TracerProvider(resource=Resource.create())) | ||
|
||
otlp_exporter = OTLPSpanExporter(endpoint=observability_config.otlp_traces_endpoint) |
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 adding a try-except block around the OTLPSpanExporter
initialization to catch potential exceptions (e.g., network errors, invalid endpoint). This would allow for more graceful error handling and prevent the server from crashing if the OTEL exporter fails to initialize.
try:
otlp_exporter = OTLPSpanExporter(endpoint=observability_config.otlp_traces_endpoint)
except Exception as e:
logger.error(f"Failed to initialize OTLP exporter: {e}")
return # Or raise, depending on desired behavior
Signed-off-by: bbartels <benjamin@bartels.dev>
Signed-off-by: bbartels <benjamin@bartels.dev>
Signed-off-by: bbartels <benjamin@bartels.dev>
Signed-off-by: bbartels <benjamin@bartels.dev>
Signed-off-by: bbartels <benjamin@bartels.dev>
Signed-off-by: bbartels <benjamin@bartels.dev>
Signed-off-by: bbartels <benjamin@bartels.dev>
1fd189f
to
56224fc
Compare
Signed-off-by: bbartels <benjamin@bartels.dev>
Just saw: #19378 |
hi @bbartels so the big issue was making open-telemetry a required vllm dependency It can cause unsolvable conflicts for downstream integrations. From my understanding, this was the issue:
It’s not easy to satisfy these constraints. |
Seems like this should resolve it on the ray side: ray-project/ray#53745 I'll leave this open until that is merged and a new ray version is published! |
Hi @bbartels, I believe everything in requirements/common.txt is a hard dependency and not conditionally imported. Including opentelemetry-exporter-otlp as a dependency has caused issues for our users, as recent versions require upgrading to Protobuf 5+, which many users aren't ready for. This PR — ray-project/ray#53745 — actually also removes opentelemetry-exporter-otlp on the Ray side, in line with recent changes in the vLLM project. TL;DR: I wouldn't recommend making opentelemetry-exporter-otlp a hard dependency for vLLM. Users with workflows that require it — and who are okay with upgrading Protobuf — can install it as needed. |
This pull request has merge conflicts that must be resolved before it can be |
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.Purpose
This adds the ability to publish OTEL metrics from the openai API server
Test Plan
Test Result
Metrics were correctly published
(Optional) Documentation Update