Skip to content

Commit

Permalink
Console exporter: Display exponential histogram boundaries (#4507)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwest authored May 24, 2023
1 parent 47d88e1 commit eb12f9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,21 @@ public override ExportResult Export(in Batch<Metric> batch)
}
else
{
// TODO: Consider how/if to display buckets for exponential histograms.
bucketsBuilder.AppendLine("Buckets are not displayed for exponential histograms.");
var exponentialHistogramData = metricPoint.GetExponentialHistogramData();
var scale = exponentialHistogramData.Scale;

if (exponentialHistogramData.ZeroCount != 0)
{
bucketsBuilder.AppendLine($"Zero Bucket:{exponentialHistogramData.ZeroCount}");
}

var offset = exponentialHistogramData.PositiveBuckets.Offset;
foreach (var bucketCount in exponentialHistogramData.PositiveBuckets)
{
var lowerBound = Base2ExponentialBucketHistogram.LowerBoundary(offset, scale).ToString(CultureInfo.InvariantCulture);
var upperBound = Base2ExponentialBucketHistogram.LowerBoundary(++offset, scale).ToString(CultureInfo.InvariantCulture);
bucketsBuilder.AppendLine($"({lowerBound}, {upperBound}]:{bucketCount}");
}
}

valueDisplay = bucketsBuilder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\OpenTelemetrySdkEventSource.cs" Link="Includes\OpenTelemetrySdkEventSource.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\PeriodicExportingMetricReaderHelper.cs" Link="Includes\PeriodicExportingMetricReaderHelper.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\TagTransformer.cs" Link="Includes\TagTransformer.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Metrics\Base2ExponentialBucketHistogram.LowerBoundary.cs" Link="Includes\Base2ExponentialBucketHistogram.LowerBoundary.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\SpanAttributeConstants.cs" Link="Includes\SpanAttributeConstants.cs" />
Expand Down

0 comments on commit eb12f9b

Please sign in to comment.