Update a record in ClickHouse by deleting and re-inserting it.
(span_id: str, update_data: dict)
| 449 | |
| 450 | |
| 451 | async def clickhouse_update_span(span_id: str, update_data: dict) -> None: |
| 452 | """Update a record in ClickHouse by deleting and re-inserting it.""" |
| 453 | # reasons for going this route at the moment: |
| 454 | # - serialization is a bitch and there is no tooling readily available to help with it |
| 455 | # - latency for propagation of updates is apparently comparable to deletion |
| 456 | |
| 457 | def merge_dicts_recursive(old, new): |
| 458 | result = old.copy() |
| 459 | for key, value in new.items(): |
| 460 | if key in result and isinstance(result[key], dict) and isinstance(value, dict): |
| 461 | result[key] = merge_dicts_recursive(result[key], value) |
| 462 | else: |
| 463 | result[key] = value |
| 464 | return result |
| 465 | |
| 466 | existing_span: dict = await clickhouse_get_span_raw(span_id) |
| 467 | if existing_span: |
| 468 | await clickhouse_delete_span(span_id) # yolo |
| 469 | else: |
| 470 | existing_span = {} |
| 471 | |
| 472 | merged_data = merge_dicts_recursive(existing_span, update_data) |
| 473 | await clickhouse_create( |
| 474 | [ |
| 475 | merged_data, |
| 476 | ] |
| 477 | ) |
| 478 | |
| 479 | |
| 480 | async def write_trace_with_timeout(trace: Trace) -> None: |
no test coverage detected
searching dependent graphs…