-- Trace V2 uses the same flattened attribute references as V1. -- Everything after the root column is one literal key, including dots. create table graph_trace_v2 ( "timestamp" timestamp(9) time index, timestamp_end timestamp(9), duration_nano bigint, parent_span_id string, trace_id string, span_id string, span_kind string, span_name string, span_status_code string, span_status_message string, trace_state string, scope_name string, scope_version string, service_name string, span_attributes json2, scope_attributes json2, resource_attributes json2, span_events json, span_links json, primary key (service_name) ) with ( 'table_data_model' = 'greptime_trace_v2', 'append_mode' = 'true', 'greptime.semantic.entity.gen_ai.agent.id' = 'span_attributes.gen_ai.agent.id', 'greptime.semantic.entity.gen_ai.agent.scope' = 'scope_attributes.environment', 'greptime.semantic.entity.gen_ai.model.id' = 'span_attributes.gen_ai.request.model', 'greptime.semantic.entity.literal_peer.id' = 'span_attributes.db.namespace', 'greptime.semantic.entity.literal_resource.id' = 'resource_attributes.host.name', 'greptime.semantic.entity.literal_span.id' = 'span_attributes.gen_ai.agent.id', 'greptime.semantic.entity.literal_scope.id' = 'scope_attributes.deployment.region.name' ); Affected Rows: 0 insert into graph_trace_v2 ("timestamp", duration_nano, trace_id, span_id, span_kind, span_status_code, service_name, span_attributes, scope_attributes, resource_attributes) values ('2026-01-01 00:00:01', 100000000, 'paired', 'client', 'SPAN_KIND_CLIENT', 'STATUS_CODE_UNSET', 'frontend', '{"gen_ai.agent.id":"agent-a","gen_ai.request.model":"model-a","gen_ai":{"agent":{"id":"nested-agent"}}}', '{"environment":"prod","deployment.region.name":"literal-region","deployment":{"region.name":"nested-region"},"a\"b\\c.d":7}', '{"service.namespace":"shop","service.instance.id":"front-1","host.id":"host-1","host.name":"node-1","host":{"name":"nested-node"},"service":{"namespace":"wrong-namespace"}}'), ('2026-01-01 00:00:02', 200000000, 'virtual', 'client', 'SPAN_KIND_CLIENT', 'STATUS_CODE_ERROR', 'frontend', '{"service.peer.name":"","db.namespace":"orders","db":{"namespace":"wrong-orders"}}', '{}', '{"service.namespace":"shop","service.instance.id":"front-1","host.id":"host-1","host.name":"node-1"}'), ('2026-01-01 00:00:03', 100, 'missing', 'internal', 'SPAN_KIND_INTERNAL', 'STATUS_CODE_UNSET', 'no-resource', '{"gen_ai.agent.id":null}', '{}', '{}'); Affected Rows: 3 -- Agent parent/child references are independent of span kind. insert into graph_trace_v2 ("timestamp", duration_nano, trace_id, span_id, parent_span_id, span_kind, span_status_code, service_name, span_attributes, scope_attributes, resource_attributes) values ('2026-01-01 00:00:01', 30000000, 'paired', 'agent-child', 'client', 'SPAN_KIND_INTERNAL', 'STATUS_CODE_UNSET', 'frontend', '{"gen_ai.agent.id":"agent-b"}', '{"environment":"prod"}', '{"service.namespace":"shop"}'); Affected Rows: 1 -- Calls can pair a V2 client with a V1 server. The literal_resource declaration -- has exactly the same spelling in both models, including its output JSON keys. create table graph_trace_v1_peer ( "timestamp" timestamp(9) time index, trace_id string, span_id string, parent_span_id string, span_kind string, span_status_code string, duration_nano bigint, service_name string, "resource_attributes.service.namespace" string, "resource_attributes.host.name" string, primary key (service_name) ) with ('table_data_model' = 'greptime_trace_v1', 'append_mode' = 'true', 'greptime.semantic.entity.literal_resource.id' = 'resource_attributes.host.name'); Affected Rows: 0 insert into graph_trace_v1_peer values ('2026-01-01 00:00:01', 'paired', 'server', 'client', 'SPAN_KIND_SERVER', 'STATUS_CODE_UNSET', 50000000, 'backend', 'shop', 'node-v1'); Affected Rows: 1 select entity_type, entity_id, scope from greptime_private.semantic_entities where observed_at >= '2026-01-01 00:00:00' and observed_at < '2026-01-01 00:01:00' order by entity_type, entity_id; +------------------+-----------------------+-------+ | entity_type | entity_id | scope | +------------------+-----------------------+-------+ | gen_ai.agent | agent-a | prod | | gen_ai.agent | agent-b | prod | | gen_ai.model | model-a | | | host | host-1 | | | literal_peer | orders | | | literal_resource | node-1 | | | literal_resource | node-v1 | | | literal_scope | literal-region | | | literal_span | agent-a | | | literal_span | agent-b | | | service | no-resource | | | service | shop/backend | | | service | shop/frontend | | | service.instance | shop/frontend,front-1 | | +------------------+-----------------------+-------+ select src_type, src_id, dst_type, dst_id, rel_type, request_count, error_count from greptime_private.semantic_relationships where observed_at >= '2026-01-01 00:00:00' and observed_at < '2026-01-01 00:01:00' order by rel_type, src_type, src_id, dst_id; +------------------+-----------------------+--------------+---------------+----------+---------------+-------------+ | src_type | src_id | dst_type | dst_id | rel_type | request_count | error_count | +------------------+-----------------------+--------------+---------------+----------+---------------+-------------+ | gen_ai.agent | agent-a | gen_ai.agent | agent-b | calls | 1 | 0 | | service | shop/frontend | service | orders | calls | 1 | 1 | | service | shop/frontend | service | shop/backend | calls | 1 | 0 | | service.instance | shop/frontend,front-1 | service | shop/frontend | part_of | | | | service.instance | shop/frontend,front-1 | host | host-1 | runs_on | | | | gen_ai.agent | agent-a | gen_ai.model | model-a | uses | | | +------------------+-----------------------+--------------+---------------+----------+---------------+-------------+ -- Empty components in the V1-compatible comma-separated list remain invalid. alter table graph_trace_v2 set 'greptime.semantic.entity.invalid.id' = 'resource_attributes.host.id,'; Error: 1004(InvalidArguments), Invalid alter table(graph_trace_v2) request: invalid value `resource_attributes.host.id,` for semantic option `greptime.semantic.entity.invalid.id` alter table graph_trace_v2 set 'greptime.semantic.entity.invalid.id' = 'resource_attributes.host.id,,service_name'; Error: 1004(InvalidArguments), Invalid alter table(graph_trace_v2) request: invalid value `resource_attributes.host.id,,service_name` for semantic option `greptime.semantic.entity.invalid.id` -- ALTER accepts JSON2 references; a missing key simply yields no entity. alter table graph_trace_v2 set 'greptime.semantic.entity.custom.id' = 'scope_attributes.missing'; Affected Rows: 0 alter table graph_trace_v2 set 'greptime.semantic.entity.host.descriptive' = 'resource_attributes.host.name'; Affected Rows: 0 -- Preserve implicit host identity by explicitly declaring it as well. alter table graph_trace_v2 set 'greptime.semantic.entity.host.id' = 'resource_attributes.host.id'; Affected Rows: 0 admin flush_table('graph_trace_v2'); +-------------------------------------+ | ADMIN flush_table('graph_trace_v2') | +-------------------------------------+ | 0 | +-------------------------------------+ admin flush_table('graph_trace_v1_peer'); +------------------------------------------+ | ADMIN flush_table('graph_trace_v1_peer') | +------------------------------------------+ | 0 | +------------------------------------------+ -- SQLNESS PROTOCOL MYSQL select entity_type, entity_id, scope, entity_id_attrs, descriptive from greptime_private.semantic_entities where observed_at >= '2026-01-01 00:00:00' and observed_at < '2026-01-01 00:01:00' order by entity_type, entity_id; +------------------+-----------------------+-------+--------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------+ | entity_type | entity_id | scope | entity_id_attrs | descriptive | +------------------+-----------------------+-------+--------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------+ | gen_ai.agent | agent-a | prod | {"span_attributes.gen_ai.agent.id":"agent-a"} | | | gen_ai.agent | agent-b | prod | {"span_attributes.gen_ai.agent.id":"agent-b"} | | | gen_ai.model | model-a | | {"span_attributes.gen_ai.request.model":"model-a"} | | | host | host-1 | | {"resource_attributes.host.id":"host-1"} | {"resource_attributes.host.name":"node-1"} | | literal_peer | orders | | {"span_attributes.db.namespace":"orders"} | | | literal_resource | node-1 | | {"resource_attributes.host.name":"node-1"} | | | literal_resource | node-v1 | | {"resource_attributes.host.name":"node-v1"} | | | literal_scope | literal-region | | {"scope_attributes.deployment.region.name":"literal-region"} | | | literal_span | agent-a | | {"span_attributes.gen_ai.agent.id":"agent-a"} | | | literal_span | agent-b | | {"span_attributes.gen_ai.agent.id":"agent-b"} | | | service | no-resource | | {"resource_attributes.service.namespace":"","service_name":"no-resource"} | | | service | shop/backend | | {"resource_attributes.service.namespace":"shop","service_name":"backend"} | | | service | shop/frontend | | {"resource_attributes.service.namespace":"shop","service_name":"frontend"} | | | service.instance | shop/frontend,front-1 | | {"resource_attributes.service.instance.id":"front-1","resource_attributes.service.namespace":"shop","service_name":"frontend"} | | +------------------+-----------------------+-------+--------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------+ select src_type, src_id, dst_type, dst_id, rel_type, request_count, error_count from greptime_private.semantic_relationships where observed_at >= '2026-01-01 00:00:00' and observed_at < '2026-01-01 00:01:00' order by rel_type, src_type, src_id, dst_id; +------------------+-----------------------+--------------+---------------+----------+---------------+-------------+ | src_type | src_id | dst_type | dst_id | rel_type | request_count | error_count | +------------------+-----------------------+--------------+---------------+----------+---------------+-------------+ | gen_ai.agent | agent-a | gen_ai.agent | agent-b | calls | 1 | 0 | | service | shop/frontend | service | orders | calls | 1 | 1 | | service | shop/frontend | service | shop/backend | calls | 1 | 0 | | service.instance | shop/frontend,front-1 | service | shop/frontend | part_of | | | | service.instance | shop/frontend,front-1 | host | host-1 | runs_on | | | | gen_ai.agent | agent-a | gen_ai.model | model-a | uses | | | +------------------+-----------------------+--------------+---------------+----------+---------------+-------------+ -- Quotes, backslashes and dots remain a literal key; numbers render as strings. alter table graph_trace_v2 set 'greptime.semantic.entity.custom.id' = 'scope_attributes.a"b\c.d'; Affected Rows: 0 select entity_type, entity_id from greptime_private.semantic_entities where entity_type = 'custom' and observed_at >= '2026-01-01 00:00:00' and observed_at < '2026-01-01 00:01:00'; +-------------+-----------+ | entity_type | entity_id | +-------------+-----------+ | custom | 7 | +-------------+-----------+ -- Path-looking suffixes are literal keys, not nested traversal or array access. -- These missing keys are valid declarations and produce no entities. alter table graph_trace_v2 set 'greptime.semantic.entity.literal_missing.id' = 'resource_attributes.host..name'; Affected Rows: 0 alter table graph_trace_v2 set 'greptime.semantic.entity.literal_index.id' = 'resource_attributes.host[0]'; Affected Rows: 0 -- The root must exist and be one of the three JSON2 attribute columns. alter table graph_trace_v2 set 'greptime.semantic.entity.invalid.id' = 'span_events.name'; Error: 4002(TableColumnNotFound), Column span_events.name not exists in table graph_trace_v2 alter table graph_trace_v2 set 'greptime.semantic.entity.invalid.id' = 'resource_attributes.'; Error: 4002(TableColumnNotFound), Column resource_attributes. not exists in table graph_trace_v2 alter table graph_trace_v2 set 'greptime.semantic.entity.invalid.id' = 'missing.key'; Error: 4002(TableColumnNotFound), Column missing.key not exists in table graph_trace_v2 alter table graph_trace_v2 set 'greptime.semantic.entity.invalid.id' = 'resource_attributes'; Error: 1004(InvalidArguments), Invalid alter table(graph_trace_v2) request: entity column `resource_attributes` (option `greptime.semantic.entity.invalid.id`) has type `Json2""`, which cannot render as a string create table graph_bad_v2 ( ts timestamp time index, resource_attributes string ) with ('table_data_model' = 'greptime_trace_v2', 'greptime.semantic.entity.host.id' = 'resource_attributes.host.id'); Error: 1004(InvalidArguments), Cannot find column by name: resource_attributes.host.id -- Ordinary JSON2 tables do not acquire Trace V2 attribute-reference semantics. create table graph_not_trace ( ts timestamp time index, resource_attributes json2 ) with ('append_mode' = 'true', 'greptime.semantic.entity.host.id' = 'resource_attributes.host.id'); Error: 1004(InvalidArguments), Cannot find column by name: resource_attributes.host.id -- Physical convention columns win over conflicting JSON2 keys. alter table graph_trace_v2 add column "resource_attributes.host.id" string; Affected Rows: 0 alter table graph_trace_v2 add column "resource_attributes.service.namespace" string; Affected Rows: 0 alter table graph_trace_v2 add column "span_attributes.db.namespace" string; Affected Rows: 0 -- Restore the implicit host declaration for the physical-column check. alter table graph_trace_v2 unset 'greptime.semantic.entity.host.id'; Affected Rows: 0 alter table graph_trace_v2 unset 'greptime.semantic.entity.host.descriptive'; Affected Rows: 0 insert into graph_trace_v2 ("timestamp", duration_nano, trace_id, span_id, span_kind, span_status_code, service_name, resource_attributes, span_attributes, "resource_attributes.host.id", "resource_attributes.service.namespace", "span_attributes.db.namespace") values ('2026-01-01 00:00:04', 100, 'physical', 'physical-client', 'SPAN_KIND_CLIENT', 'STATUS_CODE_UNSET', 'physical-service', '{"host.id":"json-host","service.namespace":"json-namespace"}', '{"db.namespace":"json-database","db":{"namespace":"nested-database"}}', 'physical-host', 'physical-namespace', 'physical-database'); Affected Rows: 1 select entity_type, entity_id from greptime_private.semantic_entities where entity_type in ('host', 'service') and observed_at >= '2026-01-01 00:00:00' and observed_at < '2026-01-01 00:01:00' order by entity_type, entity_id; +-------------+-------------------------------------+ | entity_type | entity_id | +-------------+-------------------------------------+ | host | physical-host | | service | frontend | | service | no-resource | | service | physical-namespace/physical-service | | service | shop/backend | +-------------+-------------------------------------+ select src_id, dst_id, rel_type from greptime_private.semantic_relationships where src_id = 'physical-namespace/physical-service' and observed_at >= '2026-01-01 00:00:00' and observed_at < '2026-01-01 00:01:00' order by rel_type, dst_id; +-------------------------------------+-------------------+----------+ | src_id | dst_id | rel_type | +-------------------------------------+-------------------+----------+ | physical-namespace/physical-service | physical-database | calls | +-------------------------------------+-------------------+----------+ drop table graph_trace_v2; Affected Rows: 0 drop table graph_trace_v1_peer; Affected Rows: 0