-
Notifications
You must be signed in to change notification settings - Fork 790
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
new classes ExportedMetric and Exporter #3134
new classes ExportedMetric and Exporter #3134
Conversation
|
||
namespace OpenTelemetry.Exporter | ||
{ | ||
public class InMemoryMetricExporter : BaseExporter<Metric> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a new exporter class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need an exporter that can perform the translation from Metric
to ExportedMetric
, and this new exporter does that.
The current InMemoryExporter
is generic and the exported Type must match the Type in the Batch.
opentelemetry-dotnet/src/OpenTelemetry.Exporter.InMemory/InMemoryExporter.cs
Lines 21 to 31 in d3c0c6e
public class InMemoryExporter<T> : BaseExporter<T> | |
where T : class | |
{ | |
private readonly ICollection<T> exportedItems; | |
public InMemoryExporter(ICollection<T> exportedItems) | |
{ | |
this.exportedItems = exportedItems; | |
} | |
public override ExportResult Export(in Batch<T> batch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, what's the real problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The real problem is that users cannot depend on a normally exported Metric
to be representative of the point in time it was exported.
Because the MetricApi reuses Metric
instances (by design), an exported Metric
can continue to be updated.
The Metric
class itself cannot be deep-copied, therefore we're introducing a new class which can be representative of the Metric
and a new Exporter to perform the translation.
This PR is what I believe to be the simplest solution to the specific problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something I don't like about this implementation is that it's a one-off class for a specific use case.
We could attempt to future the Exporter library by defining an InMemoryTranslationExporter<Tinput, Toutput>.
It's still a new class, but this would be a single new class to hopefully prevent an unknowable number of future one-off classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @reyang, circling back to this.
The problem I'm trying to address is that InMemoryExporter<T>
receives and exports the same type, in this case Metric
.
I want to introduce a new type ExportedMetric
which is our copy of the Metric
.
I don't see a way to accomplish this copy without introducing a new Exporter.
- Option 1: the simplest way to do this is a one-off exporter which performs this copy;
InMemoryMetricExporter
- Option 2: to prevent this and future one-off exporters, I could solve this with an
InMemoryTranslationExporter<Tinput, Toutput>
.
In this case, the caller must provide aFunc<Tinput, Toutput>
.
In either option, the caller would be the extension method AddInMemoryExporter
which I will contribute in a follow up PR along with test changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can InMemoryExporter be improved to cover the case, so you don't have to introduce a new class? (and if not, why)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I could introduce a means to provide an different behavior to the Export method.
I'm struggling with the best way to add this to the PublicApi and also explain customers would use it.
On this same thought, I'm investigating a different approach. I want to open a draft PR to get more feedback.
Codecov Report
@@ Coverage Diff @@
## main #3134 +/- ##
==========================================
- Coverage 84.74% 84.47% -0.27%
==========================================
Files 259 262 +3
Lines 9295 9327 +32
==========================================
+ Hits 7877 7879 +2
- Misses 1418 1448 +30
|
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
abandoning in favor of #3198 |
contributing to #2361
Changes
new class
ExportedMetric
. This class is used to deep-copyMetric
.new exporter. This will be RECOMMENDED for Metrics unit tests.
InMemoryMetricExporter
. This is a one-off Exporter that directly createsExporterMetric
.InMemoryTranslationExporter<Tinput, Toutput>
. This is a generic Exporter, and the caller MUST provide a Func to translate input/output types.new class
InMemoryMetricExporter
. This will be RECOMMENDED for unit tests.Modify
OpenTelemetry
project to expose internals to theInMemoryExporter
project. (aka "cheating")Modify
InMemoryExporter
removing classes now exposed fromOpenTelemetry
project.Next Steps
InMemoryExporterMetricsExtensions
and specific unit tests.Please provide a brief description of the changes here.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changesDiscussion
This design is based on examples shared by @CodeBlanch (https://github.com/open-telemetry/opentelemetry-dotnet/compare/main...CodeBlanch:inmemory-metrics-copy?expand=1).
The end goal is to enable the
InMemoryExporter
to deep-copyMetric
s.The
Metric
class itself cannot be copied. (For more details see #2361 (comment)).Instead an instance of
Metric
can be provided to the newExportedMetric
class which copies the minimum necessary members.This builds on the changes from #3113 to make copies of
MetricPoint
andHistogramBuckets
.Alternative
Currently the
InMemoryExporter<T>
will export the same Type that it receives in the exportedBatch<T>
Alternatively, we could introduce a new generic class that allows the caller to specify both the
Tinput, Toutput
and a provide translationFunc<Tinput, Toutput>
.alternative implementation example