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
64 stars 45 forks source link

Setting the "ERROR" status doesn't show correctly in Google Cloud Trace #303

Closed multani closed 10 months ago

multani commented 11 months ago

When an error occured and after I set span status to ERROR, the span doesn't show up as error in Google Cloud Trace.

Consider the following example:

#!/usr/bin/env python3

from opentelemetry import trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.trace import Status, StatusCode

def setup():
    exporter = CloudTraceSpanExporter()
    # exporter = OTLPSpanExporter(endpoint="127.0.0.1:4317", insecure=True)
    print(f"Using tracing exporter {exporter}")

    processor = BatchSpanProcessor(exporter)

    resource = Resource(attributes={SERVICE_NAME: "test"})
    tracer_provider = TracerProvider(resource=resource)
    tracer_provider.add_span_processor(processor)

    trace.set_tracer_provider(tracer_provider)

def main():
    setup()

    tracer = trace.get_tracer(__name__)
    with tracer.start_as_current_span("first") as span:
        try:
            raise Exception("oh no")
        except Exception as exc:
            span.record_exception(exc)
            span.set_status(Status(StatusCode.ERROR))
            # span.set_attribute("http.status_code", 500)

if __name__ == "__main__":
    main()

It shows up like this in Google Cloud Trace: Screenshot from 2023-12-07 22-16-01 Screenshot from 2023-12-07 22-16-10

If I switch the exporter from CloudTraceSpanExporter to the OTLPSpanExporter (towards Jaeger), it shows up correctly in Jaeger:

image

Setting the span attribute http.status_code to 500 shows up correctly though, but this doesn't use the "official" status mechanism from OpenTelemetry:

image

aabmass commented 10 months ago

@multani this was also reported in https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/issues/730

Unfortunately we can't do anything in the exporter to fix it. Please follow along on that bug.