Skip to content

Commit 44b5b04

Browse files
docs: fix getting started guide (#512)
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
1 parent 2a05f68 commit 44b5b04

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

docs/examples/otcollector-metrics/docker/prometheus.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
scrape_config:
1+
scrape_configs:
22
- job_name: 'otel-collector'
33
scrape_interval: 5s
44
static_configs:

docs/getting-started.rst

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,19 @@ Let's start by bringing up a Prometheus instance ourselves, to scrape our applic
285285

286286
.. code-block:: yaml
287287
288-
# prometheus.yml
288+
# /tmp/prometheus.yml
289289
scrape_configs:
290290
- job_name: 'my-app'
291-
scrape_interval: 5s
292-
static_configs:
293-
- targets: ['localhost:8000']
291+
scrape_interval: 5s
292+
static_configs:
293+
- targets: ['localhost:8000']
294294
295295
And start a docker container for it:
296296

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

372372
.. code-block:: yaml
373373
374-
# otel-collector-config.yaml
374+
# /tmp/otel-collector-config.yaml
375375
receivers:
376376
opencensus:
377377
endpoint: 0.0.0.0:55678
378378
exporters:
379379
logging:
380380
loglevel: debug
381-
sampling_initial: 10
382-
sampling_thereafter: 50
383381
processors:
384382
batch:
385383
queued_retry:
@@ -397,8 +395,8 @@ Start the docker container:
397395

398396
.. code-block:: sh
399397
400-
docker run -p 55678:55678\
401-
-v ./otel-collector-config.yaml:/etc/otel-collector-config.yaml\
398+
docker run -p 55678:55678 \
399+
-v /tmp/otel-collector-config.yaml:/etc/otel-collector-config.yaml \
402400
omnition/opentelemetry-collector-contrib:latest \
403401
--config=/etc/otel-collector-config.yaml
404402
@@ -433,6 +431,7 @@ And execute the following script:
433431
)
434432
tracer_provider = TracerProvider()
435433
trace.set_tracer_provider(tracer_provider)
434+
span_processor = BatchExportSpanProcessor(span_exporter)
436435
tracer_provider.add_span_processor(span_processor)
437436
438437
# create a CollectorMetricsExporter
@@ -448,21 +447,27 @@ And execute the following script:
448447
meter = metrics.get_meter(__name__)
449448
# controller collects metrics created from meter and exports it via the
450449
# exporter every interval
451-
controller = PushController(meter, collector_exporter, 5)
450+
controller = PushController(meter, metric_exporter, 5)
452451
453452
# Configure the tracer to use the collector exporter
454453
tracer = trace.get_tracer_provider().get_tracer(__name__)
455454
456455
with tracer.start_as_current_span("foo"):
457456
print("Hello world!")
458457
459-
counter = meter.create_metric(
460-
"requests", "number of requests", "requests", int, Counter, ("environment",),
458+
requests_counter = meter.create_metric(
459+
name="requests",
460+
description="number of requests",
461+
unit="1",
462+
value_type=int,
463+
metric_type=Counter,
464+
label_keys=("environment",),
461465
)
466+
462467
# Labelsets are used to identify key-values that are associated with a specific
463468
# metric that you want to record. These are useful for pre-aggregation and can
464469
# be used to store custom dimensions pertaining to a metric
465470
label_set = meter.get_label_set({"environment": "staging"})
466471
467-
counter.add(25, label_set)
472+
requests_counter.add(25, label_set)
468473
time.sleep(10) # give push_controller time to push metrics

0 commit comments

Comments
 (0)