Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Validate links during span creation #3990

Closed
@emdneto

Description

@emdneto

Describe your environment

OS: Ubuntu
Python version: 3.12
SDK version: 1.25.0
API version: 1.25.0

What happened?

We are recording invalid links when adding links during span creation.

Steps to Reproduce

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
   SimpleSpanProcessor,
   ConsoleSpanExporter,
)


trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))

tracer = trace.get_tracer("my.tracer")
with tracer.start_as_current_span("root", links=[trace.Link(trace.INVALID_SPAN_CONTEXT)]) as root:
   pass

Expected Result

"links": []

Since this is the preferred method to add links, I suppose we should also validate links at span creation

Actual Result

    "links": [
        {
            "context": {
                "trace_id": "0x00000000000000000000000000000000",
                "span_id": "0x0000000000000000",
                "trace_state": "[]"
            },
            "attributes": {}
        }
    ],

Additional context

No response

Would you like to implement a fix?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions