Minor metric fixes (#3159)

This commit is contained in:
Cijo Thomas 2022-04-12 14:45:11 -07:00 committed by GitHub
parent c261a67005
commit c4abf0b330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 2 deletions

View File

@ -25,7 +25,8 @@ using OpenTelemetry.Resources;
namespace OpenTelemetry.Metrics
{
/// <summary>
/// Build MeterProvider with Resource, Readers, and Instrumentation.
/// Build MeterProvider with Instrumentations, Meters,
/// Resource, Readers, and Views.
/// </summary>
public abstract class MeterProviderBuilderBase : MeterProviderBuilder
{

View File

@ -106,6 +106,13 @@ namespace OpenTelemetry.Metrics
return true;
}
/// <summary>
/// Finds the Metric exporter of the given type from the provider.
/// </summary>
/// <typeparam name="T">The type of the Exporter.</typeparam>
/// <param name="provider">The MeterProvider from which Exporter should be found.</param>
/// <param name="exporter">The exporter instance.</param>
/// <returns>true if the exporter of specified Type is found; otherwise false.</returns>
public static bool TryFindExporter<T>(this MeterProvider provider, out T exporter)
where T : BaseExporter<Metric>
{

View File

@ -71,7 +71,8 @@ namespace OpenTelemetry.Metrics
/// <item>If not provided, all the tags provided by the instrument
/// while reporting measurements will be used for aggregation.
/// If provided, only those tags in this list will be used
/// for aggregation.
/// for aggregation. Providing an empty array will result
/// in a metric stream without any tags.
/// </item>
/// <item>A copy is made of the provided array.</item>
/// </list>

View File

@ -0,0 +1,45 @@
// <copyright file="MeterProviderTests.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.Collections.Generic;
using OpenTelemetry.Exporter;
using Xunit;
namespace OpenTelemetry.Metrics.Tests
{
public class MeterProviderTests
{
[Fact]
public void MeterProviderFindExporterTest()
{
var exportedItems = new List<Metric>();
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddInMemoryExporter(exportedItems)
.Build();
Assert.True(meterProvider.TryFindExporter(out InMemoryExporter<Metric> inMemoryExporter));
Assert.False(meterProvider.TryFindExporter(out MyExporter myExporter));
}
private class MyExporter : BaseExporter<Metric>
{
public override ExportResult Export(in Batch<Metric> batch)
{
return ExportResult.Success;
}
}
}
}