Files
driver/tests/test_opentelemetry.py
zeekay 073c1bf61e rename: zero ClickHouse — datastore_driver speaks X-Datastore-*
The wire protocol was the last holdout and it was not cosmetic: the Hanzo
Datastore server reads X-Datastore-User, and answers a request bearing
X-ClickHouse-User with 401. Verified against the live server, both directions.
So a client still sending the old headers is not merely off-brand, it cannot
authenticate over HTTP.

Everything else follows: types, dialects, error modules, docstrings and doc
links now name Datastore, and doc URLs point at docs.hanzo.ai/datastore rather
than the upstream vendor's site. Zero occurrences of the old name remain.

Still cut from the pinned upstream version, so behaviour is unchanged.
2026-07-26 11:06:05 -07:00

90 lines
3.4 KiB
Python

from tests.testcase import BaseTestCase
from tests.util import capture_logging
class OpenTelemetryTestCase(BaseTestCase):
required_server_version = (20, 11, 2)
def test_server_logs(self):
tracestate = 'tracestate'
traceparent = '00-1af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'
settings = {
'opentelemetry_tracestate': tracestate,
'opentelemetry_traceparent': traceparent
}
with self.created_client(settings=settings) as client:
with capture_logging('datastore_driver.log', 'INFO') as buffer:
settings = {'send_logs_level': 'trace'}
query = 'SELECT 1'
client.execute(query, settings=settings)
value = buffer.getvalue()
self.assertIn('OpenTelemetry', value)
# Datastore 22.2+ use big-endian:
# https://github.com/Datastore/Datastore/pull/33723
if self.server_version >= (22, 2):
tp = '8448eb211c80319c1af7651916cd43dd'
else:
tp = '1af7651916cd43dd8448eb211c80319c'
self.assertIn(tp, value)
def test_no_tracestate(self):
traceparent = '00-1af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'
settings = {
'opentelemetry_traceparent': traceparent
}
with self.created_client(settings=settings) as client:
with capture_logging('datastore_driver.log', 'INFO') as buffer:
settings = {'send_logs_level': 'trace'}
query = 'SELECT 1'
client.execute(query, settings=settings)
value = buffer.getvalue()
self.assertIn('OpenTelemetry', value)
# Datastore 22.2+ use big-endian:
# https://github.com/Datastore/Datastore/pull/33723
if self.server_version >= (22, 2):
tp = '8448eb211c80319c1af7651916cd43dd'
else:
tp = '1af7651916cd43dd8448eb211c80319c'
self.assertIn(tp, value)
def test_bad_traceparent(self):
settings = {'opentelemetry_traceparent': 'bad'}
with self.created_client(settings=settings) as client:
with self.assertRaises(ValueError) as e:
client.execute('SELECT 1')
self.assertEqual(
str(e.exception),
'unexpected length 3, expected 55'
)
traceparent = '00-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-yyyyyyyyyyyyyyyy-01'
settings = {'opentelemetry_traceparent': traceparent}
with self.created_client(settings=settings) as client:
with self.assertRaises(ValueError) as e:
client.execute('SELECT 1')
self.assertEqual(
str(e.exception),
'Malformed traceparant header: {}'.format(traceparent)
)
def test_bad_traceparent_version(self):
settings = {
'opentelemetry_traceparent':
'01-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-01'
}
with self.created_client(settings=settings) as client:
with self.assertRaises(ValueError) as e:
client.execute('SELECT 1')
self.assertEqual(
str(e.exception),
'unexpected version 01, expected 00'
)