function MeterProviderFactory::create
@todo https://github.com/open-telemetry/opentelemetry-specification/blob/main…
- "The exporter MUST configure the default aggregation on the basis of instrument kind using the OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION variable as described below if it is implemented."
File
-
vendor/
open-telemetry/ sdk/ Metrics/ MeterProviderFactory.php, line 32
Class
Namespace
OpenTelemetry\SDK\MetricsCode
public function create(?ResourceInfo $resource = null) : MeterProviderInterface {
if (Sdk::isDisabled()) {
return new NoopMeterProvider();
}
$exporters = Configuration::getList(Variables::OTEL_METRICS_EXPORTER);
//TODO "The SDK MAY accept a comma-separated list to enable setting multiple exporters"
if (count($exporters) !== 1) {
throw new InvalidArgumentException(sprintf('Configuration %s requires exactly 1 exporter', Variables::OTEL_METRICS_EXPORTER));
}
$exporterName = $exporters[0];
try {
$factory = Registry::metricExporterFactory($exporterName);
$exporter = $factory->create();
} catch (\Throwable $t) {
self::logWarning(sprintf('Unable to create %s meter provider: %s', $exporterName, $t->getMessage()));
$exporter = new NoopMetricExporter();
}
// @todo "The exporter MUST be paired with a periodic exporting MetricReader"
$reader = new ExportingReader($exporter);
$resource ??= ResourceInfoFactory::defaultResource();
$exemplarFilter = $this->createExemplarFilter(Configuration::getEnum(Variables::OTEL_METRICS_EXEMPLAR_FILTER));
return MeterProvider::builder()->setResource($resource)
->addReader($reader)
->setExemplarFilter($exemplarFilter)
->build();
}