From 162cc7b0f45d4c138f431cf32437e21c5155d78c Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 14 May 2020 14:34:48 -0600 Subject: [PATCH 01/15] Rename otcollector to opencensus --- .../CHANGELOG.md | 0 .../LICENSE | 0 .../MANIFEST.in | 0 .../README.rst | 8 ++++---- .../setup.cfg | 4 ++-- .../setup.py | 2 +- .../src/opentelemetry/ext/opencensus}/__init__.py | 4 ++-- .../ext/opencensus}/metrics_exporter/__init__.py | 2 +- .../ext/opencensus}/trace_exporter/__init__.py | 2 +- .../src/opentelemetry/ext/opencensus}/util.py | 6 +++--- .../src/opentelemetry/ext/opencensus}/version.py | 0 .../tests/__init__.py | 0 .../tests/test_otcollector_metrics_exporter.py | 4 ++-- .../tests/test_otcollector_trace_exporter.py | 6 +++--- tox.ini | 10 +++++----- 15 files changed, 24 insertions(+), 24 deletions(-) rename ext/{opentelemetry-ext-otcollector => opentelemetry-ext-opencensus}/CHANGELOG.md (100%) rename ext/{opentelemetry-ext-otcollector => opentelemetry-ext-opencensus}/LICENSE (100%) rename ext/{opentelemetry-ext-otcollector => opentelemetry-ext-opencensus}/MANIFEST.in (100%) rename ext/{opentelemetry-ext-otcollector => opentelemetry-ext-opencensus}/README.rst (64%) rename ext/{opentelemetry-ext-otcollector => opentelemetry-ext-opencensus}/setup.cfg (95%) rename ext/{opentelemetry-ext-otcollector => opentelemetry-ext-opencensus}/setup.py (91%) rename ext/{opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector => opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus}/__init__.py (94%) rename ext/{opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector => opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus}/metrics_exporter/__init__.py (99%) rename ext/{opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector => opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus}/trace_exporter/__init__.py (99%) rename ext/{opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector => opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus}/util.py (95%) rename ext/{opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector => opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus}/version.py (100%) rename ext/{opentelemetry-ext-otcollector => opentelemetry-ext-opencensus}/tests/__init__.py (100%) rename ext/{opentelemetry-ext-otcollector => opentelemetry-ext-opencensus}/tests/test_otcollector_metrics_exporter.py (98%) rename ext/{opentelemetry-ext-otcollector => opentelemetry-ext-opencensus}/tests/test_otcollector_trace_exporter.py (98%) diff --git a/ext/opentelemetry-ext-otcollector/CHANGELOG.md b/ext/opentelemetry-ext-opencensus/CHANGELOG.md similarity index 100% rename from ext/opentelemetry-ext-otcollector/CHANGELOG.md rename to ext/opentelemetry-ext-opencensus/CHANGELOG.md diff --git a/ext/opentelemetry-ext-otcollector/LICENSE b/ext/opentelemetry-ext-opencensus/LICENSE similarity index 100% rename from ext/opentelemetry-ext-otcollector/LICENSE rename to ext/opentelemetry-ext-opencensus/LICENSE diff --git a/ext/opentelemetry-ext-otcollector/MANIFEST.in b/ext/opentelemetry-ext-opencensus/MANIFEST.in similarity index 100% rename from ext/opentelemetry-ext-otcollector/MANIFEST.in rename to ext/opentelemetry-ext-opencensus/MANIFEST.in diff --git a/ext/opentelemetry-ext-otcollector/README.rst b/ext/opentelemetry-ext-opencensus/README.rst similarity index 64% rename from ext/opentelemetry-ext-otcollector/README.rst rename to ext/opentelemetry-ext-opencensus/README.rst index 916c64ffe6b..b4ad0e2a74d 100644 --- a/ext/opentelemetry-ext-otcollector/README.rst +++ b/ext/opentelemetry-ext-opencensus/README.rst @@ -3,8 +3,8 @@ OpenTelemetry Collector Exporter |pypi| -.. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-otcollector.svg - :target: https://pypi.org/project/opentelemetry-ext-otcollector/ +.. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-opencensus.svg + :target: https://pypi.org/project/opentelemetry-ext-opencensus/ This library allows to export data to `OpenTelemetry Collector`_ , currently using OpenCensus receiver in Collector side. @@ -13,12 +13,12 @@ Installation :: - pip install opentelemetry-ext-otcollector + pip install opentelemetry-ext-opencensus References ---------- -* `OpenTelemetry Collector Exporter `_ +* `OpenTelemetry Collector Exporter `_ * `OpenTelemetry Collector `_ * `OpenTelemetry `_ diff --git a/ext/opentelemetry-ext-otcollector/setup.cfg b/ext/opentelemetry-ext-opencensus/setup.cfg similarity index 95% rename from ext/opentelemetry-ext-otcollector/setup.cfg rename to ext/opentelemetry-ext-opencensus/setup.cfg index 8ffd4b6e4d1..18a51d8154a 100644 --- a/ext/opentelemetry-ext-otcollector/setup.cfg +++ b/ext/opentelemetry-ext-opencensus/setup.cfg @@ -13,13 +13,13 @@ # limitations under the License. # [metadata] -name = opentelemetry-ext-otcollector +name = opentelemetry-ext-opencensus description = OpenTelemetry Collector Exporter long_description = file: README.rst long_description_content_type = text/x-rst author = OpenTelemetry Authors author_email = cncf-opentelemetry-contributors@lists.cncf.io -url = https://github.com/open-telemetry/opentelemetry-python/tree/master/ext/opentelemetry-ext-otcollector +url = https://github.com/open-telemetry/opentelemetry-python/tree/master/ext/opentelemetry-ext-opencensus platforms = any license = Apache-2.0 classifiers = diff --git a/ext/opentelemetry-ext-otcollector/setup.py b/ext/opentelemetry-ext-opencensus/setup.py similarity index 91% rename from ext/opentelemetry-ext-otcollector/setup.py rename to ext/opentelemetry-ext-opencensus/setup.py index d5c2886ac5f..0c2ce254da6 100644 --- a/ext/opentelemetry-ext-otcollector/setup.py +++ b/ext/opentelemetry-ext-opencensus/setup.py @@ -17,7 +17,7 @@ BASE_DIR = os.path.dirname(__file__) VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "ext", "otcollector", "version.py" + BASE_DIR, "src", "opentelemetry", "ext", "opencensus", "version.py" ) PACKAGE_INFO = {} with open(VERSION_FILENAME) as f: diff --git a/ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/__init__.py b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py similarity index 94% rename from ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/__init__.py rename to ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py index ae5e2ac33f8..5eaeea51e98 100644 --- a/ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/__init__.py +++ b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py @@ -18,7 +18,7 @@ .. code:: python from opentelemetry import trace - from opentelemetry.ext.otcollector.trace_exporter import CollectorSpanExporter + from opentelemetry.ext.opencensus.trace_exporter import CollectorSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor @@ -50,7 +50,7 @@ .. code:: python from opentelemetry import metrics - from opentelemetry.ext.otcollector.metrics_exporter import CollectorMetricsExporter + from opentelemetry.ext.opencensus.metrics_exporter import CollectorMetricsExporter from opentelemetry.sdk.metrics import Counter, MeterProvider from opentelemetry.sdk.metrics.export.controller import PushController diff --git a/ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/metrics_exporter/__init__.py b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/metrics_exporter/__init__.py similarity index 99% rename from ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/metrics_exporter/__init__.py rename to ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/metrics_exporter/__init__.py index 3a43d9cc840..01e047b3c72 100644 --- a/ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/metrics_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/metrics_exporter/__init__.py @@ -24,7 +24,7 @@ ) from opencensus.proto.metrics.v1 import metrics_pb2 -import opentelemetry.ext.otcollector.util as utils +import opentelemetry.ext.opencensus.util as utils from opentelemetry.sdk.metrics import Counter, Metric from opentelemetry.sdk.metrics.export import ( MetricRecord, diff --git a/ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/trace_exporter/__init__.py b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/trace_exporter/__init__.py similarity index 99% rename from ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/trace_exporter/__init__.py rename to ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/trace_exporter/__init__.py index 914d97ec5a9..32fb065cad8 100644 --- a/ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/trace_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/trace_exporter/__init__.py @@ -24,7 +24,7 @@ ) from opencensus.proto.trace.v1 import trace_pb2 -import opentelemetry.ext.otcollector.util as utils +import opentelemetry.ext.opencensus.util as utils import opentelemetry.trace as trace_api from opentelemetry.sdk.trace import Span, SpanContext from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult diff --git a/ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/util.py b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/util.py similarity index 95% rename from ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/util.py rename to ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/util.py index e8717b0c8b0..0f90fcf0f4f 100644 --- a/ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/util.py +++ b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/util.py @@ -21,8 +21,8 @@ from opencensus.proto.agent.common.v1 import common_pb2 from opencensus.proto.trace.v1 import trace_pb2 -from opentelemetry.ext.otcollector.version import ( - __version__ as otcollector_exporter_version, +from opentelemetry.ext.opencensus.version import ( + __version__ as opencensus_exporter_version, ) from opentelemetry.trace import SpanKind @@ -96,7 +96,7 @@ def get_node(service_name, host_name): ), library_info=common_pb2.LibraryInfo( language=common_pb2.LibraryInfo.Language.Value("PYTHON"), - exporter_version=otcollector_exporter_version, + exporter_version=opencensus_exporter_version, core_library_version=OPENTELEMETRY_VERSION, ), service_info=common_pb2.ServiceInfo(name=service_name), diff --git a/ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/version.py b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/version.py similarity index 100% rename from ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/version.py rename to ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/version.py diff --git a/ext/opentelemetry-ext-otcollector/tests/__init__.py b/ext/opentelemetry-ext-opencensus/tests/__init__.py similarity index 100% rename from ext/opentelemetry-ext-otcollector/tests/__init__.py rename to ext/opentelemetry-ext-opencensus/tests/__init__.py diff --git a/ext/opentelemetry-ext-otcollector/tests/test_otcollector_metrics_exporter.py b/ext/opentelemetry-ext-opencensus/tests/test_otcollector_metrics_exporter.py similarity index 98% rename from ext/opentelemetry-ext-otcollector/tests/test_otcollector_metrics_exporter.py rename to ext/opentelemetry-ext-opencensus/tests/test_otcollector_metrics_exporter.py index 7dcbf452e1e..1d45d85abd4 100644 --- a/ext/opentelemetry-ext-otcollector/tests/test_otcollector_metrics_exporter.py +++ b/ext/opentelemetry-ext-opencensus/tests/test_otcollector_metrics_exporter.py @@ -20,7 +20,7 @@ from opencensus.proto.metrics.v1 import metrics_pb2 from opentelemetry import metrics -from opentelemetry.ext.otcollector import metrics_exporter +from opentelemetry.ext.opencensus import metrics_exporter from opentelemetry.sdk.metrics import ( Counter, Measure, @@ -47,7 +47,7 @@ def setUpClass(cls): def test_constructor(self): mock_get_node = mock.Mock() patch = mock.patch( - "opentelemetry.ext.otcollector.util.get_node", + "opentelemetry.ext.opencensus.util.get_node", side_effect=mock_get_node, ) service_name = "testServiceName" diff --git a/ext/opentelemetry-ext-otcollector/tests/test_otcollector_trace_exporter.py b/ext/opentelemetry-ext-opencensus/tests/test_otcollector_trace_exporter.py similarity index 98% rename from ext/opentelemetry-ext-otcollector/tests/test_otcollector_trace_exporter.py rename to ext/opentelemetry-ext-opencensus/tests/test_otcollector_trace_exporter.py index 97d276af403..4a5a174161f 100644 --- a/ext/opentelemetry-ext-otcollector/tests/test_otcollector_trace_exporter.py +++ b/ext/opentelemetry-ext-opencensus/tests/test_otcollector_trace_exporter.py @@ -19,9 +19,9 @@ from google.protobuf.timestamp_pb2 import Timestamp from opencensus.proto.trace.v1 import trace_pb2 -import opentelemetry.ext.otcollector.util as utils +import opentelemetry.ext.opencensus.util as utils from opentelemetry import trace as trace_api -from opentelemetry.ext.otcollector.trace_exporter import ( +from opentelemetry.ext.opencensus.trace_exporter import ( CollectorSpanExporter, translate_to_collector, ) @@ -35,7 +35,7 @@ class TestCollectorSpanExporter(unittest.TestCase): def test_constructor(self): mock_get_node = mock.Mock() patch = mock.patch( - "opentelemetry.ext.otcollector.util.get_node", + "opentelemetry.ext.opencensus.util.get_node", side_effect=mock_get_node, ) service_name = "testServiceName" diff --git a/tox.ini b/tox.ini index 5742e717d7a..0910da22e44 100644 --- a/tox.ini +++ b/tox.ini @@ -59,9 +59,9 @@ envlist = py3{4,5,6,7,8}-test-ext-mysql pypy3-test-ext-mysql - ; opentelemetry-ext-otcollector - py3{4,5,6,7,8}-test-ext-otcollector - ; ext-otcollector intentionally excluded from pypy3 + ; opentelemetry-ext-opencensus + py3{4,5,6,7,8}-test-ext-opencensus + ; ext-opencensus intentionally excluded from pypy3 ; opentelemetry-ext-prometheus py3{4,5,6,7,8}-test-ext-prometheus @@ -143,7 +143,7 @@ changedir = test-ext-dbapi: ext/opentelemetry-ext-dbapi/tests test-ext-django: ext/opentelemetry-ext-django/tests test-ext-mysql: ext/opentelemetry-ext-mysql/tests - test-ext-otcollector: ext/opentelemetry-ext-otcollector/tests + test-ext-opencensus: ext/opentelemetry-ext-opencensus/tests test-ext-prometheus: ext/opentelemetry-ext-prometheus/tests test-ext-pymongo: ext/opentelemetry-ext-pymongo/tests test-ext-psycopg2: ext/opentelemetry-ext-psycopg2/tests @@ -184,7 +184,7 @@ commands_pre = mysql: pip install {toxinidir}/opentelemetry-auto-instrumentation {toxinidir}/ext/opentelemetry-ext-dbapi {toxinidir}/ext/opentelemetry-ext-mysql[test] - otcollector: pip install {toxinidir}/ext/opentelemetry-ext-otcollector + opencensus: pip install {toxinidir}/ext/opentelemetry-ext-opencensus prometheus: pip install {toxinidir}/ext/opentelemetry-ext-prometheus From ec691881cd2f261722f83db236d7582310469b39 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Sat, 16 May 2020 19:44:34 -0600 Subject: [PATCH 02/15] Update ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py Co-authored-by: alrex --- .../src/opentelemetry/ext/opencensus/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py index 5eaeea51e98..8912f54af59 100644 --- a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py +++ b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py @@ -18,7 +18,7 @@ .. code:: python from opentelemetry import trace - from opentelemetry.ext.opencensus.trace_exporter import CollectorSpanExporter + from opentelemetry.ext.opencensus.trace_exporter import CollectorSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor From 6f6713495e721b4f3c37b89b31a015bc868a45a2 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Sat, 16 May 2020 19:59:32 -0600 Subject: [PATCH 03/15] Add some renaming --- .../src/opentelemetry/ext/opencensus/__init__.py | 5 +++-- .../ext/opencensus/metrics_exporter/__init__.py | 8 ++++---- .../ext/opencensus/trace_exporter/__init__.py | 14 ++++++-------- .../tests/test_otcollector_metrics_exporter.py | 4 ++-- .../tests/test_otcollector_trace_exporter.py | 6 +++--- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py index 8912f54af59..c2b040e920b 100644 --- a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py +++ b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py @@ -13,12 +13,13 @@ # limitations under the License. """ -The **OpenTelemetry Collector Exporter** allows to export OpenTelemetry traces to OpenTelemetry Collector. +The **OpenCensus Collector Exporter** allows to export OpenTelemetry traces to +OpenCensus Collector. .. code:: python from opentelemetry import trace - from opentelemetry.ext.opencensus.trace_exporter import CollectorSpanExporter + from opentelemetry.ext.opencensus.trace_exporter import OpenCensusCollectorSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor diff --git a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/metrics_exporter/__init__.py b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/metrics_exporter/__init__.py index 01e047b3c72..e5c2c7841b2 100644 --- a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/metrics_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/metrics_exporter/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""OpenTelemetry Collector Metrics Exporter.""" +"""OpenCensus Collector Metrics Exporter.""" import logging from typing import Sequence @@ -39,11 +39,11 @@ # pylint: disable=no-member -class CollectorMetricsExporter(MetricsExporter): - """OpenTelemetry Collector metrics exporter. +class OpenCensusCollectorMetricsExporter(MetricsExporter): + """OpenCensus Collector metrics exporter. Args: - endpoint: OpenTelemetry Collector OpenCensus receiver endpoint. + endpoint: OpenCensus Collector receiver endpoint. service_name: Name of Collector service. host_name: Host name. client: MetricsService client stub. diff --git a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/trace_exporter/__init__.py b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/trace_exporter/__init__.py index 32fb065cad8..49847f4b363 100644 --- a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/trace_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/trace_exporter/__init__.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""OpenTelemetry Collector Exporter.""" +"""OpenCensus Collector Span Exporter.""" import logging -from typing import Optional, Sequence +from typing import Sequence import grpc from opencensus.proto.agent.trace.v1 import ( @@ -25,10 +25,8 @@ from opencensus.proto.trace.v1 import trace_pb2 import opentelemetry.ext.opencensus.util as utils -import opentelemetry.trace as trace_api -from opentelemetry.sdk.trace import Span, SpanContext +from opentelemetry.sdk.trace import Span from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult -from opentelemetry.trace import SpanKind, TraceState DEFAULT_ENDPOINT = "localhost:55678" @@ -36,11 +34,11 @@ # pylint: disable=no-member -class CollectorSpanExporter(SpanExporter): - """OpenTelemetry Collector span exporter. +class OpenCensusCollectorSpanExporter(SpanExporter): + """OpenCensus Collector span exporter. Args: - endpoint: OpenTelemetry Collector OpenCensus receiver endpoint. + endpoint: OpenCensus Collector receiver endpoint. service_name: Name of Collector service. host_name: Host name. client: TraceService client stub. diff --git a/ext/opentelemetry-ext-opencensus/tests/test_otcollector_metrics_exporter.py b/ext/opentelemetry-ext-opencensus/tests/test_otcollector_metrics_exporter.py index 1d45d85abd4..a9a0ef73c62 100644 --- a/ext/opentelemetry-ext-opencensus/tests/test_otcollector_metrics_exporter.py +++ b/ext/opentelemetry-ext-opencensus/tests/test_otcollector_metrics_exporter.py @@ -55,7 +55,7 @@ def test_constructor(self): client = grpc.insecure_channel("") endpoint = "testEndpoint" with patch: - exporter = metrics_exporter.CollectorMetricsExporter( + exporter = metrics_exporter.OpenCensusCollectorMetricsExporter( service_name=service_name, host_name=host_name, endpoint=endpoint, @@ -115,7 +115,7 @@ def test_export(self): mock_export = mock.MagicMock() mock_client.Export = mock_export host_name = "testHostName" - collector_exporter = metrics_exporter.CollectorMetricsExporter( + collector_exporter = metrics_exporter.OpenCensusCollectorMetricsExporter( client=mock_client, host_name=host_name ) test_metric = self._meter.create_metric( diff --git a/ext/opentelemetry-ext-opencensus/tests/test_otcollector_trace_exporter.py b/ext/opentelemetry-ext-opencensus/tests/test_otcollector_trace_exporter.py index 4a5a174161f..6b3c788fd1e 100644 --- a/ext/opentelemetry-ext-opencensus/tests/test_otcollector_trace_exporter.py +++ b/ext/opentelemetry-ext-opencensus/tests/test_otcollector_trace_exporter.py @@ -22,7 +22,7 @@ import opentelemetry.ext.opencensus.util as utils from opentelemetry import trace as trace_api from opentelemetry.ext.opencensus.trace_exporter import ( - CollectorSpanExporter, + OpenCensusCollectorSpanExporter, translate_to_collector, ) from opentelemetry.sdk import trace @@ -43,7 +43,7 @@ def test_constructor(self): client = grpc.insecure_channel("") endpoint = "testEndpoint" with patch: - exporter = CollectorSpanExporter( + exporter = OpenCensusCollectorSpanExporter( service_name=service_name, host_name=host_name, endpoint=endpoint, @@ -289,7 +289,7 @@ def test_export(self): mock_export = mock.MagicMock() mock_client.Export = mock_export host_name = "testHostName" - collector_exporter = CollectorSpanExporter( + collector_exporter = OpenCensusCollectorSpanExporter( client=mock_client, host_name=host_name ) From 1a6bc81ec7cd009ea6250591e249fa19a5e2b73b Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Sun, 17 May 2020 11:18:57 -0600 Subject: [PATCH 04/15] Fix docs WIP --- docs/examples/opencensus-metrics/README.rst | 51 +++++++++++++++++++ docs/examples/opencensus-metrics/collector.py | 47 +++++++++++++++++ .../docker/collector-config.yaml | 18 +++++++ .../docker/docker-compose.yaml | 19 +++++++ .../opencensus-metrics/docker/prometheus.yaml | 5 ++ docs/examples/opencensus-tracer/README.rst | 50 ++++++++++++++++++ docs/examples/opencensus-tracer/collector.py | 36 +++++++++++++ .../docker/collector-config.yaml | 19 +++++++ .../docker/docker-compose.yaml | 20 ++++++++ docs/ext/opencensus/opencensus.rst | 7 +++ docs/ext/otcollector/otcollector.rst | 7 --- 11 files changed, 272 insertions(+), 7 deletions(-) create mode 100644 docs/examples/opencensus-metrics/README.rst create mode 100644 docs/examples/opencensus-metrics/collector.py create mode 100644 docs/examples/opencensus-metrics/docker/collector-config.yaml create mode 100644 docs/examples/opencensus-metrics/docker/docker-compose.yaml create mode 100644 docs/examples/opencensus-metrics/docker/prometheus.yaml create mode 100644 docs/examples/opencensus-tracer/README.rst create mode 100644 docs/examples/opencensus-tracer/collector.py create mode 100644 docs/examples/opencensus-tracer/docker/collector-config.yaml create mode 100644 docs/examples/opencensus-tracer/docker/docker-compose.yaml create mode 100644 docs/ext/opencensus/opencensus.rst delete mode 100644 docs/ext/otcollector/otcollector.rst diff --git a/docs/examples/opencensus-metrics/README.rst b/docs/examples/opencensus-metrics/README.rst new file mode 100644 index 00000000000..a7e196f6298 --- /dev/null +++ b/docs/examples/opencensus-metrics/README.rst @@ -0,0 +1,51 @@ +OT Collector Metrics Exporter Example +===================================== + +This example shows how to export metrics to the OT collector. + +The source files of this example are available :scm_web:`here `. + +Installation +------------ + +.. code-block:: sh + + pip install opentelemetry-api + pip install opentelemetry-sdk + pip install opentelemetry-ext-opencensus + +Run the Example +--------------- + +Before running the example, it's necessary to run the OpenTelemetry collector +and Prometheus. The :scm_web:`docker ` +folder contains the a docker-compose template with the configuration of those +services. + +.. code-block:: sh + + pip install docker-compose + cd docker + docker-compose up + + +Now, the example can be executed: + +.. code-block:: sh + + python collector.py + + +The metrics are available in the Prometheus dashboard at http://localhost:9090/graph, +look for the "requests" metric on the list. + +Useful links +------------ + +- OpenTelemetry_ +- OpenCensus_ +- :doc:`../../api/metrics` +- :doc:`../../ext/opencensus/opencensus` + +.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/ +.. _OpenCensus: https://github.com/open-telemetry/open-collector diff --git a/docs/examples/opencensus-metrics/collector.py b/docs/examples/opencensus-metrics/collector.py new file mode 100644 index 00000000000..48472bd8402 --- /dev/null +++ b/docs/examples/opencensus-metrics/collector.py @@ -0,0 +1,47 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +""" +This example shows how to export metrics to the OT collector. +""" + +from opentelemetry import metrics +from opentelemetry.ext.opencensus.metrics_exporter import ( + CollectorMetricsExporter, +) +from opentelemetry.sdk.metrics import Counter, MeterProvider +from opentelemetry.sdk.metrics.export.controller import PushController + +exporter = CollectorMetricsExporter( + service_name="basic-service", endpoint="localhost:55678" +) + +metrics.set_meter_provider(MeterProvider()) +meter = metrics.get_meter(__name__) +controller = PushController(meter, exporter, 5) + +requests_counter = meter.create_metric( + name="requests", + description="number of requests", + unit="1", + value_type=int, + metric_type=Counter, + label_keys=("environment",), +) + +staging_labels = {"environment": "staging"} +requests_counter.add(25, staging_labels) + +print("Metrics are available now at http://localhost:9090/graph") +input("Press any key to exit...") diff --git a/docs/examples/opencensus-metrics/docker/collector-config.yaml b/docs/examples/opencensus-metrics/docker/collector-config.yaml new file mode 100644 index 00000000000..78f685d208e --- /dev/null +++ b/docs/examples/opencensus-metrics/docker/collector-config.yaml @@ -0,0 +1,18 @@ +receivers: + opencensus: + endpoint: "0.0.0.0:55678" + +exporters: + prometheus: + endpoint: "0.0.0.0:8889" + logging: {} + +processors: + batch: + queued_retry: + +service: + pipelines: + metrics: + receivers: [opencensus] + exporters: [logging, prometheus] diff --git a/docs/examples/opencensus-metrics/docker/docker-compose.yaml b/docs/examples/opencensus-metrics/docker/docker-compose.yaml new file mode 100644 index 00000000000..d12a0a4f18c --- /dev/null +++ b/docs/examples/opencensus-metrics/docker/docker-compose.yaml @@ -0,0 +1,19 @@ +version: "2" +services: + + otel-collector: + image: omnition/opentelemetry-collector-contrib:latest + command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"] + volumes: + - ./collector-config.yaml:/conf/collector-config.yaml + ports: + - "8889:8889" # Prometheus exporter metrics + - "55678:55678" # OpenCensus receiver + + prometheus: + container_name: prometheus + image: prom/prometheus:latest + volumes: + - ./prometheus.yaml:/etc/prometheus/prometheus.yml + ports: + - "9090:9090" diff --git a/docs/examples/opencensus-metrics/docker/prometheus.yaml b/docs/examples/opencensus-metrics/docker/prometheus.yaml new file mode 100644 index 00000000000..4eb23572314 --- /dev/null +++ b/docs/examples/opencensus-metrics/docker/prometheus.yaml @@ -0,0 +1,5 @@ +scrape_configs: + - job_name: 'otel-collector' + scrape_interval: 5s + static_configs: + - targets: ['otel-collector:8889'] diff --git a/docs/examples/opencensus-tracer/README.rst b/docs/examples/opencensus-tracer/README.rst new file mode 100644 index 00000000000..d82803df407 --- /dev/null +++ b/docs/examples/opencensus-tracer/README.rst @@ -0,0 +1,50 @@ +OT Collector Tracer Exporter Example +==================================== + +This example shows how to export traces to the OT collector. + +The source files of this example are available :scm_web:`here `. + +Installation +------------ + +.. code-block:: sh + + pip install opentelemetry-api + pip install opentelemetry-sdk + pip install opentelemetry-ext-otcollector + +Run the Example +--------------- + +Before running the example, it's necessary to run the OpenTelemetry collector +and Jaeger. The :scm_web:`docker ` +folder contains the a docker-compose template with the configuration of those +services. + +.. code-block:: sh + + pip install docker-compose + cd docker + docker-compose up + + +Now, the example can be executed: + +.. code-block:: sh + + python collector.py + + +The traces are available in the Jaeger UI at http://localhost:16686/. + +Useful links +------------ + +- OpenTelemetry_ +- OTCollector_ +- :doc:`../../api/trace` +- :doc:`../../ext/otcollector/otcollector` + +.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/ +.. _OTCollector: https://github.com/open-telemetry/opentelemetry-collector \ No newline at end of file diff --git a/docs/examples/opencensus-tracer/collector.py b/docs/examples/opencensus-tracer/collector.py new file mode 100644 index 00000000000..d92fa52f3a4 --- /dev/null +++ b/docs/examples/opencensus-tracer/collector.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from opentelemetry import trace +from opentelemetry.ext.otcollector.trace_exporter import CollectorSpanExporter +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import BatchExportSpanProcessor + +exporter = CollectorSpanExporter( + service_name="basic-service", endpoint="localhost:55678" +) + +trace.set_tracer_provider(TracerProvider()) +tracer = trace.get_tracer(__name__) +span_processor = BatchExportSpanProcessor(exporter) + +trace.get_tracer_provider().add_span_processor(span_processor) +with tracer.start_as_current_span("foo"): + with tracer.start_as_current_span("bar"): + with tracer.start_as_current_span("baz"): + print("Hello world from OpenTelemetry Python!") diff --git a/docs/examples/opencensus-tracer/docker/collector-config.yaml b/docs/examples/opencensus-tracer/docker/collector-config.yaml new file mode 100644 index 00000000000..bcf59c58024 --- /dev/null +++ b/docs/examples/opencensus-tracer/docker/collector-config.yaml @@ -0,0 +1,19 @@ +receivers: + opencensus: + endpoint: "0.0.0.0:55678" + +exporters: + jaeger_grpc: + endpoint: jaeger-all-in-one:14250 + logging: {} + +processors: + batch: + queued_retry: + +service: + pipelines: + traces: + receivers: [opencensus] + exporters: [jaeger_grpc, logging] + processors: [batch, queued_retry] diff --git a/docs/examples/opencensus-tracer/docker/docker-compose.yaml b/docs/examples/opencensus-tracer/docker/docker-compose.yaml new file mode 100644 index 00000000000..71d7ccd5a11 --- /dev/null +++ b/docs/examples/opencensus-tracer/docker/docker-compose.yaml @@ -0,0 +1,20 @@ +version: "2" +services: + + # Collector + collector: + image: omnition/opentelemetry-collector-contrib:latest + command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"] + volumes: + - ./collector-config.yaml:/conf/collector-config.yaml + ports: + - "55678:55678" + + jaeger-all-in-one: + image: jaegertracing/all-in-one:latest + ports: + - "16686:16686" + - "6831:6831/udp" + - "6832:6832/udp" + - "14268" + - "14250" diff --git a/docs/ext/opencensus/opencensus.rst b/docs/ext/opencensus/opencensus.rst new file mode 100644 index 00000000000..e3fca7d56bc --- /dev/null +++ b/docs/ext/opencensus/opencensus.rst @@ -0,0 +1,7 @@ +OpenCensus Collector Exporter +============================= + +.. automodule:: opentelemetry.ext.opencensus + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/ext/otcollector/otcollector.rst b/docs/ext/otcollector/otcollector.rst deleted file mode 100644 index 286aed6c082..00000000000 --- a/docs/ext/otcollector/otcollector.rst +++ /dev/null @@ -1,7 +0,0 @@ -OpenTelemetry Collector Exporter -================================ - -.. automodule:: opentelemetry.ext.otcollector - :members: - :undoc-members: - :show-inheritance: From 0dfc785c65d77d486d0e8fae82c9162f5d121257 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 18 May 2020 09:14:13 -0600 Subject: [PATCH 05/15] Rename to opencensusexporter --- .../CHANGELOG.md | 0 .../LICENSE | 0 .../MANIFEST.in | 0 .../README.rst | 8 ++++---- .../setup.cfg | 6 +++--- .../setup.py | 2 +- .../opentelemetry/ext/opencensusexporter}/__init__.py | 4 ++-- .../opencensusexporter}/metrics_exporter/__init__.py | 6 +++--- .../ext/opencensusexporter}/trace_exporter/__init__.py | 6 +++--- .../src/opentelemetry/ext/opencensusexporter}/util.py | 10 +++++----- .../opentelemetry/ext/opencensusexporter}/version.py | 0 .../tests/__init__.py | 0 .../tests/test_otcollector_metrics_exporter.py | 6 +++--- .../tests/test_otcollector_trace_exporter.py | 8 ++++---- 14 files changed, 28 insertions(+), 28 deletions(-) rename ext/{opentelemetry-ext-opencensus => opentelemetry-ext-opencensusexporter}/CHANGELOG.md (100%) rename ext/{opentelemetry-ext-opencensus => opentelemetry-ext-opencensusexporter}/LICENSE (100%) rename ext/{opentelemetry-ext-opencensus => opentelemetry-ext-opencensusexporter}/MANIFEST.in (100%) rename ext/{opentelemetry-ext-opencensus => opentelemetry-ext-opencensusexporter}/README.rst (78%) rename ext/{opentelemetry-ext-opencensus => opentelemetry-ext-opencensusexporter}/setup.cfg (91%) rename ext/{opentelemetry-ext-opencensus => opentelemetry-ext-opencensusexporter}/setup.py (91%) rename ext/{opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus => opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter}/__init__.py (93%) rename ext/{opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus => opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter}/metrics_exporter/__init__.py (96%) rename ext/{opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus => opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter}/trace_exporter/__init__.py (97%) rename ext/{opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus => opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter}/util.py (90%) rename ext/{opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus => opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter}/version.py (100%) rename ext/{opentelemetry-ext-opencensus => opentelemetry-ext-opencensusexporter}/tests/__init__.py (100%) rename ext/{opentelemetry-ext-opencensus => opentelemetry-ext-opencensusexporter}/tests/test_otcollector_metrics_exporter.py (97%) rename ext/{opentelemetry-ext-opencensus => opentelemetry-ext-opencensusexporter}/tests/test_otcollector_trace_exporter.py (97%) diff --git a/ext/opentelemetry-ext-opencensus/CHANGELOG.md b/ext/opentelemetry-ext-opencensusexporter/CHANGELOG.md similarity index 100% rename from ext/opentelemetry-ext-opencensus/CHANGELOG.md rename to ext/opentelemetry-ext-opencensusexporter/CHANGELOG.md diff --git a/ext/opentelemetry-ext-opencensus/LICENSE b/ext/opentelemetry-ext-opencensusexporter/LICENSE similarity index 100% rename from ext/opentelemetry-ext-opencensus/LICENSE rename to ext/opentelemetry-ext-opencensusexporter/LICENSE diff --git a/ext/opentelemetry-ext-opencensus/MANIFEST.in b/ext/opentelemetry-ext-opencensusexporter/MANIFEST.in similarity index 100% rename from ext/opentelemetry-ext-opencensus/MANIFEST.in rename to ext/opentelemetry-ext-opencensusexporter/MANIFEST.in diff --git a/ext/opentelemetry-ext-opencensus/README.rst b/ext/opentelemetry-ext-opencensusexporter/README.rst similarity index 78% rename from ext/opentelemetry-ext-opencensus/README.rst rename to ext/opentelemetry-ext-opencensusexporter/README.rst index b4ad0e2a74d..2bbb6376abc 100644 --- a/ext/opentelemetry-ext-opencensus/README.rst +++ b/ext/opentelemetry-ext-opencensusexporter/README.rst @@ -3,8 +3,8 @@ OpenTelemetry Collector Exporter |pypi| -.. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-opencensus.svg - :target: https://pypi.org/project/opentelemetry-ext-opencensus/ +.. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-opencensusexporter.svg + :target: https://pypi.org/project/opentelemetry-ext-opencensusexporter/ This library allows to export data to `OpenTelemetry Collector`_ , currently using OpenCensus receiver in Collector side. @@ -13,12 +13,12 @@ Installation :: - pip install opentelemetry-ext-opencensus + pip install opentelemetry-ext-opencensusexporter References ---------- -* `OpenTelemetry Collector Exporter `_ +* `OpenTelemetry Collector Exporter `_ * `OpenTelemetry Collector `_ * `OpenTelemetry `_ diff --git a/ext/opentelemetry-ext-opencensus/setup.cfg b/ext/opentelemetry-ext-opencensusexporter/setup.cfg similarity index 91% rename from ext/opentelemetry-ext-opencensus/setup.cfg rename to ext/opentelemetry-ext-opencensusexporter/setup.cfg index 18a51d8154a..ef0bceff628 100644 --- a/ext/opentelemetry-ext-opencensus/setup.cfg +++ b/ext/opentelemetry-ext-opencensusexporter/setup.cfg @@ -13,13 +13,13 @@ # limitations under the License. # [metadata] -name = opentelemetry-ext-opencensus +name = opentelemetry-ext-opencensusexporter description = OpenTelemetry Collector Exporter long_description = file: README.rst long_description_content_type = text/x-rst author = OpenTelemetry Authors author_email = cncf-opentelemetry-contributors@lists.cncf.io -url = https://github.com/open-telemetry/opentelemetry-python/tree/master/ext/opentelemetry-ext-opencensus +url = https://github.com/open-telemetry/opentelemetry-python/tree/master/ext/opentelemetry-ext-opencensusexporter platforms = any license = Apache-2.0 classifiers = @@ -41,7 +41,7 @@ package_dir= packages=find_namespace: install_requires = grpcio >= 1.0.0, < 2.0.0 - opencensus-proto >= 0.1.0, < 1.0.0 + opencensusexporter-proto >= 0.1.0, < 1.0.0 opentelemetry-api == 0.8.dev0 opentelemetry-sdk == 0.8.dev0 protobuf >= 3.8.0 diff --git a/ext/opentelemetry-ext-opencensus/setup.py b/ext/opentelemetry-ext-opencensusexporter/setup.py similarity index 91% rename from ext/opentelemetry-ext-opencensus/setup.py rename to ext/opentelemetry-ext-opencensusexporter/setup.py index 0c2ce254da6..dfb8fd82bff 100644 --- a/ext/opentelemetry-ext-opencensus/setup.py +++ b/ext/opentelemetry-ext-opencensusexporter/setup.py @@ -17,7 +17,7 @@ BASE_DIR = os.path.dirname(__file__) VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "ext", "opencensus", "version.py" + BASE_DIR, "src", "opentelemetry", "ext", "opencensusexporter", "version.py" ) PACKAGE_INFO = {} with open(VERSION_FILENAME) as f: diff --git a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/__init__.py similarity index 93% rename from ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py rename to ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/__init__.py index c2b040e920b..658d2b346d8 100644 --- a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/__init__.py @@ -19,7 +19,7 @@ .. code:: python from opentelemetry import trace - from opentelemetry.ext.opencensus.trace_exporter import OpenCensusCollectorSpanExporter + from opentelemetry.ext.opencensusexporter.trace_exporter import OpenCensusCollectorSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor @@ -51,7 +51,7 @@ .. code:: python from opentelemetry import metrics - from opentelemetry.ext.opencensus.metrics_exporter import CollectorMetricsExporter + from opentelemetry.ext.opencensusexporter.metrics_exporter import CollectorMetricsExporter from opentelemetry.sdk.metrics import Counter, MeterProvider from opentelemetry.sdk.metrics.export.controller import PushController diff --git a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/metrics_exporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py similarity index 96% rename from ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/metrics_exporter/__init__.py rename to ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py index e5c2c7841b2..4a3305e8176 100644 --- a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/metrics_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py @@ -18,13 +18,13 @@ from typing import Sequence import grpc -from opencensus.proto.agent.metrics.v1 import ( +from opencensusexporter.proto.agent.metrics.v1 import ( metrics_service_pb2, metrics_service_pb2_grpc, ) -from opencensus.proto.metrics.v1 import metrics_pb2 +from opencensusexporter.proto.metrics.v1 import metrics_pb2 -import opentelemetry.ext.opencensus.util as utils +import opentelemetry.ext.opencensusexporter.util as utils from opentelemetry.sdk.metrics import Counter, Metric from opentelemetry.sdk.metrics.export import ( MetricRecord, diff --git a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/trace_exporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py similarity index 97% rename from ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/trace_exporter/__init__.py rename to ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py index 49847f4b363..5f6f9809b0f 100644 --- a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/trace_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py @@ -18,13 +18,13 @@ from typing import Sequence import grpc -from opencensus.proto.agent.trace.v1 import ( +from opencensusexporter.proto.agent.trace.v1 import ( trace_service_pb2, trace_service_pb2_grpc, ) -from opencensus.proto.trace.v1 import trace_pb2 +from opencensusexporter.proto.trace.v1 import trace_pb2 -import opentelemetry.ext.opencensus.util as utils +import opentelemetry.ext.opencensusexporter.util as utils from opentelemetry.sdk.trace import Span from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult diff --git a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/util.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/util.py similarity index 90% rename from ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/util.py rename to ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/util.py index 0f90fcf0f4f..cd82c1c1512 100644 --- a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/util.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/util.py @@ -18,11 +18,11 @@ import pkg_resources from google.protobuf.timestamp_pb2 import Timestamp -from opencensus.proto.agent.common.v1 import common_pb2 -from opencensus.proto.trace.v1 import trace_pb2 +from opencensusexporter.proto.agent.common.v1 import common_pb2 +from opencensusexporter.proto.trace.v1 import trace_pb2 -from opentelemetry.ext.opencensus.version import ( - __version__ as opencensus_exporter_version, +from opentelemetry.ext.opencensusexporter.version import ( + __version__ as opencensusexporter_exporter_version, ) from opentelemetry.trace import SpanKind @@ -96,7 +96,7 @@ def get_node(service_name, host_name): ), library_info=common_pb2.LibraryInfo( language=common_pb2.LibraryInfo.Language.Value("PYTHON"), - exporter_version=opencensus_exporter_version, + exporter_version=opencensusexporter_exporter_version, core_library_version=OPENTELEMETRY_VERSION, ), service_info=common_pb2.ServiceInfo(name=service_name), diff --git a/ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/version.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/version.py similarity index 100% rename from ext/opentelemetry-ext-opencensus/src/opentelemetry/ext/opencensus/version.py rename to ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/version.py diff --git a/ext/opentelemetry-ext-opencensus/tests/__init__.py b/ext/opentelemetry-ext-opencensusexporter/tests/__init__.py similarity index 100% rename from ext/opentelemetry-ext-opencensus/tests/__init__.py rename to ext/opentelemetry-ext-opencensusexporter/tests/__init__.py diff --git a/ext/opentelemetry-ext-opencensus/tests/test_otcollector_metrics_exporter.py b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py similarity index 97% rename from ext/opentelemetry-ext-opencensus/tests/test_otcollector_metrics_exporter.py rename to ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py index a9a0ef73c62..9a3b3cd3e5f 100644 --- a/ext/opentelemetry-ext-opencensus/tests/test_otcollector_metrics_exporter.py +++ b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py @@ -17,10 +17,10 @@ import grpc from google.protobuf.timestamp_pb2 import Timestamp -from opencensus.proto.metrics.v1 import metrics_pb2 +from opencensusexporter.proto.metrics.v1 import metrics_pb2 from opentelemetry import metrics -from opentelemetry.ext.opencensus import metrics_exporter +from opentelemetry.ext.opencensusexporter import metrics_exporter from opentelemetry.sdk.metrics import ( Counter, Measure, @@ -47,7 +47,7 @@ def setUpClass(cls): def test_constructor(self): mock_get_node = mock.Mock() patch = mock.patch( - "opentelemetry.ext.opencensus.util.get_node", + "opentelemetry.ext.opencensusexporter.util.get_node", side_effect=mock_get_node, ) service_name = "testServiceName" diff --git a/ext/opentelemetry-ext-opencensus/tests/test_otcollector_trace_exporter.py b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py similarity index 97% rename from ext/opentelemetry-ext-opencensus/tests/test_otcollector_trace_exporter.py rename to ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py index 6b3c788fd1e..1bcc30f50ed 100644 --- a/ext/opentelemetry-ext-opencensus/tests/test_otcollector_trace_exporter.py +++ b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py @@ -17,11 +17,11 @@ import grpc from google.protobuf.timestamp_pb2 import Timestamp -from opencensus.proto.trace.v1 import trace_pb2 +from opencensusexporter.proto.trace.v1 import trace_pb2 -import opentelemetry.ext.opencensus.util as utils +import opentelemetry.ext.opencensusexporter.util as utils from opentelemetry import trace as trace_api -from opentelemetry.ext.opencensus.trace_exporter import ( +from opentelemetry.ext.opencensusexporter.trace_exporter import ( OpenCensusCollectorSpanExporter, translate_to_collector, ) @@ -35,7 +35,7 @@ class TestCollectorSpanExporter(unittest.TestCase): def test_constructor(self): mock_get_node = mock.Mock() patch = mock.patch( - "opentelemetry.ext.opencensus.util.get_node", + "opentelemetry.ext.opencensusexporter.util.get_node", side_effect=mock_get_node, ) service_name = "testServiceName" From 3df73ab48de7adee481f708764fe1c80d5e7f16c Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 18 May 2020 09:17:24 -0600 Subject: [PATCH 06/15] More renaming --- .../README.rst | 0 .../collector.py | 0 .../docker/collector-config.yaml | 0 .../docker/docker-compose.yaml | 0 .../docker/prometheus.yaml | 0 .../README.rst | 21 ++++++++++--------- .../collector.py | 0 .../docker/collector-config.yaml | 0 .../docker/docker-compose.yaml | 0 docs/ext/opencensus/opencensus.rst | 7 ------- .../opencensusexporter/opencensusexporter.rst | 7 +++++++ 11 files changed, 18 insertions(+), 17 deletions(-) rename docs/examples/{opencensus-metrics => opencensusexporter-metrics}/README.rst (100%) rename docs/examples/{opencensus-metrics => opencensusexporter-metrics}/collector.py (100%) rename docs/examples/{opencensus-metrics => opencensusexporter-metrics}/docker/collector-config.yaml (100%) rename docs/examples/{opencensus-metrics => opencensusexporter-metrics}/docker/docker-compose.yaml (100%) rename docs/examples/{opencensus-metrics => opencensusexporter-metrics}/docker/prometheus.yaml (100%) rename docs/examples/{opencensus-tracer => opencensusexporter-tracer}/README.rst (52%) rename docs/examples/{opencensus-tracer => opencensusexporter-tracer}/collector.py (100%) rename docs/examples/{opencensus-tracer => opencensusexporter-tracer}/docker/collector-config.yaml (100%) rename docs/examples/{opencensus-tracer => opencensusexporter-tracer}/docker/docker-compose.yaml (100%) delete mode 100644 docs/ext/opencensus/opencensus.rst create mode 100644 docs/ext/opencensusexporter/opencensusexporter.rst diff --git a/docs/examples/opencensus-metrics/README.rst b/docs/examples/opencensusexporter-metrics/README.rst similarity index 100% rename from docs/examples/opencensus-metrics/README.rst rename to docs/examples/opencensusexporter-metrics/README.rst diff --git a/docs/examples/opencensus-metrics/collector.py b/docs/examples/opencensusexporter-metrics/collector.py similarity index 100% rename from docs/examples/opencensus-metrics/collector.py rename to docs/examples/opencensusexporter-metrics/collector.py diff --git a/docs/examples/opencensus-metrics/docker/collector-config.yaml b/docs/examples/opencensusexporter-metrics/docker/collector-config.yaml similarity index 100% rename from docs/examples/opencensus-metrics/docker/collector-config.yaml rename to docs/examples/opencensusexporter-metrics/docker/collector-config.yaml diff --git a/docs/examples/opencensus-metrics/docker/docker-compose.yaml b/docs/examples/opencensusexporter-metrics/docker/docker-compose.yaml similarity index 100% rename from docs/examples/opencensus-metrics/docker/docker-compose.yaml rename to docs/examples/opencensusexporter-metrics/docker/docker-compose.yaml diff --git a/docs/examples/opencensus-metrics/docker/prometheus.yaml b/docs/examples/opencensusexporter-metrics/docker/prometheus.yaml similarity index 100% rename from docs/examples/opencensus-metrics/docker/prometheus.yaml rename to docs/examples/opencensusexporter-metrics/docker/prometheus.yaml diff --git a/docs/examples/opencensus-tracer/README.rst b/docs/examples/opencensusexporter-tracer/README.rst similarity index 52% rename from docs/examples/opencensus-tracer/README.rst rename to docs/examples/opencensusexporter-tracer/README.rst index d82803df407..2527385f29f 100644 --- a/docs/examples/opencensus-tracer/README.rst +++ b/docs/examples/opencensusexporter-tracer/README.rst @@ -1,9 +1,10 @@ -OT Collector Tracer Exporter Example -==================================== +OpenTelemetry Collector Tracer OpenCensus Exporter Example +========================================================== -This example shows how to export traces to the OT collector. +This example shows how to use the OpenCensus Exporter to export traces to the +OpenTelemetry collector. -The source files of this example are available :scm_web:`here `. +The source files of this example are available :scm_web:`here `. Installation ------------ @@ -12,14 +13,14 @@ Installation pip install opentelemetry-api pip install opentelemetry-sdk - pip install opentelemetry-ext-otcollector + pip install opentelemetry-ext-opencensusexporter Run the Example --------------- Before running the example, it's necessary to run the OpenTelemetry collector -and Jaeger. The :scm_web:`docker ` -folder contains the a docker-compose template with the configuration of those +and Jaeger. The :scm_web:`docker ` +folder contains a ``docker-compose`` template with the configuration of those services. .. code-block:: sh @@ -42,9 +43,9 @@ Useful links ------------ - OpenTelemetry_ -- OTCollector_ +- `OpenTelemetry Collector`_ - :doc:`../../api/trace` -- :doc:`../../ext/otcollector/otcollector` +- :doc:`../../ext/opencensusexporter/opencensusexporter` .. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/ -.. _OTCollector: https://github.com/open-telemetry/opentelemetry-collector \ No newline at end of file +.. _OpenTelemetry Collector: https://github.com/open-telemetry/opentelemetry-collector diff --git a/docs/examples/opencensus-tracer/collector.py b/docs/examples/opencensusexporter-tracer/collector.py similarity index 100% rename from docs/examples/opencensus-tracer/collector.py rename to docs/examples/opencensusexporter-tracer/collector.py diff --git a/docs/examples/opencensus-tracer/docker/collector-config.yaml b/docs/examples/opencensusexporter-tracer/docker/collector-config.yaml similarity index 100% rename from docs/examples/opencensus-tracer/docker/collector-config.yaml rename to docs/examples/opencensusexporter-tracer/docker/collector-config.yaml diff --git a/docs/examples/opencensus-tracer/docker/docker-compose.yaml b/docs/examples/opencensusexporter-tracer/docker/docker-compose.yaml similarity index 100% rename from docs/examples/opencensus-tracer/docker/docker-compose.yaml rename to docs/examples/opencensusexporter-tracer/docker/docker-compose.yaml diff --git a/docs/ext/opencensus/opencensus.rst b/docs/ext/opencensus/opencensus.rst deleted file mode 100644 index e3fca7d56bc..00000000000 --- a/docs/ext/opencensus/opencensus.rst +++ /dev/null @@ -1,7 +0,0 @@ -OpenCensus Collector Exporter -============================= - -.. automodule:: opentelemetry.ext.opencensus - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/ext/opencensusexporter/opencensusexporter.rst b/docs/ext/opencensusexporter/opencensusexporter.rst new file mode 100644 index 00000000000..07b9a855582 --- /dev/null +++ b/docs/ext/opencensusexporter/opencensusexporter.rst @@ -0,0 +1,7 @@ +OpenCensus Exporter +=================== + +.. automodule:: opentelemetry.ext.opencensusexporter + :members: + :undoc-members: + :show-inheritance: From 6502111a354adf699456618a8a26302732d1f795 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 18 May 2020 09:23:58 -0600 Subject: [PATCH 07/15] More renaming --- .../README.rst | 11 ++++++----- .../collector.py | 0 .../docker/collector-config.yaml | 0 .../docker/docker-compose.yaml | 0 .../docker/prometheus.yaml | 0 .../README.rst | 0 .../collector.py | 0 .../docker/collector-config.yaml | 0 .../docker/docker-compose.yaml | 0 9 files changed, 6 insertions(+), 5 deletions(-) rename docs/examples/{opencensusexporter-metrics => opencensus-exporter-metrics}/README.rst (76%) rename docs/examples/{opencensusexporter-metrics => opencensus-exporter-metrics}/collector.py (100%) rename docs/examples/{opencensusexporter-metrics => opencensus-exporter-metrics}/docker/collector-config.yaml (100%) rename docs/examples/{opencensusexporter-metrics => opencensus-exporter-metrics}/docker/docker-compose.yaml (100%) rename docs/examples/{opencensusexporter-metrics => opencensus-exporter-metrics}/docker/prometheus.yaml (100%) rename docs/examples/{opencensusexporter-tracer => opencensus-exporter-tracer}/README.rst (100%) rename docs/examples/{opencensusexporter-tracer => opencensus-exporter-tracer}/collector.py (100%) rename docs/examples/{opencensusexporter-tracer => opencensus-exporter-tracer}/docker/collector-config.yaml (100%) rename docs/examples/{opencensusexporter-tracer => opencensus-exporter-tracer}/docker/docker-compose.yaml (100%) diff --git a/docs/examples/opencensusexporter-metrics/README.rst b/docs/examples/opencensus-exporter-metrics/README.rst similarity index 76% rename from docs/examples/opencensusexporter-metrics/README.rst rename to docs/examples/opencensus-exporter-metrics/README.rst index a7e196f6298..b64a74e14be 100644 --- a/docs/examples/opencensusexporter-metrics/README.rst +++ b/docs/examples/opencensus-exporter-metrics/README.rst @@ -1,9 +1,10 @@ -OT Collector Metrics Exporter Example -===================================== +OpenTelemetry Collector Metrics OpenCensus Exporter Example +=========================================================== -This example shows how to export metrics to the OT collector. +This example shows how to use the OpenCensus Exporter to export metrics to +the OpenTelemetry collector. -The source files of this example are available :scm_web:`here `. +The source files of this example are available :scm_web:`here `. Installation ------------ @@ -12,7 +13,7 @@ Installation pip install opentelemetry-api pip install opentelemetry-sdk - pip install opentelemetry-ext-opencensus + pip install opentelemetry-ext-opencensusexporter Run the Example --------------- diff --git a/docs/examples/opencensusexporter-metrics/collector.py b/docs/examples/opencensus-exporter-metrics/collector.py similarity index 100% rename from docs/examples/opencensusexporter-metrics/collector.py rename to docs/examples/opencensus-exporter-metrics/collector.py diff --git a/docs/examples/opencensusexporter-metrics/docker/collector-config.yaml b/docs/examples/opencensus-exporter-metrics/docker/collector-config.yaml similarity index 100% rename from docs/examples/opencensusexporter-metrics/docker/collector-config.yaml rename to docs/examples/opencensus-exporter-metrics/docker/collector-config.yaml diff --git a/docs/examples/opencensusexporter-metrics/docker/docker-compose.yaml b/docs/examples/opencensus-exporter-metrics/docker/docker-compose.yaml similarity index 100% rename from docs/examples/opencensusexporter-metrics/docker/docker-compose.yaml rename to docs/examples/opencensus-exporter-metrics/docker/docker-compose.yaml diff --git a/docs/examples/opencensusexporter-metrics/docker/prometheus.yaml b/docs/examples/opencensus-exporter-metrics/docker/prometheus.yaml similarity index 100% rename from docs/examples/opencensusexporter-metrics/docker/prometheus.yaml rename to docs/examples/opencensus-exporter-metrics/docker/prometheus.yaml diff --git a/docs/examples/opencensusexporter-tracer/README.rst b/docs/examples/opencensus-exporter-tracer/README.rst similarity index 100% rename from docs/examples/opencensusexporter-tracer/README.rst rename to docs/examples/opencensus-exporter-tracer/README.rst diff --git a/docs/examples/opencensusexporter-tracer/collector.py b/docs/examples/opencensus-exporter-tracer/collector.py similarity index 100% rename from docs/examples/opencensusexporter-tracer/collector.py rename to docs/examples/opencensus-exporter-tracer/collector.py diff --git a/docs/examples/opencensusexporter-tracer/docker/collector-config.yaml b/docs/examples/opencensus-exporter-tracer/docker/collector-config.yaml similarity index 100% rename from docs/examples/opencensusexporter-tracer/docker/collector-config.yaml rename to docs/examples/opencensus-exporter-tracer/docker/collector-config.yaml diff --git a/docs/examples/opencensusexporter-tracer/docker/docker-compose.yaml b/docs/examples/opencensus-exporter-tracer/docker/docker-compose.yaml similarity index 100% rename from docs/examples/opencensusexporter-tracer/docker/docker-compose.yaml rename to docs/examples/opencensus-exporter-tracer/docker/docker-compose.yaml From 30a9ff42de332fe137c7df585cb21bfd1d747cf5 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 18 May 2020 10:56:14 -0600 Subject: [PATCH 08/15] More renaming --- .../opencensus-exporter-metrics/README.rst | 12 +-- .../opencensus-exporter-tracer/README.rst | 2 +- .../README.rst | 8 +- .../setup.cfg | 4 +- .../ext/opencensusexporter/__init__.py | 73 +------------------ .../metrics_exporter/__init__.py | 5 +- .../trace_exporter/__init__.py | 4 +- .../test_otcollector_metrics_exporter.py | 4 +- .../tests/test_otcollector_trace_exporter.py | 6 +- tox.ini | 10 +-- 10 files changed, 29 insertions(+), 99 deletions(-) diff --git a/docs/examples/opencensus-exporter-metrics/README.rst b/docs/examples/opencensus-exporter-metrics/README.rst index b64a74e14be..30961e061df 100644 --- a/docs/examples/opencensus-exporter-metrics/README.rst +++ b/docs/examples/opencensus-exporter-metrics/README.rst @@ -4,7 +4,7 @@ OpenTelemetry Collector Metrics OpenCensus Exporter Example This example shows how to use the OpenCensus Exporter to export metrics to the OpenTelemetry collector. -The source files of this example are available :scm_web:`here `. +The source files of this example are available :scm_web:`here `. Installation ------------ @@ -19,7 +19,7 @@ Run the Example --------------- Before running the example, it's necessary to run the OpenTelemetry collector -and Prometheus. The :scm_web:`docker ` +and Prometheus. The :scm_web:`docker ` folder contains the a docker-compose template with the configuration of those services. @@ -44,9 +44,9 @@ Useful links ------------ - OpenTelemetry_ -- OpenCensus_ -- :doc:`../../api/metrics` -- :doc:`../../ext/opencensus/opencensus` +- `OpenTelemetry Collector`_ +- :doc:`../../api/trace` +- :doc:`../../ext/opencensusexporter/opencensusexporter` .. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/ -.. _OpenCensus: https://github.com/open-telemetry/open-collector +.. _OpenTelemetry Collector: https://github.com/open-telemetry/opentelemetry-collector diff --git a/docs/examples/opencensus-exporter-tracer/README.rst b/docs/examples/opencensus-exporter-tracer/README.rst index 2527385f29f..00199943086 100644 --- a/docs/examples/opencensus-exporter-tracer/README.rst +++ b/docs/examples/opencensus-exporter-tracer/README.rst @@ -19,7 +19,7 @@ Run the Example --------------- Before running the example, it's necessary to run the OpenTelemetry collector -and Jaeger. The :scm_web:`docker ` +and Jaeger. The :scm_web:`docker ` folder contains a ``docker-compose`` template with the configuration of those services. diff --git a/ext/opentelemetry-ext-opencensusexporter/README.rst b/ext/opentelemetry-ext-opencensusexporter/README.rst index 2bbb6376abc..75563053d10 100644 --- a/ext/opentelemetry-ext-opencensusexporter/README.rst +++ b/ext/opentelemetry-ext-opencensusexporter/README.rst @@ -1,12 +1,12 @@ -OpenTelemetry Collector Exporter -================================ +OpenCensus Exporter +=================== |pypi| .. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-opencensusexporter.svg :target: https://pypi.org/project/opentelemetry-ext-opencensusexporter/ -This library allows to export data to `OpenTelemetry Collector`_ , currently using OpenCensus receiver in Collector side. +This library allows to export traces and metrics using OpenCensus. Installation ------------ @@ -19,6 +19,6 @@ Installation References ---------- -* `OpenTelemetry Collector Exporter `_ +* `OpenCensus Exporter `_ * `OpenTelemetry Collector `_ * `OpenTelemetry `_ diff --git a/ext/opentelemetry-ext-opencensusexporter/setup.cfg b/ext/opentelemetry-ext-opencensusexporter/setup.cfg index ef0bceff628..850368fd0dd 100644 --- a/ext/opentelemetry-ext-opencensusexporter/setup.cfg +++ b/ext/opentelemetry-ext-opencensusexporter/setup.cfg @@ -14,7 +14,7 @@ # [metadata] name = opentelemetry-ext-opencensusexporter -description = OpenTelemetry Collector Exporter +description = OpenCensus Exporter long_description = file: README.rst long_description_content_type = text/x-rst author = OpenTelemetry Authors @@ -41,7 +41,7 @@ package_dir= packages=find_namespace: install_requires = grpcio >= 1.0.0, < 2.0.0 - opencensusexporter-proto >= 0.1.0, < 1.0.0 + opencensus-proto >= 0.1.0, < 1.0.0 opentelemetry-api == 0.8.dev0 opentelemetry-sdk == 0.8.dev0 protobuf >= 3.8.0 diff --git a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/__init__.py index 658d2b346d8..27aae238f45 100644 --- a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/__init__.py @@ -13,75 +13,6 @@ # limitations under the License. """ -The **OpenCensus Collector Exporter** allows to export OpenTelemetry traces to -OpenCensus Collector. - -.. code:: python - - from opentelemetry import trace - from opentelemetry.ext.opencensusexporter.trace_exporter import OpenCensusCollectorSpanExporter - from opentelemetry.sdk.trace import TracerProvider - from opentelemetry.sdk.trace.export import BatchExportSpanProcessor - - - # create a CollectorSpanExporter - collector_exporter = CollectorSpanExporter( - # optional: - # endpoint="myCollectorUrl:55678", - # service_name="test_service", - # host_name="machine/container name", - ) - - # Create a BatchExportSpanProcessor and add the exporter to it - span_processor = BatchExportSpanProcessor(collector_exporter) - - # Configure the tracer to use the collector exporter - tracer_provider = TracerProvider() - tracer_provider.add_span_processor(span_processor) - tracer = TracerProvider().get_tracer(__name__) - - with tracer.start_as_current_span("foo"): - print("Hello world!") - -Metrics Usage -------------- - -The **OpenTelemetry Collector Exporter** allows to export OpenTelemetry metrics to OpenTelemetry Collector. - -.. code:: python - - from opentelemetry import metrics - from opentelemetry.ext.opencensusexporter.metrics_exporter import CollectorMetricsExporter - from opentelemetry.sdk.metrics import Counter, MeterProvider - from opentelemetry.sdk.metrics.export.controller import PushController - - - # create a CollectorMetricsExporter - collector_exporter = CollectorMetricsExporter( - # optional: - # endpoint="myCollectorUrl:55678", - # service_name="test_service", - # host_name="machine/container name", - ) - - # Meter is responsible for creating and recording metrics - metrics.set_meter_provider(MeterProvider()) - meter = metrics.get_meter(__name__) - # controller collects metrics created from meter and exports it via the - # exporter every interval - controller = PushController(meter, collector_exporter, 5) - counter = meter.create_metric( - "requests", - "number of requests", - "requests", - int, - Counter, - ("environment",), - ) - # Labels are used to identify key-values that are associated with a specific - # metric that you want to record. These are useful for pre-aggregation and can - # be used to store custom dimensions pertaining to a metric - labels = {"environment": "staging"} - - counter.add(25, labels) +The **OpenCensus Exporter** allows to export traces and metrics using +OpenCensus. """ diff --git a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py index 4a3305e8176..8eb6065a76e 100644 --- a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py @@ -30,7 +30,6 @@ MetricRecord, MetricsExporter, MetricsExportResult, - aggregate, ) DEFAULT_ENDPOINT = "localhost:55678" @@ -39,8 +38,8 @@ # pylint: disable=no-member -class OpenCensusCollectorMetricsExporter(MetricsExporter): - """OpenCensus Collector metrics exporter. +class OpenCensusMetricsExporter(MetricsExporter): + """OpenCensus metrics exporter. Args: endpoint: OpenCensus Collector receiver endpoint. diff --git a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py index 5f6f9809b0f..a5f40f8f05d 100644 --- a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""OpenCensus Collector Span Exporter.""" +"""OpenCensus Span Exporter.""" import logging from typing import Sequence @@ -34,7 +34,7 @@ # pylint: disable=no-member -class OpenCensusCollectorSpanExporter(SpanExporter): +class OpenCensusSpanExporter(SpanExporter): """OpenCensus Collector span exporter. Args: diff --git a/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py index 9a3b3cd3e5f..63fe5f27a1f 100644 --- a/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py +++ b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py @@ -55,7 +55,7 @@ def test_constructor(self): client = grpc.insecure_channel("") endpoint = "testEndpoint" with patch: - exporter = metrics_exporter.OpenCensusCollectorMetricsExporter( + exporter = metrics_exporter.OpenCensusMetricsExporter( service_name=service_name, host_name=host_name, endpoint=endpoint, @@ -115,7 +115,7 @@ def test_export(self): mock_export = mock.MagicMock() mock_client.Export = mock_export host_name = "testHostName" - collector_exporter = metrics_exporter.OpenCensusCollectorMetricsExporter( + collector_exporter = metrics_exporter.OpenCensusMetricsExporter( client=mock_client, host_name=host_name ) test_metric = self._meter.create_metric( diff --git a/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py index 1bcc30f50ed..30a7be1e689 100644 --- a/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py +++ b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py @@ -22,7 +22,7 @@ import opentelemetry.ext.opencensusexporter.util as utils from opentelemetry import trace as trace_api from opentelemetry.ext.opencensusexporter.trace_exporter import ( - OpenCensusCollectorSpanExporter, + OpenCensusSpanExporter, translate_to_collector, ) from opentelemetry.sdk import trace @@ -43,7 +43,7 @@ def test_constructor(self): client = grpc.insecure_channel("") endpoint = "testEndpoint" with patch: - exporter = OpenCensusCollectorSpanExporter( + exporter = OpenCensusSpanExporter( service_name=service_name, host_name=host_name, endpoint=endpoint, @@ -289,7 +289,7 @@ def test_export(self): mock_export = mock.MagicMock() mock_client.Export = mock_export host_name = "testHostName" - collector_exporter = OpenCensusCollectorSpanExporter( + collector_exporter = OpenCensusSpanExporter( client=mock_client, host_name=host_name ) diff --git a/tox.ini b/tox.ini index 0910da22e44..948fae77d8b 100644 --- a/tox.ini +++ b/tox.ini @@ -59,9 +59,9 @@ envlist = py3{4,5,6,7,8}-test-ext-mysql pypy3-test-ext-mysql - ; opentelemetry-ext-opencensus - py3{4,5,6,7,8}-test-ext-opencensus - ; ext-opencensus intentionally excluded from pypy3 + ; opentelemetry-ext-opencensusexporter + py3{4,5,6,7,8}-test-ext-opencensusexporter + ; ext-opencensusexporter intentionally excluded from pypy3 ; opentelemetry-ext-prometheus py3{4,5,6,7,8}-test-ext-prometheus @@ -143,7 +143,7 @@ changedir = test-ext-dbapi: ext/opentelemetry-ext-dbapi/tests test-ext-django: ext/opentelemetry-ext-django/tests test-ext-mysql: ext/opentelemetry-ext-mysql/tests - test-ext-opencensus: ext/opentelemetry-ext-opencensus/tests + test-ext-opencensusexporter: ext/opentelemetry-ext-opencensusexporter/tests test-ext-prometheus: ext/opentelemetry-ext-prometheus/tests test-ext-pymongo: ext/opentelemetry-ext-pymongo/tests test-ext-psycopg2: ext/opentelemetry-ext-psycopg2/tests @@ -184,7 +184,7 @@ commands_pre = mysql: pip install {toxinidir}/opentelemetry-auto-instrumentation {toxinidir}/ext/opentelemetry-ext-dbapi {toxinidir}/ext/opentelemetry-ext-mysql[test] - opencensus: pip install {toxinidir}/ext/opentelemetry-ext-opencensus + opencensusexporter: pip install {toxinidir}/ext/opentelemetry-ext-opencensusexporter prometheus: pip install {toxinidir}/ext/opentelemetry-ext-prometheus From bea27acf18dd9541fcb53bb55bc536eed52c8813 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 18 May 2020 11:10:14 -0600 Subject: [PATCH 09/15] More renaming --- .../ext/opencensusexporter/metrics_exporter/__init__.py | 4 ++-- .../ext/opencensusexporter/trace_exporter/__init__.py | 4 ++-- .../src/opentelemetry/ext/opencensusexporter/util.py | 4 ++-- .../tests/test_otcollector_metrics_exporter.py | 2 +- .../tests/test_otcollector_trace_exporter.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py index 8eb6065a76e..faa0788c7f1 100644 --- a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py @@ -18,11 +18,11 @@ from typing import Sequence import grpc -from opencensusexporter.proto.agent.metrics.v1 import ( +from opencensus.proto.agent.metrics.v1 import ( metrics_service_pb2, metrics_service_pb2_grpc, ) -from opencensusexporter.proto.metrics.v1 import metrics_pb2 +from opencensus.proto.metrics.v1 import metrics_pb2 import opentelemetry.ext.opencensusexporter.util as utils from opentelemetry.sdk.metrics import Counter, Metric diff --git a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py index a5f40f8f05d..adadef1666f 100644 --- a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py @@ -18,11 +18,11 @@ from typing import Sequence import grpc -from opencensusexporter.proto.agent.trace.v1 import ( +from opencensus.proto.agent.trace.v1 import ( trace_service_pb2, trace_service_pb2_grpc, ) -from opencensusexporter.proto.trace.v1 import trace_pb2 +from opencensus.proto.trace.v1 import trace_pb2 import opentelemetry.ext.opencensusexporter.util as utils from opentelemetry.sdk.trace import Span diff --git a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/util.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/util.py index cd82c1c1512..88ff6258f7d 100644 --- a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/util.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/util.py @@ -18,8 +18,8 @@ import pkg_resources from google.protobuf.timestamp_pb2 import Timestamp -from opencensusexporter.proto.agent.common.v1 import common_pb2 -from opencensusexporter.proto.trace.v1 import trace_pb2 +from opencensus.proto.agent.common.v1 import common_pb2 +from opencensus.proto.trace.v1 import trace_pb2 from opentelemetry.ext.opencensusexporter.version import ( __version__ as opencensusexporter_exporter_version, diff --git a/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py index 63fe5f27a1f..63ea28cd935 100644 --- a/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py +++ b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py @@ -17,7 +17,7 @@ import grpc from google.protobuf.timestamp_pb2 import Timestamp -from opencensusexporter.proto.metrics.v1 import metrics_pb2 +from opencensus.proto.metrics.v1 import metrics_pb2 from opentelemetry import metrics from opentelemetry.ext.opencensusexporter import metrics_exporter diff --git a/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py index 30a7be1e689..0801d6d0c1b 100644 --- a/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py +++ b/ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_trace_exporter.py @@ -17,7 +17,7 @@ import grpc from google.protobuf.timestamp_pb2 import Timestamp -from opencensusexporter.proto.trace.v1 import trace_pb2 +from opencensus.proto.trace.v1 import trace_pb2 import opentelemetry.ext.opencensusexporter.util as utils from opentelemetry import trace as trace_api From 257c060f416bc4acc58f8d25b0c49f46e710b0ce Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 18 May 2020 12:20:07 -0600 Subject: [PATCH 10/15] Update examples --- docs/examples/opencensus-exporter-metrics/collector.py | 6 +++--- docs/examples/opencensus-exporter-tracer/collector.py | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/examples/opencensus-exporter-metrics/collector.py b/docs/examples/opencensus-exporter-metrics/collector.py index 48472bd8402..89dabd12eab 100644 --- a/docs/examples/opencensus-exporter-metrics/collector.py +++ b/docs/examples/opencensus-exporter-metrics/collector.py @@ -17,13 +17,13 @@ """ from opentelemetry import metrics -from opentelemetry.ext.opencensus.metrics_exporter import ( - CollectorMetricsExporter, +from opentelemetry.ext.opencensusexporter.metrics_exporter import ( + OpenCensusMetricsExporter, ) from opentelemetry.sdk.metrics import Counter, MeterProvider from opentelemetry.sdk.metrics.export.controller import PushController -exporter = CollectorMetricsExporter( +exporter = OpenCensusMetricsExporter( service_name="basic-service", endpoint="localhost:55678" ) diff --git a/docs/examples/opencensus-exporter-tracer/collector.py b/docs/examples/opencensus-exporter-tracer/collector.py index d92fa52f3a4..5bae9e0be06 100644 --- a/docs/examples/opencensus-exporter-tracer/collector.py +++ b/docs/examples/opencensus-exporter-tracer/collector.py @@ -14,14 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - from opentelemetry import trace -from opentelemetry.ext.otcollector.trace_exporter import CollectorSpanExporter +from opentelemetry.ext.opencensusexporter.trace_exporter import OpenCensusSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor -exporter = CollectorSpanExporter( +exporter = OpenCensusSpanExporter( service_name="basic-service", endpoint="localhost:55678" ) From b6b4144da513b3175aaefa07a11081f0202d3f2b Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 19 May 2020 08:53:42 -0600 Subject: [PATCH 11/15] Add docker test for opencensus --- .../tests/docker-compose.yml | 7 +++- .../test_opencensusexporter_functional.py | 42 +++++++++++++++++++ tox.ini | 3 +- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py diff --git a/ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml b/ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml index f996db077e8..ffe66284995 100644 --- a/ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml +++ b/ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml @@ -38,4 +38,9 @@ services: - "5778:5778" - "16686:16686" - "14268:14268" - - "9411:9411" + - "9411:9411" + otopencensus: + image: omnition/opencensus-collector:0.1.6 + ports: + - "8888:8888" + - "55678:55678" diff --git a/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py b/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py new file mode 100644 index 00000000000..fa6318aa804 --- /dev/null +++ b/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py @@ -0,0 +1,42 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from opentelemetry.ext.opencensusexporter.metrics_exporter import ( + OpenCensusMetricsExporter, +) +from opentelemetry.sdk.trace.export import BatchExportSpanProcessor +from opentelemetry import trace +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.test.test_base import TestBase + + +class TestOpenCensusExporter(TestBase): + + def setUp(self): + super().setUp() + + exporter = OpenCensusMetricsExporter( + service_name="basic-service", endpoint="localhost:55678" + ) + trace.set_tracer_provider(TracerProvider()) + self.tracer = trace.get_tracer(__name__) + span_processor = BatchExportSpanProcessor(exporter) + + trace.get_tracer_provider().add_span_processor(span_processor) + + def test_long_command(self): + with self.tracer.start_as_current_span("foo"): + with self.tracer.start_as_current_span("bar"): + with self.tracer.start_as_current_span("baz"): + print("Hello world from OpenTelemetry Python!") diff --git a/tox.ini b/tox.ini index 948fae77d8b..8f44a47edf6 100644 --- a/tox.ini +++ b/tox.ini @@ -310,7 +310,8 @@ commands_pre = -e {toxinidir}/ext/opentelemetry-ext-pymongo \ -e {toxinidir}/ext/opentelemetry-ext-pymysql \ -e {toxinidir}/ext/opentelemetry-ext-sqlalchemy \ - -e {toxinidir}/ext/opentelemetry-ext-redis + -e {toxinidir}/ext/opentelemetry-ext-redis \ + -e {toxinidir}/ext/opentelemetry-ext-opencensusexporter docker-compose up -d python check_availability.py commands = From 450186442399a6e54762cccf148fe2204c090fe9 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 19 May 2020 17:58:17 -0600 Subject: [PATCH 12/15] All docker tests passing --- .../tests/docker-compose.yml | 3 +- .../test_opencensusexporter_functional.py | 102 ++++++++++++++++-- .../metrics_exporter/__init__.py | 8 +- .../trace_exporter/__init__.py | 6 +- 4 files changed, 96 insertions(+), 23 deletions(-) diff --git a/ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml b/ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml index ffe66284995..bbb005a02ef 100644 --- a/ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml +++ b/ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml @@ -40,7 +40,8 @@ services: - "14268:14268" - "9411:9411" otopencensus: - image: omnition/opencensus-collector:0.1.6 + image: omnition/opencensus-collector:0.1.11 + command: --logging-exporter DEBUG ports: - "8888:8888" - "55678:55678" diff --git a/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py b/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py index fa6318aa804..57a5c500bf6 100644 --- a/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py +++ b/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py @@ -12,31 +12,113 @@ # See the License for the specific language governing permissions and # limitations under the License. +from opentelemetry.ext.opencensusexporter.trace_exporter import ( + OpenCensusSpanExporter, +) from opentelemetry.ext.opencensusexporter.metrics_exporter import ( OpenCensusMetricsExporter, ) -from opentelemetry.sdk.trace.export import BatchExportSpanProcessor -from opentelemetry import trace +from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor +from opentelemetry.sdk.metrics import Counter, MeterProvider +from opentelemetry import trace, metrics from opentelemetry.sdk.trace import TracerProvider from opentelemetry.test.test_base import TestBase +from opentelemetry.context import attach, detach, set_value +from opentelemetry.sdk.metrics.export.controller import PushController +from time import sleep + + +class ExportStatusSpanProcessor(SimpleExportSpanProcessor): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.export_status = [] + + def on_end(self, span): + token = attach(set_value("suppress_instrumentation", True)) + self.export_status.append(self.span_exporter.export((span,))) + detach(token) + + +class ExportStatusMetricController(PushController): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.export_status = [] -class TestOpenCensusExporter(TestBase): + def run(self): + while not self.finished.wait(self.interval): + self.tick() + + def tick(self): + # Collect all of the meter's metrics to be exported + self.meter.collect() + token = attach(set_value("suppress_instrumentation", True)) + # Export the given metrics in the batcher + self.export_status.append( + self.exporter.export(self.meter.batcher.checkpoint_set()) + ) + detach(token) + # Perform post-exporting logic based on batcher configuration + self.meter.batcher.finished_collection() + + +class TestOpenCensusSpanExporter(TestBase): def setUp(self): super().setUp() - exporter = OpenCensusMetricsExporter( - service_name="basic-service", endpoint="localhost:55678" - ) trace.set_tracer_provider(TracerProvider()) self.tracer = trace.get_tracer(__name__) - span_processor = BatchExportSpanProcessor(exporter) + self.span_processor = ExportStatusSpanProcessor( + OpenCensusSpanExporter( + service_name="basic-service", endpoint="localhost:55678" + ) + ) - trace.get_tracer_provider().add_span_processor(span_processor) + trace.get_tracer_provider().add_span_processor(self.span_processor) - def test_long_command(self): + def test_export(self): with self.tracer.start_as_current_span("foo"): with self.tracer.start_as_current_span("bar"): with self.tracer.start_as_current_span("baz"): - print("Hello world from OpenTelemetry Python!") + pass + + self.assertTrue(len(self.span_processor.export_status), 3) + + for export_status in self.span_processor.export_status: + self.assertEqual(export_status.name, "SUCCESS") + self.assertEqual(export_status.value, 0) + + +class TestOpenCensusMetricsExporter(TestBase): + + def setUp(self): + super().setUp() + + metrics.set_meter_provider(MeterProvider()) + self.meter = metrics.get_meter(__name__) + self.controller = ExportStatusMetricController( + self.meter, + OpenCensusMetricsExporter( + service_name="basic-service", endpoint="localhost:55678" + ), + 1 + ) + + def test_export(self): + + self.meter.create_metric( + name="requests", + description="number of requests", + unit="1", + value_type=int, + metric_type=Counter, + label_keys=("environment",), + ).add(25, {"environment": "staging"}) + + sleep(2) + + self.assertEqual(len(self.controller.export_status), 1) + self.assertEqual(self.controller.export_status[0].name, "SUCCESS") + self.assertEqual(self.controller.export_status[0].value, 0) diff --git a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py index faa0788c7f1..3b17486b813 100644 --- a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py @@ -70,13 +70,7 @@ def export( self, metric_records: Sequence[MetricRecord] ) -> MetricsExportResult: try: - responses = self.client.Export( - self.generate_metrics_requests(metric_records) - ) - - # Read response - for _ in responses: - pass + self.client.Export(self.generate_metrics_requests(metric_records)) except grpc.RpcError: return MetricsExportResult.FAILURE diff --git a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py index adadef1666f..c4ae6dea0b3 100644 --- a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py @@ -64,11 +64,7 @@ def __init__( def export(self, spans: Sequence[Span]) -> SpanExportResult: try: - responses = self.client.Export(self.generate_span_requests(spans)) - - # Read response - for _ in responses: - pass + self.client.Export(self.generate_span_requests(spans)) except grpc.RpcError: return SpanExportResult.FAILURE From 3e4cfeeb1c227d662d7012f4cf520eb0b7171dcd Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 19 May 2020 18:14:24 -0600 Subject: [PATCH 13/15] Fix lint --- .../opencensus-exporter-tracer/collector.py | 4 +++- .../test_opencensusexporter_functional.py | 23 ++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/docs/examples/opencensus-exporter-tracer/collector.py b/docs/examples/opencensus-exporter-tracer/collector.py index 5bae9e0be06..3f0c18aaf75 100644 --- a/docs/examples/opencensus-exporter-tracer/collector.py +++ b/docs/examples/opencensus-exporter-tracer/collector.py @@ -15,7 +15,9 @@ # limitations under the License. from opentelemetry import trace -from opentelemetry.ext.opencensusexporter.trace_exporter import OpenCensusSpanExporter +from opentelemetry.ext.opencensusexporter.trace_exporter import ( + OpenCensusSpanExporter, +) from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor diff --git a/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py b/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py index 57a5c500bf6..d466c2bcd15 100644 --- a/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py +++ b/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py @@ -12,24 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opentelemetry.ext.opencensusexporter.trace_exporter import ( - OpenCensusSpanExporter, -) +from time import sleep + +from opentelemetry import metrics, trace +from opentelemetry.context import attach, detach, set_value from opentelemetry.ext.opencensusexporter.metrics_exporter import ( OpenCensusMetricsExporter, ) -from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor +from opentelemetry.ext.opencensusexporter.trace_exporter import ( + OpenCensusSpanExporter, +) from opentelemetry.sdk.metrics import Counter, MeterProvider -from opentelemetry import trace, metrics +from opentelemetry.sdk.metrics.export.controller import PushController from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor from opentelemetry.test.test_base import TestBase -from opentelemetry.context import attach, detach, set_value -from opentelemetry.sdk.metrics.export.controller import PushController -from time import sleep class ExportStatusSpanProcessor(SimpleExportSpanProcessor): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.export_status = [] @@ -41,7 +41,6 @@ def on_end(self, span): class ExportStatusMetricController(PushController): - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.export_status = [] @@ -64,7 +63,6 @@ def tick(self): class TestOpenCensusSpanExporter(TestBase): - def setUp(self): super().setUp() @@ -92,7 +90,6 @@ def test_export(self): class TestOpenCensusMetricsExporter(TestBase): - def setUp(self): super().setUp() @@ -103,7 +100,7 @@ def setUp(self): OpenCensusMetricsExporter( service_name="basic-service", endpoint="localhost:55678" ), - 1 + 1, ) def test_export(self): From 45752a72920ac9649f87a76ecd6289e6a7fa83d7 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 21 May 2020 10:12:19 -0600 Subject: [PATCH 14/15] Add read for responses again --- .../ext/opencensusexporter/metrics_exporter/__init__.py | 8 +++++++- .../ext/opencensusexporter/trace_exporter/__init__.py | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py index 3b17486b813..faa0788c7f1 100644 --- a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/metrics_exporter/__init__.py @@ -70,7 +70,13 @@ def export( self, metric_records: Sequence[MetricRecord] ) -> MetricsExportResult: try: - self.client.Export(self.generate_metrics_requests(metric_records)) + responses = self.client.Export( + self.generate_metrics_requests(metric_records) + ) + + # Read response + for _ in responses: + pass except grpc.RpcError: return MetricsExportResult.FAILURE diff --git a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py index c4ae6dea0b3..adadef1666f 100644 --- a/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py +++ b/ext/opentelemetry-ext-opencensusexporter/src/opentelemetry/ext/opencensusexporter/trace_exporter/__init__.py @@ -64,7 +64,11 @@ def __init__( def export(self, spans: Sequence[Span]) -> SpanExportResult: try: - self.client.Export(self.generate_span_requests(spans)) + responses = self.client.Export(self.generate_span_requests(spans)) + + # Read response + for _ in responses: + pass except grpc.RpcError: return SpanExportResult.FAILURE From 63a2dc6895dab89a0678e74e784e86f1eac86d2b Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 22 May 2020 11:23:11 -0600 Subject: [PATCH 15/15] Remove test This is done to keep the test code while the OpenCensus issue reported (https://github.com/census-instrumentation/opencensus-service/issues/641) gets fixed. --- .../test_opencensusexporter_functional.py | 124 ++++++++++-------- 1 file changed, 66 insertions(+), 58 deletions(-) diff --git a/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py b/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py index d466c2bcd15..929002a4c7c 100644 --- a/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py +++ b/ext/opentelemetry-ext-docker-tests/tests/opencensus/test_opencensusexporter_functional.py @@ -12,18 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -from time import sleep - -from opentelemetry import metrics, trace +from opentelemetry import trace from opentelemetry.context import attach, detach, set_value -from opentelemetry.ext.opencensusexporter.metrics_exporter import ( - OpenCensusMetricsExporter, -) from opentelemetry.ext.opencensusexporter.trace_exporter import ( OpenCensusSpanExporter, ) -from opentelemetry.sdk.metrics import Counter, MeterProvider -from opentelemetry.sdk.metrics.export.controller import PushController from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor from opentelemetry.test.test_base import TestBase @@ -40,28 +33,6 @@ def on_end(self, span): detach(token) -class ExportStatusMetricController(PushController): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.export_status = [] - - def run(self): - while not self.finished.wait(self.interval): - self.tick() - - def tick(self): - # Collect all of the meter's metrics to be exported - self.meter.collect() - token = attach(set_value("suppress_instrumentation", True)) - # Export the given metrics in the batcher - self.export_status.append( - self.exporter.export(self.meter.batcher.checkpoint_set()) - ) - detach(token) - # Perform post-exporting logic based on batcher configuration - self.meter.batcher.finished_collection() - - class TestOpenCensusSpanExporter(TestBase): def setUp(self): super().setUp() @@ -89,33 +60,70 @@ def test_export(self): self.assertEqual(export_status.value, 0) -class TestOpenCensusMetricsExporter(TestBase): - def setUp(self): - super().setUp() +# FIXME This test fails because of an issue in the OpenCensus collector +# reported here: +# https://github.com/census-instrumentation/opencensus-service/issues/641 +# Uncomment this test when this issue gets fixed. - metrics.set_meter_provider(MeterProvider()) - self.meter = metrics.get_meter(__name__) - self.controller = ExportStatusMetricController( - self.meter, - OpenCensusMetricsExporter( - service_name="basic-service", endpoint="localhost:55678" - ), - 1, - ) +# from time import sleep +# from opentelemetry.ext.opencensusexporter.metrics_exporter import ( +# OpenCensusMetricsExporter, +# ) +# from opentelemetry.sdk.metrics import Counter, MeterProvider +# from opentelemetry.sdk.metrics.export.controller import PushController - def test_export(self): - - self.meter.create_metric( - name="requests", - description="number of requests", - unit="1", - value_type=int, - metric_type=Counter, - label_keys=("environment",), - ).add(25, {"environment": "staging"}) - - sleep(2) - - self.assertEqual(len(self.controller.export_status), 1) - self.assertEqual(self.controller.export_status[0].name, "SUCCESS") - self.assertEqual(self.controller.export_status[0].value, 0) +# from opentelemetry import metrics +# +# +# class ExportStatusMetricController(PushController): +# def __init__(self, *args, **kwargs): +# super().__init__(*args, **kwargs) +# self.export_status = [] +# +# def run(self): +# while not self.finished.wait(self.interval): +# self.tick() +# +# def tick(self): +# # Collect all of the meter's metrics to be exported +# self.meter.collect() +# token = attach(set_value("suppress_instrumentation", True)) +# # Export the given metrics in the batcher +# self.export_status.append( +# self.exporter.export(self.meter.batcher.checkpoint_set()) +# ) +# detach(token) +# # Perform post-exporting logic based on batcher configuration +# self.meter.batcher.finished_collection() +# +# +# class TestOpenCensusMetricsExporter(TestBase): +# def setUp(self): +# super().setUp() +# +# metrics.set_meter_provider(MeterProvider()) +# self.meter = metrics.get_meter(__name__) +# self.controller = ExportStatusMetricController( +# self.meter, +# OpenCensusMetricsExporter( +# service_name="basic-service", endpoint="localhost:55678" +# ), +# 1, +# ) +# +# def test_export(self): +# +# self.meter.create_metric( +# name="requests", +# description="number of requests", +# unit="1", +# value_type=int, +# metric_type=Counter, +# label_keys=("environment",), +# ).add(25, {"environment": "staging"}) +# +# sleep(2) +# +# self.assertEqual(len(self.controller.export_status), 1) +# self.assertEqual(self.controller.export_status[0].name, "SUCCESS") +# self.assertEqual(self.controller.export_status[0].value, 0)