Skip to content

Commit

Permalink
opencensus: Rename otcollector to opencensus (#695)
Browse files Browse the repository at this point in the history
renaming otcollector to opencensus, as it's using opencensus under the hood. This was originally intended to be replaced by otlp, by a new package can be created for that instead. 

Co-authored-by: alrex <alrex.boten@gmail.com>
  • Loading branch information
ocelotl and codeboten authored May 23, 2020
1 parent f15d76a commit 46f8f64
Show file tree
Hide file tree
Showing 30 changed files with 488 additions and 156 deletions.
52 changes: 52 additions & 0 deletions docs/examples/opencensus-exporter-metrics/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 <docs/examples/opencensus-exporter-metrics/>`.

Installation
------------

.. code-block:: sh
pip install opentelemetry-api
pip install opentelemetry-sdk
pip install opentelemetry-ext-opencensusexporter
Run the Example
---------------

Before running the example, it's necessary to run the OpenTelemetry collector
and Prometheus. The :scm_web:`docker <docs/examples/opencensus-exporter-metrics/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_
- `OpenTelemetry Collector`_
- :doc:`../../api/trace`
- :doc:`../../ext/opencensusexporter/opencensusexporter`

.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/
.. _OpenTelemetry Collector: https://github.com/open-telemetry/opentelemetry-collector
47 changes: 47 additions & 0 deletions docs/examples/opencensus-exporter-metrics/collector.py
Original file line number Diff line number Diff line change
@@ -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.opencensusexporter.metrics_exporter import (
OpenCensusMetricsExporter,
)
from opentelemetry.sdk.metrics import Counter, MeterProvider
from opentelemetry.sdk.metrics.export.controller import PushController

exporter = OpenCensusMetricsExporter(
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...")
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scrape_configs:
- job_name: 'otel-collector'
scrape_interval: 5s
static_configs:
- targets: ['otel-collector:8889']
51 changes: 51 additions & 0 deletions docs/examples/opencensus-exporter-tracer/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
OpenTelemetry Collector Tracer OpenCensus Exporter Example
==========================================================

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 <docs/examples/opencensus-exporter-tracer/>`.

Installation
------------

.. code-block:: sh
pip install opentelemetry-api
pip install opentelemetry-sdk
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 <docs/examples/opencensus-exporter-tracer/docker/>`
folder contains 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_
- `OpenTelemetry Collector`_
- :doc:`../../api/trace`
- :doc:`../../ext/opencensusexporter/opencensusexporter`

.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/
.. _OpenTelemetry Collector: https://github.com/open-telemetry/opentelemetry-collector
36 changes: 36 additions & 0 deletions docs/examples/opencensus-exporter-tracer/collector.py
Original file line number Diff line number Diff line change
@@ -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.

from opentelemetry import trace
from opentelemetry.ext.opencensusexporter.trace_exporter import (
OpenCensusSpanExporter,
)
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

exporter = OpenCensusSpanExporter(
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!")
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 7 additions & 0 deletions docs/ext/opencensusexporter/opencensusexporter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OpenCensus Exporter
===================

.. automodule:: opentelemetry.ext.opencensusexporter
:members:
:undoc-members:
:show-inheritance:
7 changes: 0 additions & 7 deletions docs/ext/otcollector/otcollector.rst

This file was deleted.

8 changes: 7 additions & 1 deletion ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ services:
- "5778:5778"
- "16686:16686"
- "14268:14268"
- "9411:9411"
- "9411:9411"
otopencensus:
image: omnition/opencensus-collector:0.1.11
command: --logging-exporter DEBUG
ports:
- "8888:8888"
- "55678:55678"
Loading

0 comments on commit 46f8f64

Please sign in to comment.