Hide MetricReader.ProcessMetrics for now (#2683)

This commit is contained in:
Reiley Yang 2021-11-26 11:34:19 -08:00 committed by GitHub
parent 71a6969c1c
commit 4da595faf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 7 additions and 71 deletions

View File

@ -1,59 +0,0 @@
// <copyright file="MyReader.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System;
using System.Text;
using OpenTelemetry;
using OpenTelemetry.Metrics;
internal class MyReader : MetricReader
{
private readonly string name;
public MyReader(string name = "MyReader")
{
this.name = name;
}
protected override bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMilliseconds)
{
var sb = new StringBuilder();
foreach (var record in metrics)
{
if (sb.Length > 0)
{
sb.Append(", ");
}
sb.Append($"{record}");
}
Console.WriteLine($"{this.name}.ProcessMetrics(metrics=[{sb}], timeoutMilliseconds={timeoutMilliseconds})");
return true;
}
protected override bool OnShutdown(int timeoutMilliseconds)
{
Console.WriteLine($"{this.name}.OnShutdown(timeoutMilliseconds={timeoutMilliseconds})");
return base.OnShutdown(timeoutMilliseconds);
}
protected override void Dispose(bool disposing)
{
Console.WriteLine($"{this.name}.Dispose({disposing})");
base.Dispose(disposing);
}
}

View File

@ -42,7 +42,7 @@ public class Program
{
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter("MyCompany.MyProduct.MyLibrary")
.AddReader(new MyReader())
.AddReader(new BaseExportingMetricReader(new MyExporter("ExporterX")))
.AddMyExporter()
.Build();

View File

@ -1,4 +1,3 @@
abstract OpenTelemetry.Metrics.MetricReader.ProcessMetrics(in OpenTelemetry.Batch<OpenTelemetry.Metrics.Metric> metrics, int timeoutMilliseconds) -> bool
OpenTelemetry.BaseExporter<T>.ForceFlush(int timeoutMilliseconds = -1) -> bool
OpenTelemetry.Batch<T>.Batch(T[] items, int count) -> void
OpenTelemetry.Batch<T>.Count.get -> long
@ -116,7 +115,6 @@ override OpenTelemetry.BatchExportProcessor<T>.Dispose(bool disposing) -> void
override OpenTelemetry.Metrics.BaseExportingMetricReader.Dispose(bool disposing) -> void
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnCollect(int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.BaseExportingMetricReader.ProcessMetrics(in OpenTelemetry.Batch<OpenTelemetry.Metrics.Metric> metrics, int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddInstrumentation<TInstrumentation>(System.Func<TInstrumentation> instrumentationFactory) -> OpenTelemetry.Metrics.MeterProviderBuilder
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddMeter(params string[] names) -> OpenTelemetry.Metrics.MeterProviderBuilder
override OpenTelemetry.Metrics.PeriodicExportingMetricReader.Dispose(bool disposing) -> void

View File

@ -1,4 +1,3 @@
abstract OpenTelemetry.Metrics.MetricReader.ProcessMetrics(in OpenTelemetry.Batch<OpenTelemetry.Metrics.Metric> metrics, int timeoutMilliseconds) -> bool
OpenTelemetry.BaseExporter<T>.ForceFlush(int timeoutMilliseconds = -1) -> bool
OpenTelemetry.Batch<T>.Batch(T[] items, int count) -> void
OpenTelemetry.Batch<T>.Count.get -> long
@ -116,7 +115,6 @@ override OpenTelemetry.BatchExportProcessor<T>.Dispose(bool disposing) -> void
override OpenTelemetry.Metrics.BaseExportingMetricReader.Dispose(bool disposing) -> void
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnCollect(int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.BaseExportingMetricReader.ProcessMetrics(in OpenTelemetry.Batch<OpenTelemetry.Metrics.Metric> metrics, int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddInstrumentation<TInstrumentation>(System.Func<TInstrumentation> instrumentationFactory) -> OpenTelemetry.Metrics.MeterProviderBuilder
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddMeter(params string[] names) -> OpenTelemetry.Metrics.MeterProviderBuilder
override OpenTelemetry.Metrics.PeriodicExportingMetricReader.Dispose(bool disposing) -> void

View File

@ -78,7 +78,7 @@ namespace OpenTelemetry.Metrics
}
/// <inheritdoc/>
protected override bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMilliseconds)
internal override bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMilliseconds)
{
// TODO: Do we need to consider timeout here?
return this.exporter.Export(metrics) == ExportResult.Success;

View File

@ -70,7 +70,7 @@ namespace OpenTelemetry.Metrics
public Enumerator GetEnumerator() => new Enumerator(this.head);
/// <inheritdoc/>
protected override bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMilliseconds)
internal override bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMilliseconds)
{
// CompositeMetricReader delegates the work to its underlying readers,
// so CompositeMetricReader.ProcessMetrics should never be called.

View File

@ -191,7 +191,10 @@ namespace OpenTelemetry.Metrics
/// Returns <c>true</c> when metrics processing succeeded; otherwise,
/// <c>false</c>.
/// </returns>
protected abstract bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMilliseconds);
internal virtual bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMilliseconds)
{
return true;
}
/// <summary>
/// Called by <c>Collect</c>. This function should block the current

View File

@ -229,10 +229,6 @@ namespace OpenTelemetry.Extensions.Hosting.Tests
internal class TestReader : MetricReader
{
protected override bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMilliseconds)
{
return true;
}
}
}
}