-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <alrex.boten@gmail.com>
- Loading branch information
Showing
30 changed files
with
488 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...") |
18 changes: 18 additions & 0 deletions
18
docs/examples/opencensus-exporter-metrics/docker/collector-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
19 changes: 19 additions & 0 deletions
19
docs/examples/opencensus-exporter-metrics/docker/docker-compose.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
5 changes: 5 additions & 0 deletions
5
docs/examples/opencensus-exporter-metrics/docker/prometheus.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") |
19 changes: 19 additions & 0 deletions
19
docs/examples/opencensus-exporter-tracer/docker/collector-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
20 changes: 20 additions & 0 deletions
20
docs/examples/opencensus-exporter-tracer/docker/docker-compose.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.