Skip to content

Commit

Permalink
docs: fix getting started guide (#512)
Browse files Browse the repository at this point in the history
This commit fixes a series of issues in the getting started guide:

- Avoid using relative paths for docker volumes. Use `pwd` instead:
  moby/moby#4830 (comment)
- Fix indentation in prometheus config
- Fix otcollector example
  - Missing span processor
  - Remove sampling_initial and sampling_thereafter keys in config
  • Loading branch information
mauriciovasquezbernal committed Mar 27, 2020
1 parent 2a05f68 commit 44b5b04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/examples/otcollector-metrics/docker/prometheus.yaml
@@ -1,4 +1,4 @@
scrape_config:
scrape_configs:
- job_name: 'otel-collector'
scrape_interval: 5s
static_configs:
Expand Down
33 changes: 19 additions & 14 deletions docs/getting-started.rst
Expand Up @@ -285,19 +285,19 @@ Let's start by bringing up a Prometheus instance ourselves, to scrape our applic

.. code-block:: yaml
# prometheus.yml
# /tmp/prometheus.yml
scrape_configs:
- job_name: 'my-app'
scrape_interval: 5s
static_configs:
- targets: ['localhost:8000']
scrape_interval: 5s
static_configs:
- targets: ['localhost:8000']
And start a docker container for it:

.. code-block:: sh
# --net=host will not work properly outside of Linux.
docker run --net=host -v ./prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus\
docker run --net=host -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus \
--log.level=debug --config.file=/etc/prometheus/prometheus.yml
For our Python application, we will need to install an exporter specific to Prometheus:
Expand Down Expand Up @@ -371,15 +371,13 @@ To see how this works in practice, let's start the Collector locally. Write the

.. code-block:: yaml
# otel-collector-config.yaml
# /tmp/otel-collector-config.yaml
receivers:
opencensus:
endpoint: 0.0.0.0:55678
exporters:
logging:
loglevel: debug
sampling_initial: 10
sampling_thereafter: 50
processors:
batch:
queued_retry:
Expand All @@ -397,8 +395,8 @@ Start the docker container:

.. code-block:: sh
docker run -p 55678:55678\
-v ./otel-collector-config.yaml:/etc/otel-collector-config.yaml\
docker run -p 55678:55678 \
-v /tmp/otel-collector-config.yaml:/etc/otel-collector-config.yaml \
omnition/opentelemetry-collector-contrib:latest \
--config=/etc/otel-collector-config.yaml
Expand Down Expand Up @@ -433,6 +431,7 @@ And execute the following script:
)
tracer_provider = TracerProvider()
trace.set_tracer_provider(tracer_provider)
span_processor = BatchExportSpanProcessor(span_exporter)
tracer_provider.add_span_processor(span_processor)
# create a CollectorMetricsExporter
Expand All @@ -448,21 +447,27 @@ And execute the following script:
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)
controller = PushController(meter, metric_exporter, 5)
# Configure the tracer to use the collector exporter
tracer = trace.get_tracer_provider().get_tracer(__name__)
with tracer.start_as_current_span("foo"):
print("Hello world!")
counter = meter.create_metric(
"requests", "number of requests", "requests", int, Counter, ("environment",),
requests_counter = meter.create_metric(
name="requests",
description="number of requests",
unit="1",
value_type=int,
metric_type=Counter,
label_keys=("environment",),
)
# Labelsets 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
label_set = meter.get_label_set({"environment": "staging"})
counter.add(25, label_set)
requests_counter.add(25, label_set)
time.sleep(10) # give push_controller time to push metrics

0 comments on commit 44b5b04

Please sign in to comment.