File tree Expand file tree Collapse file tree 3 files changed +10
-3
lines changed
Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,9 @@ gcloud auth application-default login
2121#### Run the Sample
2222``` sh
2323# export necessary OTEL environment variables
24- export OTEL_RESOURCE_ATTRIBUTES= " gcp.project_id= <project-id>"
24+ export PROJECT_ID= < project-id>
2525export OTEL_EXPORTER_OTLP_ENDPOINT=< endpoint>
26+ export OTEL_RESOURCE_ATTRIBUTES=" gcp.project_id=$PROJECT_ID ,service.name=otlp-sample,service.instance.id=1"
2627
2728# from the samples/otlpmetric repository
2829python3 example.py
Original file line number Diff line number Diff line change 2424from opentelemetry .exporter .otlp .proto .grpc .metric_exporter import (
2525 OTLPMetricExporter ,
2626)
27- from opentelemetry .sdk .resources import SERVICE_NAME , Resource
27+ from opentelemetry .resourcedetector .gcp_resource_detector ._detector import (
28+ GoogleCloudResourceDetector ,
29+ )
30+ from opentelemetry .sdk .resources import SERVICE_NAME , Resource , get_aggregated_resources
2831from opentelemetry .sdk .metrics import MeterProvider
2932from opentelemetry .sdk .metrics .export import PeriodicExportingMetricReader
3033
3437
3538credentials , project_id = google .auth .default ()
3639request = google .auth .transport .requests .Request ()
37- resource = Resource .create (attributes = {SERVICE_NAME : "otlp-gcp-grpc-sample" })
40+ resource = get_aggregated_resources (
41+ [GoogleCloudResourceDetector (raise_on_error = True )]
42+ )
3843
3944auth_metadata_plugin = AuthMetadataPlugin (
4045 credentials = credentials , request = request
Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ opentelemetry-sdk==1.24.0
44google-auth == 2.18.1
55opentelemetry-exporter-otlp-proto-grpc == 1.24.0
66grpcio == 1.63.0
7+ opentelemetry-resourcedetector-gcp == 1.8.0
You can’t perform that action at this time.
0 commit comments