Skip to content

gcp cloud trace and OTEL ResourceAttributes #7300

@raphaelauv

Description

@raphaelauv

GCP Cloud run does not seem to respect the ResourceAttributes of OTEL

from opentelemetry import trace
from opentelemetry.semconv.resource import ResourceAttributes
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry.propagate import set_global_textmap
from opentelemetry.propagators.cloud_trace_propagator import CloudTraceFormatPropagator

API_CODE_VERSION = os.getenv('API_CODE_VERSION', '0.1')
ENV = os.getenv("ENV", "preprod")


set_global_textmap(CloudTraceFormatPropagator())
tracer_provider = TracerProvider(resource=Resource.create(attributes={
    ResourceAttributes.SERVICE_VERSION: API_CODE_VERSION,
    ResourceAttributes.DEPLOYMENT_ENVIRONMENT: ENV,
    ResourceAttributes.SERVICE_NAME: "toto"
}))
tracer_provider.add_span_processor(BatchSpanProcessor(CloudTraceSpanExporter(project_id=TRACING_GCP_PROJECT_ID)))
trace.set_tracer_provider(tracer_provider)

FastAPIInstrumentor.instrument_app(app=app_fast_api, excluded_urls="/health,/openapi.json")

running this will give span in cloud trace , but the ResourceAttributes do not appear in the filter options of cloud run

Screenshot from 2021-12-27 18-32-22
Screenshot from 2021-12-27 18-32-32

Metadata

Metadata

Labels

api: runIssues related to the Cloud Run API.samplesIssues that are directly related to samples.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions