-
Notifications
You must be signed in to change notification settings - Fork 825
/
OpenCensusMetricProducer.java
55 lines (49 loc) · 1.77 KB
/
OpenCensusMetricProducer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.opencensusshim.metrics;
import io.opencensus.metrics.Metrics;
import io.opencensus.metrics.export.MetricProducerManager;
import io.opentelemetry.opencensusshim.internal.metrics.MetricAdapter;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.export.MetricProducer;
import io.opentelemetry.sdk.resources.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* A producer instance of OpenCensus metrics.
*
* <p>The idea here is we can register this reader with the OpenTelemetry SDK, allowing us to also
* pull metrics from OpenCensus backends on demand.
*/
final class OpenCensusMetricProducer implements MetricProducer {
private final Resource resource;
private final MetricProducerManager openCensusMetricStorage;
OpenCensusMetricProducer(Resource resource, MetricProducerManager openCensusMetricStorage) {
this.resource = resource;
this.openCensusMetricStorage = openCensusMetricStorage;
}
/**
* Constructs a new {@link OpenCensusMetricProducer} that reports against the given {@link
* Resource}.
*/
static MetricProducer create(Resource resource) {
return new OpenCensusMetricProducer(
resource, Metrics.getExportComponent().getMetricProducerManager());
}
@Override
public Collection<MetricData> collectAllMetrics() {
List<MetricData> result = new ArrayList<>();
openCensusMetricStorage
.getAllMetricProducer()
.forEach(
producer -> {
producer
.getMetrics()
.forEach(metric -> result.add(MetricAdapter.convert(resource, metric)));
});
return result;
}
}