backfilled data¶
When Logfire fails to send logs to the server, it dumps the data to disk to avoid data loss.
Logfire supports bulk loading of data, either importing data from other systems or loading data that has been dumped to disk.
To backfill data, you can use the logfire 回填 command:
$ logfire backfill--help
By default,logfire backfill will read from the default fallback file, so if you're just trying to upload data after a network failure, you can run:
$ logfire backfill
Batch loading data¶
The same mechanism can also be used for bulk loading of data, for example, if you import data from another system.
First create a dump file:
from datetime import datetime
from logfire.backfill import Log, PrepareBackfill, StartSpan
with PrepareBackfill('logfire_spans123.bin') as backfill:
span = StartSpan(
start_timestamp=datetime(2023, 1, 1, 0, 0, 0),
span_name='session',
msg_template='session {user_id=} {path=}',
service_name='docs.pydantic.dev',
log_attributes={'user_id': '123', 'path': '/test'},
)
child = StartSpan(
start_timestamp=datetime(2023, 1, 1, 0, 0, 1),
span_name='query',
msg_template='ran db query',
service_name='docs.pydantic.dev',
log_attributes={'query': 'SELECT * FROM users'},
parent=span,
)
backfill.write(
Log(
timestamp=datetime(2023, 1, 1, 0, 0, 2),
msg_template='GET {path=}',
level='info',
service_name='docs.pydantic.dev',
attributes={'path': '/test'},
)
)
backfill.write(child.end(end_timestamp=datetime(2023, 1, 1, 0, 0, 3)))
backfill.write(span.end(end_timestamp=datetime(2023, 1, 1, 0, 0, 4)))
This will create a file containing the data 的logfire_spans123.bin in the document.
Then load it using the 回填 command-line tool:
$ logfire backfill --file logfire_spans123.bin
本文总阅读量次