Skip to content

TraceState does not check illegal inputs #5136

@tohidemyname

Description

@tohidemyname

Describe your environment

OS: Windows
Python version: Python 3.13
SDK version: the latest
API version: the latest

TraceState.add() does not fully check whether the inputs are correct.

What happened?

TraceState.add() should reject the illegal inputs.

Steps to Reproduce

Here is my test case:

`from opentelemetry.trace import TraceState

Java constants mapped to Python

EMPTY = TraceState()
FIRST_VALUE = "first_value" # Adjust to match your test's actual constant
class MyTestCase(unittest.TestCase):

def test_valid_long_tenant_id(self):
    result = EMPTY.add("12345678901234567890@nr", FIRST_VALUE)
    assert result.get("12345678901234567890@nr") == FIRST_VALUE


def test_vendor_id_longer_than_13_characters(self):
    with self.assertRaises(Exception) as context:
        EMPTY.add("1@nrabcdefghijkl", FIRST_VALUE)
    self.assertTrue('This is broken' in context.exception)

def test_vendor_id_longer_than_13_characters_long_tenant_id(self):
    with self.assertRaises(Exception) as context:
        EMPTY.add("12345678901234567890@nrabcdefghijkl", FIRST_VALUE)
    self.assertTrue('This is broken' in context.exception)

def test_tenant_id_longer_than_240_characters(self):
    tenant_id = "a" * 241
    with self.assertRaises(Exception) as context:
        EMPTY.add(f"{tenant_id}@nr", FIRST_VALUE)
    self.assertTrue('This is broken' in context.exception)

def test_non_vendor_format_first_key_character(self):
    with self.assertRaises(Exception) as context:
        EMPTY.add("1acdfrgs", FIRST_VALUE)
    self.assertTrue('This is broken' in context.exception)`

Expected Result

Shall reject.

Actual Result

Added.

Additional context

No response

Would you like to implement a fix?

None

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

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