From a619139ad0bc932fab71b154eac690a818179024 Mon Sep 17 00:00:00 2001
From: Aaron Abbott <aaronabbott@google.com>
Date: Tue, 9 May 2023 15:42:03 +0000
Subject: [PATCH] Update monitoring README and docs requirements files

---
 .../cloud_monitoring/requirements.txt         |  1 +
 docs/examples/flask_e2e/requirements.txt      |  1 +
 .../README.rst                                | 39 ++++++++++++-------
 3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/docs/examples/cloud_monitoring/requirements.txt b/docs/examples/cloud_monitoring/requirements.txt
index 55f21f2c..2211f704 100644
--- a/docs/examples/cloud_monitoring/requirements.txt
+++ b/docs/examples/cloud_monitoring/requirements.txt
@@ -11,6 +11,7 @@ grpcio-status==1.50.0
 idna==3.4
 opentelemetry-api==1.14.0
 ../../../opentelemetry-exporter-gcp-monitoring
+../../../opentelemetry-resourcedetector-gcp
 opentelemetry-sdk==1.14.0
 opentelemetry-semantic-conventions==0.35b0
 proto-plus==1.22.1
diff --git a/docs/examples/flask_e2e/requirements.txt b/docs/examples/flask_e2e/requirements.txt
index 827432f1..f7ebd17f 100644
--- a/docs/examples/flask_e2e/requirements.txt
+++ b/docs/examples/flask_e2e/requirements.txt
@@ -19,6 +19,7 @@ opentelemetry-api==1.14.0
 ../../../opentelemetry-exporter-gcp-monitoring
 ../../../opentelemetry-exporter-gcp-trace
 ../../../opentelemetry-propagator-gcp
+../../../opentelemetry-resourcedetector-gcp
 opentelemetry-instrumentation==0.35b0
 opentelemetry-instrumentation-requests==0.35b0
 opentelemetry-instrumentation-flask==0.35b0
diff --git a/opentelemetry-exporter-gcp-monitoring/README.rst b/opentelemetry-exporter-gcp-monitoring/README.rst
index 798becc6..55ee8155 100644
--- a/opentelemetry-exporter-gcp-monitoring/README.rst
+++ b/opentelemetry-exporter-gcp-monitoring/README.rst
@@ -30,32 +30,45 @@ Usage
 .. code:: python
 
     import time
-
+    
     from opentelemetry import metrics
     from opentelemetry.exporter.cloud_monitoring import (
         CloudMonitoringMetricsExporter,
     )
-    from opentelemetry.sdk.metrics import Counter, MeterProvider
-
-    metrics.set_meter_provider(MeterProvider())
-    meter = metrics.get_meter(__name__)
-    metrics.get_meter_provider().start_pipeline(
-        meter, CloudMonitoringMetricsExporter(), 5
+    from opentelemetry.sdk.metrics import MeterProvider
+    from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
+    from opentelemetry.sdk.resources import Resource
+    
+    metrics.set_meter_provider(
+        MeterProvider(
+            metric_readers=[
+                PeriodicExportingMetricReader(
+                    CloudMonitoringMetricsExporter(), export_interval_millis=5000
+                )
+            ],
+            resource=Resource.create(
+                {
+                    "service.name": "basic_metrics",
+                    "service.namespace": "examples",
+                    "service.instance.id": "instance123",
+                }
+            ),
+        )
     )
-
+    meter = metrics.get_meter(__name__)
+    
+    # Creates metric workload.googleapis.com/request_counter with monitored resource generic_task
     requests_counter = meter.create_counter(
         name="request_counter",
         description="number of requests",
         unit="1",
-        value_type=int
     )
-
+    
     staging_labels = {"environment": "staging"}
-
+    
     for i in range(20):
         requests_counter.add(25, staging_labels)
-        time.sleep(10)
-
+        time.sleep(5)
 
 
 References