File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change 17
17
import logging
18
18
19
19
import google .auth
20
- from opentelemetry .resourcedetector .gcp_resource_detector import GoogleCloudResourceDetector
21
20
from opentelemetry .sdk ._logs import LogRecordProcessor
22
21
from opentelemetry .sdk ._logs .export import BatchLogRecordProcessor
23
22
from opentelemetry .sdk .metrics .export import MetricReader
@@ -108,8 +107,19 @@ def get_gcp_resource() -> Resource:
108
107
# Then the GCP detector adds attributes corresponding to a correct
109
108
# monitored resource if ADK runs on one of supported platforms
110
109
# (e.g. GCE, GKE, CloudRun).
111
- return (
112
- OTELResourceDetector ()
113
- .detect ()
114
- .merge (GoogleCloudResourceDetector (raise_on_error = False ).detect ())
115
- )
110
+
111
+ resource = OTELResourceDetector ().detect ()
112
+
113
+ try :
114
+ from opentelemetry .resourcedetector .gcp_resource_detector import GoogleCloudResourceDetector
115
+
116
+ resource = resource .merge (
117
+ GoogleCloudResourceDetector (raise_on_error = False ).detect ()
118
+ )
119
+ except ImportError :
120
+ logger .warning (
121
+ 'Cloud not import opentelemetry.resourcedetector.gcp_resource_detector'
122
+ ' GCE, GKE or CloudRun related resource attributes may be missing'
123
+ )
124
+
125
+ return resource
You can’t perform that action at this time.
0 commit comments