forked from langflow-ai/langflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: opentelemetry and prometheus (langflow-ai#2543)
* opentelemetry and prometheus * set env override in create_app * add prometheus_client to pyproject * update top level poetry.lock
- Loading branch information
1 parent
d166930
commit 8057156
Showing
7 changed files
with
299 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/backend/base/langflow/services/telemetry/opentelemetry.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from opentelemetry import metrics | ||
from opentelemetry.exporter.prometheus import PrometheusMetricReader | ||
from opentelemetry.sdk.metrics import MeterProvider | ||
from opentelemetry.sdk.resources import Resource | ||
|
||
|
||
class OpenTelemetry: | ||
def __init__(self, prometheus_enabled: bool = True): | ||
resource = Resource.create({"service.name": "langflow"}) | ||
meter_provider = MeterProvider(resource=resource) | ||
self.prometheus_enabled = prometheus_enabled | ||
if prometheus_enabled: | ||
reader = PrometheusMetricReader() | ||
meter_provider = MeterProvider(resource=resource, metric_readers=[reader]) | ||
|
||
metrics.set_meter_provider(meter_provider) | ||
self.meter = meter_provider.get_meter("langflow") | ||
|
||
self._register_metrics() | ||
|
||
def _register_metrics(self): | ||
pass | ||
""" | ||
metrics can be registered in this function | ||
self.counter = self.meter.create_counter( | ||
name = "requests", | ||
unit = "bytes", | ||
description="The number of requests", | ||
) | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.