Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base2 Exponential Bucket Histogram should reset to scale 20 after each collection cycle if DELTA aggregation temporality is used #5635

Open
reyang opened this issue May 21, 2024 · 0 comments
Labels
bug Something isn't working metrics pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Comments

@reyang
Copy link
Member

reyang commented May 21, 2024

Package

OpenTelemetry

Package Version

Package Name Version
OpenTelemetry.Api 1.8.0
OpenTelemetry 1.8.0

Runtime Version

all

Description

// TODO: Determine if this is sufficient for delta temporality.
// I'm not sure we should be resetting the scale.

It should reset, otherwise the precision will never recover unless the process restarted.

Steps to Reproduce

using System.Diagnostics.Metrics;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;

namespace CustomizingTheSdk;

public class Program
{
    private static readonly Meter Meter1 = new("CompanyA.ProductA.Library1", "1.0");

    public static void Main()
    {
        using var meterProvider = Sdk.CreateMeterProviderBuilder()
            .AddMeter(Meter1.Name)
            .AddView(instrumentName: "MyExponentialBucketHistogram", new Base2ExponentialBucketHistogramConfiguration())
            .AddConsoleExporter((_, readerOptions) => readerOptions.TemporalityPreference = MetricReaderTemporalityPreference.Delta)
            .Build();

        var random = new Random();

        var exponentialBucketHistogram = Meter1.CreateHistogram<long>("MyExponentialBucketHistogram");
        for (int i = 0; i < 20000; i++)
        {
            exponentialBucketHistogram.Record(random.Next(1, 1000), new("tag1", "value1"), new("tag2", "value2"));
        }

        meterProvider.ForceFlush();
    
        exponentialBucketHistogram.Record(2, new("tag1", "value1"), new("tag2", "value2"));
    }
}

Expected Result

The 2nd export batch should have low dynamic range and high precision (scale = 20) since Delta Temporality is used.

Actual Result

The 2nd export batch has a large dynamic range (0.0.9170040432046712, 1024] and low precision, which was carried from the 1st export.

Resource associated with Metric:
    telemetry.sdk.name: opentelemetry
    telemetry.sdk.language: dotnet
    telemetry.sdk.version: 1.8.1-alpha.0.75
    service.name: unknown_service:customizing-the-sdk

Metric Name: MyExponentialBucketHistogram, Meter: CompanyA.ProductA.Library1/1.0
(2024-05-21T04:32:29.6575560Z, 2024-05-21T04:32:29.6881729Z] tag1: value1 tag2: value2 ExponentialHistogram
Value: Sum: 9953662 Count: 20000 Min: 1 Max: 999
(0.9170040432046712, 1]:25
(1, 1.0905077326652577]:0
(1.0905077326652577, 1.189207115002721]:0
(1.189207115002721, 1.2968395546510096]:0
(1.2968395546510096, 1.414213562373095]:0
(1.414213562373095, 1.5422108254079407]:0
(1.5422108254079407, 1.681792830507429]:0
(1.681792830507429, 1.8340080864093424]:0
(1.8340080864093424, 2]:18
(2, 2.1810154653305154]:0
(2.1810154653305154, 2.378414230005442]:0
(2.378414230005442, 2.5936791093020193]:0
(2.5936791093020193, 2.82842712474619]:0
(2.82842712474619, 3.0844216508158815]:17
(3.0844216508158815, 3.363585661014858]:0
(3.363585661014858, 3.668016172818685]:0
(3.668016172818685, 4]:16
(4, 4.362030930661031]:0
(4.362030930661031, 4.756828460010884]:0
(4.756828460010884, 5.187358218604039]:18
(5.187358218604039, 5.656854249492381]:0
(5.656854249492381, 6.168843301631763]:25
(6.168843301631763, 6.727171322029717]:0
(6.727171322029717, 7.33603234563737]:11
(7.33603234563737, 7.999999999999998]:19
(7.999999999999998, 8.724061861322062]:0
(8.724061861322062, 9.513656920021766]:16
(9.513656920021766, 10.374716437208079]:25
(10.374716437208079, 11.31370849898476]:20
(11.31370849898476, 12.337686603263528]:17
(12.337686603263528, 13.454342644059432]:25
(13.454342644059432, 14.672064691274741]:18
(14.672064691274741, 15.999999999999998]:40
(15.999999999999998, 17.448123722644116]:24
(17.448123722644116, 19.027313840043536]:40
(19.027313840043536, 20.749432874416147]:16
(20.749432874416147, 22.62741699796952]:32
(22.62741699796952, 24.67537320652705]:53
(24.67537320652705, 26.908685288118864]:37
(26.908685288118864, 29.344129382549472]:73
(29.344129382549472, 32]:66
(32, 34.89624744528824]:44
(34.89624744528824, 38.05462768008707]:82
(38.05462768008707, 41.4988657488323]:60
(41.4988657488323, 45.254833995939045]:75
(45.254833995939045, 49.3507464130541]:86
(49.3507464130541, 53.817370576237735]:81
(53.817370576237735, 58.68825876509898]:90
(58.68825876509898, 63.99999999999998]:136
(63.99999999999998, 69.79249489057648]:98
(69.79249489057648, 76.10925536017416]:142
(76.10925536017416, 82.99773149766457]:132
(82.99773149766457, 90.50966799187806]:164
(90.50966799187806, 98.70149282610821]:142
(98.70149282610821, 107.63474115247547]:174
(107.63474115247547, 117.37651753019786]:212
(117.37651753019786, 127.99999999999997]:205
(127.99999999999997, 139.58498978115298]:228
(139.58498978115298, 152.21851072034832]:249
(152.21851072034832, 165.99546299532915]:259
(165.99546299532915, 181.01933598375612]:353
(181.01933598375612, 197.40298565221642]:325
(197.40298565221642, 215.26948230495097]:350
(215.26948230495097, 234.75303506039575]:378
(234.75303506039575, 255.99999999999994]:419
(255.99999999999994, 279.16997956230597]:487
(279.16997956230597, 304.4370214406964]:505
(304.4370214406964, 331.99092599065835]:519
(331.99092599065835, 362.0386719675123]:631
(362.0386719675123, 394.8059713044329]:655
(394.8059713044329, 430.5389646099016]:750
(430.5389646099016, 469.5060701207915]:735
(469.5060701207915, 511.99999999999994]:853
(511.99999999999994, 558.339959124612]:934
(558.339959124612, 608.8740428813928]:993
(608.8740428813928, 663.9818519813167]:1165
(663.9818519813167, 724.0773439350246]:1228
(724.0773439350246, 789.6119426088659]:1309
(789.6119426088659, 861.0779292198033]:1403
(861.0779292198033, 939.0121402415831]:1561
(939.0121402415831, 1024]:1137


Metric Name: MyExponentialBucketHistogram, Meter: CompanyA.ProductA.Library1/1.0
(2024-05-21T04:32:29.6881729Z, 2024-05-21T04:32:29.7153904Z] tag1: value1 tag2: value2 ExponentialHistogram
Value: Sum: 2 Count: 1 Min: 2 Max: 2
(0.9170040432046712, 1]:0
(1, 1.0905077326652577]:0
(1.0905077326652577, 1.189207115002721]:0
(1.189207115002721, 1.2968395546510096]:0
(1.2968395546510096, 1.414213562373095]:0
(1.414213562373095, 1.5422108254079407]:0
(1.5422108254079407, 1.681792830507429]:0
(1.681792830507429, 1.8340080864093424]:0
(1.8340080864093424, 2]:1
(2, 2.1810154653305154]:0
(2.1810154653305154, 2.378414230005442]:0
(2.378414230005442, 2.5936791093020193]:0
(2.5936791093020193, 2.82842712474619]:0
(2.82842712474619, 3.0844216508158815]:0
(3.0844216508158815, 3.363585661014858]:0
(3.363585661014858, 3.668016172818685]:0
(3.668016172818685, 4]:0
(4, 4.362030930661031]:0
(4.362030930661031, 4.756828460010884]:0
(4.756828460010884, 5.187358218604039]:0
(5.187358218604039, 5.656854249492381]:0
(5.656854249492381, 6.168843301631763]:0
(6.168843301631763, 6.727171322029717]:0
(6.727171322029717, 7.33603234563737]:0
(7.33603234563737, 7.999999999999998]:0
(7.999999999999998, 8.724061861322062]:0
(8.724061861322062, 9.513656920021766]:0
(9.513656920021766, 10.374716437208079]:0
(10.374716437208079, 11.31370849898476]:0
(11.31370849898476, 12.337686603263528]:0
(12.337686603263528, 13.454342644059432]:0
(13.454342644059432, 14.672064691274741]:0
(14.672064691274741, 15.999999999999998]:0
(15.999999999999998, 17.448123722644116]:0
(17.448123722644116, 19.027313840043536]:0
(19.027313840043536, 20.749432874416147]:0
(20.749432874416147, 22.62741699796952]:0
(22.62741699796952, 24.67537320652705]:0
(24.67537320652705, 26.908685288118864]:0
(26.908685288118864, 29.344129382549472]:0
(29.344129382549472, 32]:0
(32, 34.89624744528824]:0
(34.89624744528824, 38.05462768008707]:0
(38.05462768008707, 41.4988657488323]:0
(41.4988657488323, 45.254833995939045]:0
(45.254833995939045, 49.3507464130541]:0
(49.3507464130541, 53.817370576237735]:0
(53.817370576237735, 58.68825876509898]:0
(58.68825876509898, 63.99999999999998]:0
(63.99999999999998, 69.79249489057648]:0
(69.79249489057648, 76.10925536017416]:0
(76.10925536017416, 82.99773149766457]:0
(82.99773149766457, 90.50966799187806]:0
(90.50966799187806, 98.70149282610821]:0
(98.70149282610821, 107.63474115247547]:0
(107.63474115247547, 117.37651753019786]:0
(117.37651753019786, 127.99999999999997]:0
(127.99999999999997, 139.58498978115298]:0
(139.58498978115298, 152.21851072034832]:0
(152.21851072034832, 165.99546299532915]:0
(165.99546299532915, 181.01933598375612]:0
(181.01933598375612, 197.40298565221642]:0
(197.40298565221642, 215.26948230495097]:0
(215.26948230495097, 234.75303506039575]:0
(234.75303506039575, 255.99999999999994]:0
(255.99999999999994, 279.16997956230597]:0
(279.16997956230597, 304.4370214406964]:0
(304.4370214406964, 331.99092599065835]:0
(331.99092599065835, 362.0386719675123]:0
(362.0386719675123, 394.8059713044329]:0
(394.8059713044329, 430.5389646099016]:0
(430.5389646099016, 469.5060701207915]:0
(469.5060701207915, 511.99999999999994]:0
(511.99999999999994, 558.339959124612]:0
(558.339959124612, 608.8740428813928]:0
(608.8740428813928, 663.9818519813167]:0
(663.9818519813167, 724.0773439350246]:0
(724.0773439350246, 789.6119426088659]:0
(789.6119426088659, 861.0779292198033]:0
(861.0779292198033, 939.0121402415831]:0
(939.0121402415831, 1024]:0

Additional Context

No response

@reyang reyang added bug Something isn't working metrics labels May 21, 2024
@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working metrics pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package
Projects
None yet
Development

No branches or pull requests

1 participant