GoogleCloudPlatform / opentelemetry-operations-python

OpenTelemetry Python exporters for Google Cloud Monitoring and Trace
https://google-cloud-opentelemetry.readthedocs.io/en/stable/
Apache License 2.0
63 stars 45 forks source link

Cloud Run ResourceDetector not using service name #300

Closed theobouwman closed 8 months ago

theobouwman commented 10 months ago

The service.name attribute is not added grom the GoogleCloudResourceDetector in Cloud Run. Am I doing something wrong?

resources = get_aggregated_resources(
        [GoogleCloudResourceDetector(raise_on_error=True)]
    )

    SQLAlchemyInstrumentor().instrument(engine=db._engine)

    set_global_textmap(CloudTraceFormatPropagator())

    tracer_provider = TracerProvider(resource=resources)
    cloud_trace_exporter = CloudTraceSpanExporter()
    tracer_provider.add_span_processor(
        # BatchSpanProcessor buffers spans and sends them in batches in a
        # background thread. The default parameters are sensible, but can be
        # tweaked to optimize your performance
        BatchSpanProcessor(cloud_trace_exporter)
    )

    meter_provider = MeterProvider(
        metric_readers=[
            PeriodicExportingMetricReader(
                CloudMonitoringMetricsExporter(), export_interval_millis=5000
            )
        ],
        resource=resources,
    )

    trace.set_tracer_provider(tracer_provider)
    metrics.set_meter_provider(meter_provider)

    tracer = trace.get_tracer(__name__)
    meter = metrics.get_meter(__name__)

    FastAPIInstrumentor.instrument_app(
        app,
        tracer_provider=tracer_provider,
        meter_provider=meter_provider
    )

Screenshot 2023-11-08 at 12 21 01

aabmass commented 8 months ago

Hey @theobouwman sorry for the slow response here. A few things to note:

I'd recommend just setting the OTEL_SERVICE_NAME environment variable in Cloud Run. Please re-open if you have any questions