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

Metrics Console Exporter + Add last_updated_timestamp to metrics #192

Merged
merged 23 commits into from
Nov 5, 2019

Conversation

lzchen
Copy link
Contributor

@lzchen lzchen commented Sep 30, 2019

Implemented a console exporter for metrics, which simply prints metrics data to the console.
As well, added last_updated_timestamp field to metrics, certain exporters (Azure) need this field to be tracked.

@lzchen
Copy link
Contributor Author

lzchen commented Oct 1, 2019

[WIP] PR is a placeholder until export logic is spec'd out.

DO NOT MERGE.

@c24t c24t added the WIP Work in progress label Oct 1, 2019
@c24t
Copy link
Member

c24t commented Oct 1, 2019

[WIP] PR is a placeholder until export logic is spec'd out.

Are you still looking for comments here? You can mark the PR as draft if not.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to see unit tests, but can be convinced to approve if it's blocking other efforts.

"""


class ConsoleMetricsExporter(MetricsExporter):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd vote for the ability to add a format string here, similar to logging. e.g. I may want to emit things as JSON on the console.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd want to be consistent with the ConsoleSpanExporter for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. Random question, maybe for you and @Oberon00: any issues if I do add the ability to format output to both of these in a followup PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a problem with that. Go for it!

) -> "MetricsExportResult":
for metric_tuple in metric_tuples:
handle = metric_tuple[0].get_handle(metric_tuple[1])
print(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a way to pass the stream in the init? that way I could also choose to log in other streams, such as stderr.

Copy link
Contributor Author

@lzchen lzchen Oct 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thought as above: any issue with me adding this flexibility in a followup PR?

@lzchen
Copy link
Contributor Author

lzchen commented Oct 3, 2019

Follows SDK spec

@lzchen lzchen removed the WIP Work in progress label Oct 29, 2019
@lzchen
Copy link
Contributor Author

lzchen commented Oct 29, 2019

Reopening this. We can have the ConsoleExporter exist in the package with the simple export functionality called directly. Once we implement queues and workers for metrics, we can apply them to all metrics exporters.

@c24t
@toumorokoshi

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One blocking comment about the test, looks good otherwise!

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thanks!

from opentelemetry.sdk.metrics import Counter, Meter
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter

metrics.set_preferred_meter_implementation(lambda T: Meter())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great if the SDK meter implementation didn't need this additional lambda. Feel a little weird that this pattern will have to be added in every codebase that wants to use the standard meter implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I think as part of [#195], there will be an easier way to initialize these implementations (perhaps a default implementation is none is specified).

from enum import Enum
from typing import Sequence, Tuple

from .. import Metric
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random aside, but it feels weird to have to import from a parent module like this.

Maybe a style thing but I prefer importing from the submodule it is defined in:

from ..metric import Metric

prevents someone adding a cyclic dependency by importing a value in here into the top level module as well.

"""


class ConsoleMetricsExporter(MetricsExporter):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. Random question, maybe for you and @Oberon00: any issues if I do add the ability to format output to both of these in a followup PR?

) -> "MetricsExportResult":
for metric_tuple in metric_tuples:
handle = metric_tuple[0].get_handle(metric_tuple[1])
print(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thought as above: any issue with me adding this flexibility in a followup PR?

from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter


class TestConsoleMetricsExporter(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding tests!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we've made the decision to use pytest now, we no longer need to inherit from unittest.TestCase and can just use the general assert. I guess after #128 gets merged in we could discuss refactoring these.

@lzchen lzchen merged commit e5ba7e7 into open-telemetry:master Nov 5, 2019
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
* feat(zipkin-exporter): implement

* fix(zipkin): use time fns

* refactor(exporter-zipkin): linter fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants