open-telemetry / open-telemetry/opentelemetry-python

TraceState does not check illegal inputs

Open
#5,136 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
2.6k
Forks
1k
Avg merge
4d 15h
Merged PRs (30d)
19

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at TraceState.add and reproduce the supplied cases, comparing the accepted valid tenant ID with the inputs that should be rejected. Trace the existing validation and its tests, then ensure the listed illegal formats and lengths are rejected while the valid case remains accepted; run the relevant TraceState test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.