aws-otel-community
aws-otel-community copied to clipboard
Span's add_event and record_exception not working with X-Ray
Span's add_event() and record_exception() are not working when exporter is X-Ray. For other exporters like Jaeger I could see Logs as a separate field in UI for add_event() and record_exception(). Looks like set_attribute() works fine as I can see the attributes in Metadata section of the span X-Ray.
Steps to reproduce:
- Run the aws-otel-collector in docker as below
docker run --rm -p 4317:4317 -p 55680:55680 -p 8889:8888 -e "AWS_ACCESS_KEY_ID=<YOUR ACCESS KEY>" -e "AWS_SECRET_ACCESS_KEY=<YOUR SECRET>" -e AWS_REGION=
-v :/otel-local-config.yaml --name awscollector public.ecr.aws/aws-observability/aws-otel-collector:latest --config otel-local-config.yaml - Create a simple python script with 2 spans as below and run: """OTLP exporter""" from opentelemetry import trace from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import ( OTLPSpanExporter, ) from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor from opentelemetry.sdk.extension.aws.trace import AwsXRayIdGenerator
span_exporter = OTLPSpanExporter( endpoint="localhost:4317", insecure=True, ) span_processor = BatchSpanProcessor(span_exporter) tracer_provider = TracerProvider(id_generator=AwsXRayIdGenerator()) tracer_provider.add_span_processor(span_processor) trace.set_tracer_provider(tracer_provider)
tracer = trace.get_tracer(name)
try: s1 = tracer.start_span("foo") s1.add_event("Tracing.........Foo...........", {}) s1.set_attribute("example", "value") time.sleep(2) s2 = tracer.start_span("bar", context=trace.set_span_in_context(s1)) try: 1 / 0 except Exception as e: s2.record_exception(e) finally: s2.end() finally: s1.end()
Note: I have to use tracer.start_span instead of tracer.start_as_current_span as per the requirement
Expected: s1.add_event("Tracing.........Foo...........", {}) - has to send logs/event to X-Ray (foo Segment) s2.record_exception(e) - has to send Exception trace to X-Ray (bar Subsegment)
Actual:
- Dont know where the events/logs will be for foo Segment in X-Ray
- Did not get Exception trace in Exception tab of bar Subsegment
Environment: Install docker, python3.8, opentelemetry-sdk and opentelemtry-api