[PR #17627] [Observability] Integrate OpenTelemetry #28733

Closed
opened 2026-02-21 20:44:01 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/17627

State: closed
Merged: Yes


Summary

This pull request introduces OpenTelemetry (OTel) support to the project, including configuration settings, initialization, and integration with various components.

OpenTelemetry Integration:

Docker Configuration:

By default, the opentelemetry is off. You can turn it on in .env

Screenshots

Before After
... image

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/17627 **State:** closed **Merged:** Yes --- # Summary This pull request introduces OpenTelemetry (OTel) support to the project, including configuration settings, initialization, and integration with various components. ### OpenTelemetry Integration: * [`api/.env.example`](diffhunk://#diff-2fdd31c8eaeb05db626d15ffa6f31b34be3044212e22d6831e976afbab90cc86R466-R478): Added configuration settings for enabling and configuring OpenTelemetry. * [`api/app_factory.py`](diffhunk://#diff-4a41f42da1dee20d447c238eb600571e1e424bfe76bad556de5f6aa20819196dR54): Included `ext_otel` in the list of extensions to initialize OpenTelemetry. [[1]](diffhunk://#diff-4a41f42da1dee20d447c238eb600571e1e424bfe76bad556de5f6aa20819196dR54) [[2]](diffhunk://#diff-4a41f42da1dee20d447c238eb600571e1e424bfe76bad556de5f6aa20819196dR85) * [`api/configs/app_config.py`](diffhunk://#diff-8eb81cc9f0d94efeabc016fcb25cbf62e4dfa116390130e388eaaf4854df630eR12): Imported and added `ObservabilityConfig` to the configuration. [[1]](diffhunk://#diff-8eb81cc9f0d94efeabc016fcb25cbf62e4dfa116390130e388eaaf4854df630eR12) [[2]](diffhunk://#diff-8eb81cc9f0d94efeabc016fcb25cbf62e4dfa116390130e388eaaf4854df630eR63-R64) * [`api/configs/observability/__init__.py`](diffhunk://#diff-f14131a5c85c8d4dfb193ee7992798e532ff8d697c35bbcf9e05a13a1a3bdcefR1-R9): Created `ObservabilityConfig` class inheriting from `OTelConfig`. * [`api/configs/observability/otel/otel_config.py`](diffhunk://#diff-fcc7612e0b8f0e1511318b2314535f94534dd3f59f62f4b4dca6be1ee8743fc2R1-R44): Defined `OTelConfig` class with various OpenTelemetry configuration settings. * [`api/extensions/ext_otel.py`](diffhunk://#diff-d9b99e6e386de2f18f686daf1e6fcb87ca02c20900826cbdc5892a5e81f362b6R1-R130): Implemented `init_app` function to initialize OpenTelemetry and set up context propagation and shutdown procedures. * [`api/pyproject.toml`](diffhunk://#diff-40f8f985c548e2b57b803d17f42833f8a4d94603ca5b5e0bf48de51872809400R52-R65): Added OpenTelemetry dependencies. ### Docker Configuration: * [`docker/.env.example`](diffhunk://#diff-ec10582dde9af6c0c622084d3244b29d496260613491c430ec8958565e2f31b4R1014): Added OpenTelemetry configuration settings to the Docker environment example file. [[1]](diffhunk://#diff-ec10582dde9af6c0c622084d3244b29d496260613491c430ec8958565e2f31b4R1014) [[2]](diffhunk://#diff-ec10582dde9af6c0c622084d3244b29d496260613491c430ec8958565e2f31b4R1039-R1053) * [`docker/README.md`](diffhunk://#diff-da8fcbe728a9172b578e5d754f8e2df214c658c4321f610e63dd68bea828ab49R31-R33): Updated documentation to include OpenTelemetry setup instructions. [[1]](diffhunk://#diff-da8fcbe728a9172b578e5d754f8e2df214c658c4321f610e63dd68bea828ab49R31-R33) [[2]](diffhunk://#diff-da8fcbe728a9172b578e5d754f8e2df214c658c4321f610e63dd68bea828ab49L92-R99) * [`docker/docker-compose.yaml`](diffhunk://#diff-89fafc265c1fa601cf2364b20be83308031335fda9467fcf3249d5ec1c0c8172R458-R468): Added OpenTelemetry environment variables to the shared API worker environment. By default, the opentelemetry is off. You can turn it on in `.env` # Screenshots | Before | After | |--------|-------| | ... | ![image](https://github.com/user-attachments/assets/c5e17ee5-e198-4cee-8eee-fac0a71aecd3) | # Checklist > [!IMPORTANT] > Please review the checklist below before submitting your pull request. - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:44:01 -05:00
yindo closed this issue 2026-02-21 20:44:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#28733