mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
feat: support pre-setting instance_id via LANGBOT__INSTANCE_ID env var
In SaaS (cloud edition), the instance_id can now be injected via environment variable to match the pod UUID. This enables zero-lookup telemetry routing in Space - no need to reverse-lookup instance_id to find the pod.
This commit is contained in:
@@ -146,14 +146,29 @@ class LoadConfigStage(stage.BootingStage):
|
|||||||
await ap.instance_config.dump_config()
|
await ap.instance_config.dump_config()
|
||||||
|
|
||||||
# load or generate instance id
|
# load or generate instance id
|
||||||
ap.instance_id = await config.load_json_config(
|
# In SaaS (cloud edition), the instance id can be pre-set via LANGBOT__INSTANCE_ID
|
||||||
'data/labels/instance_id.json',
|
# environment variable to match the pod UUID, enabling zero-lookup telemetry routing.
|
||||||
template_data={
|
env_instance_id = os.environ.get('LANGBOT__INSTANCE_ID')
|
||||||
'instance_id': f'instance_{str(uuid.uuid4())}',
|
if env_instance_id:
|
||||||
'instance_create_ts': int(time.time()),
|
ap.instance_id = await config.load_json_config(
|
||||||
},
|
'data/labels/instance_id.json',
|
||||||
completion=False,
|
template_data={
|
||||||
)
|
'instance_id': env_instance_id,
|
||||||
|
'instance_create_ts': int(time.time()),
|
||||||
|
},
|
||||||
|
completion=False,
|
||||||
|
)
|
||||||
|
# Override with env value even if file already existed with a different id
|
||||||
|
ap.instance_id.data['instance_id'] = env_instance_id
|
||||||
|
else:
|
||||||
|
ap.instance_id = await config.load_json_config(
|
||||||
|
'data/labels/instance_id.json',
|
||||||
|
template_data={
|
||||||
|
'instance_id': f'instance_{str(uuid.uuid4())}',
|
||||||
|
'instance_create_ts': int(time.time()),
|
||||||
|
},
|
||||||
|
completion=False,
|
||||||
|
)
|
||||||
|
|
||||||
constants.instance_id = ap.instance_id.data['instance_id']
|
constants.instance_id = ap.instance_id.data['instance_id']
|
||||||
constants.edition = ap.instance_config.data.get('system', {}).get('edition', 'community')
|
constants.edition = ap.instance_config.data.get('system', {}).get('edition', 'community')
|
||||||
|
|||||||
Reference in New Issue
Block a user