Skip to content

Commit 46f8f64

Browse files
ocelotlcodeboten
andauthored
opencensus: Rename otcollector to opencensus (#695)
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 <[email protected]>
1 parent f15d76a commit 46f8f64

File tree

30 files changed

+488
-156
lines changed

30 files changed

+488
-156
lines changed

Diff for: docs/examples/opencensus-exporter-metrics/README.rst

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
OpenTelemetry Collector Metrics OpenCensus Exporter Example
2+
===========================================================
3+
4+
This example shows how to use the OpenCensus Exporter to export metrics to
5+
the OpenTelemetry collector.
6+
7+
The source files of this example are available :scm_web:`here <docs/examples/opencensus-exporter-metrics/>`.
8+
9+
Installation
10+
------------
11+
12+
.. code-block:: sh
13+
14+
pip install opentelemetry-api
15+
pip install opentelemetry-sdk
16+
pip install opentelemetry-ext-opencensusexporter
17+
18+
Run the Example
19+
---------------
20+
21+
Before running the example, it's necessary to run the OpenTelemetry collector
22+
and Prometheus. The :scm_web:`docker <docs/examples/opencensus-exporter-metrics/docker/>`
23+
folder contains the a docker-compose template with the configuration of those
24+
services.
25+
26+
.. code-block:: sh
27+
28+
pip install docker-compose
29+
cd docker
30+
docker-compose up
31+
32+
33+
Now, the example can be executed:
34+
35+
.. code-block:: sh
36+
37+
python collector.py
38+
39+
40+
The metrics are available in the Prometheus dashboard at http://localhost:9090/graph,
41+
look for the "requests" metric on the list.
42+
43+
Useful links
44+
------------
45+
46+
- OpenTelemetry_
47+
- `OpenTelemetry Collector`_
48+
- :doc:`../../api/trace`
49+
- :doc:`../../ext/opencensusexporter/opencensusexporter`
50+
51+
.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/
52+
.. _OpenTelemetry Collector: https://github.com/open-telemetry/opentelemetry-collector
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""
16+
This example shows how to export metrics to the OT collector.
17+
"""
18+
19+
from opentelemetry import metrics
20+
from opentelemetry.ext.opencensusexporter.metrics_exporter import (
21+
OpenCensusMetricsExporter,
22+
)
23+
from opentelemetry.sdk.metrics import Counter, MeterProvider
24+
from opentelemetry.sdk.metrics.export.controller import PushController
25+
26+
exporter = OpenCensusMetricsExporter(
27+
service_name="basic-service", endpoint="localhost:55678"
28+
)
29+
30+
metrics.set_meter_provider(MeterProvider())
31+
meter = metrics.get_meter(__name__)
32+
controller = PushController(meter, exporter, 5)
33+
34+
requests_counter = meter.create_metric(
35+
name="requests",
36+
description="number of requests",
37+
unit="1",
38+
value_type=int,
39+
metric_type=Counter,
40+
label_keys=("environment",),
41+
)
42+
43+
staging_labels = {"environment": "staging"}
44+
requests_counter.add(25, staging_labels)
45+
46+
print("Metrics are available now at http://localhost:9090/graph")
47+
input("Press any key to exit...")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
receivers:
2+
opencensus:
3+
endpoint: "0.0.0.0:55678"
4+
5+
exporters:
6+
prometheus:
7+
endpoint: "0.0.0.0:8889"
8+
logging: {}
9+
10+
processors:
11+
batch:
12+
queued_retry:
13+
14+
service:
15+
pipelines:
16+
metrics:
17+
receivers: [opencensus]
18+
exporters: [logging, prometheus]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: "2"
2+
services:
3+
4+
otel-collector:
5+
image: omnition/opentelemetry-collector-contrib:latest
6+
command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"]
7+
volumes:
8+
- ./collector-config.yaml:/conf/collector-config.yaml
9+
ports:
10+
- "8889:8889" # Prometheus exporter metrics
11+
- "55678:55678" # OpenCensus receiver
12+
13+
prometheus:
14+
container_name: prometheus
15+
image: prom/prometheus:latest
16+
volumes:
17+
- ./prometheus.yaml:/etc/prometheus/prometheus.yml
18+
ports:
19+
- "9090:9090"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scrape_configs:
2+
- job_name: 'otel-collector'
3+
scrape_interval: 5s
4+
static_configs:
5+
- targets: ['otel-collector:8889']

Diff for: docs/examples/opencensus-exporter-tracer/README.rst

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
OpenTelemetry Collector Tracer OpenCensus Exporter Example
2+
==========================================================
3+
4+
This example shows how to use the OpenCensus Exporter to export traces to the
5+
OpenTelemetry collector.
6+
7+
The source files of this example are available :scm_web:`here <docs/examples/opencensus-exporter-tracer/>`.
8+
9+
Installation
10+
------------
11+
12+
.. code-block:: sh
13+
14+
pip install opentelemetry-api
15+
pip install opentelemetry-sdk
16+
pip install opentelemetry-ext-opencensusexporter
17+
18+
Run the Example
19+
---------------
20+
21+
Before running the example, it's necessary to run the OpenTelemetry collector
22+
and Jaeger. The :scm_web:`docker <docs/examples/opencensus-exporter-tracer/docker/>`
23+
folder contains a ``docker-compose`` template with the configuration of those
24+
services.
25+
26+
.. code-block:: sh
27+
28+
pip install docker-compose
29+
cd docker
30+
docker-compose up
31+
32+
33+
Now, the example can be executed:
34+
35+
.. code-block:: sh
36+
37+
python collector.py
38+
39+
40+
The traces are available in the Jaeger UI at http://localhost:16686/.
41+
42+
Useful links
43+
------------
44+
45+
- OpenTelemetry_
46+
- `OpenTelemetry Collector`_
47+
- :doc:`../../api/trace`
48+
- :doc:`../../ext/opencensusexporter/opencensusexporter`
49+
50+
.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/
51+
.. _OpenTelemetry Collector: https://github.com/open-telemetry/opentelemetry-collector
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright The OpenTelemetry Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from opentelemetry import trace
18+
from opentelemetry.ext.opencensusexporter.trace_exporter import (
19+
OpenCensusSpanExporter,
20+
)
21+
from opentelemetry.sdk.trace import TracerProvider
22+
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
23+
24+
exporter = OpenCensusSpanExporter(
25+
service_name="basic-service", endpoint="localhost:55678"
26+
)
27+
28+
trace.set_tracer_provider(TracerProvider())
29+
tracer = trace.get_tracer(__name__)
30+
span_processor = BatchExportSpanProcessor(exporter)
31+
32+
trace.get_tracer_provider().add_span_processor(span_processor)
33+
with tracer.start_as_current_span("foo"):
34+
with tracer.start_as_current_span("bar"):
35+
with tracer.start_as_current_span("baz"):
36+
print("Hello world from OpenTelemetry Python!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
receivers:
2+
opencensus:
3+
endpoint: "0.0.0.0:55678"
4+
5+
exporters:
6+
jaeger_grpc:
7+
endpoint: jaeger-all-in-one:14250
8+
logging: {}
9+
10+
processors:
11+
batch:
12+
queued_retry:
13+
14+
service:
15+
pipelines:
16+
traces:
17+
receivers: [opencensus]
18+
exporters: [jaeger_grpc, logging]
19+
processors: [batch, queued_retry]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: "2"
2+
services:
3+
4+
# Collector
5+
collector:
6+
image: omnition/opentelemetry-collector-contrib:latest
7+
command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"]
8+
volumes:
9+
- ./collector-config.yaml:/conf/collector-config.yaml
10+
ports:
11+
- "55678:55678"
12+
13+
jaeger-all-in-one:
14+
image: jaegertracing/all-in-one:latest
15+
ports:
16+
- "16686:16686"
17+
- "6831:6831/udp"
18+
- "6832:6832/udp"
19+
- "14268"
20+
- "14250"

Diff for: docs/ext/opencensusexporter/opencensusexporter.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
OpenCensus Exporter
2+
===================
3+
4+
.. automodule:: opentelemetry.ext.opencensusexporter
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

Diff for: docs/ext/otcollector/otcollector.rst

-7
This file was deleted.

Diff for: ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ services:
3838
- "5778:5778"
3939
- "16686:16686"
4040
- "14268:14268"
41-
- "9411:9411"
41+
- "9411:9411"
42+
otopencensus:
43+
image: omnition/opencensus-collector:0.1.11
44+
command: --logging-exporter DEBUG
45+
ports:
46+
- "8888:8888"
47+
- "55678:55678"

0 commit comments

Comments
 (0)