0
0
GCPcloud~10 mins

Cloud Trace for latency analysis in GCP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable Cloud Trace API in your GCP project.

GCP
gcloud services enable [1]
Drag options to blanks, or click blank then click option'
Abigquery.googleapis.com
Bcloudtrace.googleapis.com
Cstorage.googleapis.com
Dcompute.googleapis.com
Attempts:
3 left
💡 Hint
Common Mistakes
Enabling unrelated APIs like Compute or Storage instead of Cloud Trace.
Misspelling the API name.
2fill in blank
medium

Complete the code to create a trace span using the OpenTelemetry Python library.

GCP
with tracer.start_as_current_span("[1]") as span:
    # your code here
    pass
Drag options to blanks, or click blank then click option'
Acustom_operation
Bdatabase_query
Cprocess_data
Dhttp_request
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic or unrelated span names that don't describe the operation.
Leaving the span name empty.
3fill in blank
hard

Fix the error in the code to export trace data to Cloud Trace using OpenTelemetry.

GCP
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor([1]))
Drag options to blanks, or click blank then click option'
AFileSpanExporter()
BConsoleSpanExporter()
CCloudTraceSpanExporter()
DLoggingSpanExporter()
Attempts:
3 left
💡 Hint
Common Mistakes
Using exporters that only print or log traces locally.
Not adding a span processor at all.
4fill in blank
hard

Fill both blanks to configure the OpenTelemetry tracer with resource attributes and exporter.

GCP
resource = Resource(attributes={"service.name": [1])
tracer_provider = TracerProvider(resource=resource)
tracer_provider.add_span_processor(BatchSpanProcessor([2]))
Drag options to blanks, or click blank then click option'
A"my-service"
BCloudTraceSpanExporter()
CConsoleSpanExporter()
D"default-service"
Attempts:
3 left
💡 Hint
Common Mistakes
Using ConsoleSpanExporter instead of CloudTraceSpanExporter.
Not setting a proper service name.
5fill in blank
hard

Fill all three blanks to create a trace span, add attributes, and end it properly.

GCP
tracer = trace.get_tracer("[1]")
with tracer.start_as_current_span("[2]") as span:
    span.set_attribute("http.status_code", [3])
    # your code here
Drag options to blanks, or click blank then click option'
Amy-service
Brequest-handler
C200
Derror-handler
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect span or tracer names.
Setting wrong or string HTTP status codes.