You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This directory contains examples of how to implement and use the `MetricProducer` interface to bridge third-party metric sources with OpenTelemetry.
4
+
5
+
## What is MetricProducer?
6
+
7
+
`MetricProducer` is an interface defined in the OpenTelemetry specification that allows you to plug third-party metric sources into an OpenTelemetry `MetricReader`. This is particularly useful for:
8
+
9
+
- Bridging existing monitoring systems to OpenTelemetry
10
+
- Integrating with systems like Prometheus, StatsD, or custom monitoring solutions
11
+
- Collecting pre-processed metrics from external sources
12
+
13
+
## Key Concepts
14
+
15
+
- **MetricProducer**: Interface that defines how to produce metrics from third-party sources
16
+
- **MetricReader**: Collects metrics from both the OpenTelemetry SDK and registered MetricProducers
17
+
- **Pre-processed data**: Unlike OpenTelemetry instruments that collect raw measurements, MetricProducers work with already aggregated metrics
18
+
19
+
## Examples
20
+
21
+
### basic_example.py
22
+
23
+
A comprehensive example showing:
24
+
- How to implement `MetricProducer` for different systems (Prometheus simulation, custom system)
25
+
- How to convert third-party metric formats to OpenTelemetry `MetricsData`
26
+
- How to register producers with a `MetricReader`
27
+
- How both SDK metrics and producer metrics are combined
28
+
29
+
## Running the Examples
30
+
31
+
```bash
32
+
# From the repo root
33
+
cd docs/examples/metrics/producer
34
+
python basic_example.py
35
+
```
36
+
37
+
## Implementation Pattern
38
+
39
+
When implementing a `MetricProducer`:
40
+
41
+
1. **Inherit from MetricProducer**: Create a class that extends the abstract base class
42
+
2. **Implement produce()**: This method should fetch and convert metrics to OpenTelemetry format
43
+
3. **Handle errors gracefully**: Your producer should not crash the entire collection process
44
+
4. **Respect timeout**: The `produce()` method receives a timeout parameter
45
+
5. **Return MetricsData**: Convert your metrics to the standard OpenTelemetry format
46
+
47
+
```python
48
+
from opentelemetry.sdk.metrics.export import MetricProducer, MetricsData
0 commit comments