census-instrumentation / opencensus-java

A stats collection and distributed tracing framework
https://opencensus.io
Apache License 2.0
674 stars 201 forks source link

How do I use MeasureDouble with Aggregation.Sum #2092

Closed mickykurniawan closed 2 years ago

mickykurniawan commented 2 years ago

Please answer these questions before submitting a bug report.

What version of OpenCensus are you using?

0.30.0

What JVM are you using (java -version)?

openjdk version "11.0.12" 2021-07-20 OpenJDK Runtime Environment Homebrew (build 11.0.12+0) OpenJDK 64-Bit Server VM Homebrew (build 11.0.12+0, mixed mode)

What did you do?

If possible, provide a recipe for reproducing the error.

// create MeasureDouble
public static final Measure.MeasureDouble M_TRANSACTION = Measure.MeasureDouble.create(
        "transaction",
        "Transaction measurement.",
        "1");

// register view with Aggregation.Sum
Stats.getViewManager().registerView(View.create(
       View.Name.create("my_view"),
        "My view description.",
        M_TRANSACTION,
       Aggregation.Sum.create(),
       List.of(KEY_TYPE)));

// put and record stats with amount
Stats.getStatsRecorder().newMeasureMap()
        .put(M_TRANSACTION, amount.doubleValue())
        .record(Tags.getTagger().currentBuilder()
                .putLocal(KEY_TYPE, TagValue.create(type))
                .build());

What did you expect to see?

I'm expecting to see sum of amount in GCP Metrics Explorer.

What did you see instead?

I see no metrics value being streamed at all.

Additional context

N/A

mickykurniawan commented 2 years ago

Nevermind it solved, turns out I need to recreate new View as I used existing View with MeasureLong