55import sys
66from pathlib import Path
77
8+ import os
89from ..utils .logs_server import serve_logs
910
1011
@@ -20,53 +21,76 @@ def logs_command(args):
2021 print ("Press Ctrl+C to stop the server" )
2122 print ("-" * 50 )
2223
23- # Setup Elasticsearch based on flags
24+ # Backend selection: Fireworks first when API key present, unless overridden
25+ use_fireworks = False
26+ if getattr (args , "use_fireworks" , False ):
27+ use_fireworks = True
28+ elif getattr (args , "use_elasticsearch" , False ):
29+ use_fireworks = False
30+ else :
31+ use_fireworks = bool (os .environ .get ("FIREWORKS_API_KEY" ))
32+
33+ # Setup backend configs
2434 elasticsearch_config = None
35+ # Prefer explicit FW_TRACING_GATEWAY_BASE_URL, then GATEWAY_URL from env (remote validation),
36+ # finally default to public tracing.fireworks.ai
37+ fireworks_base_url = (
38+ os .environ .get ("FW_TRACING_GATEWAY_BASE_URL" )
39+ or os .environ .get ("GATEWAY_URL" )
40+ or "https://tracing.fireworks.ai"
41+ )
2542 try :
26- if getattr (args , "use_env_elasticsearch_config" , False ):
27- # Use environment variables for configuration
28- print ("⚙️ Using environment variables for Elasticsearch config" )
29- from eval_protocol .pytest .remote_rollout_processor import (
30- create_elasticsearch_config_from_env ,
31- )
32-
33- elasticsearch_config = create_elasticsearch_config_from_env ()
34- # Ensure index exists with correct mapping, mirroring Docker setup path
35- try :
36- from eval_protocol .log_utils .elasticsearch_index_manager import (
37- ElasticsearchIndexManager ,
43+ if not use_fireworks :
44+ if getattr (args , "use_env_elasticsearch_config" , False ):
45+ # Use environment variables for configuration
46+ print ("⚙️ Using environment variables for Elasticsearch config" )
47+ from eval_protocol .pytest .remote_rollout_processor import (
48+ create_elasticsearch_config_from_env ,
3849 )
3950
40- index_manager = ElasticsearchIndexManager (
41- elasticsearch_config .url ,
42- elasticsearch_config .index_name ,
43- elasticsearch_config .api_key ,
44- )
45- created = index_manager .create_logging_index_mapping ()
46- if created :
47- print (
48- f"🧭 Verified Elasticsearch index '{ elasticsearch_config .index_name } ' mapping (created or already correct)"
51+ elasticsearch_config = create_elasticsearch_config_from_env ()
52+ # Ensure index exists with correct mapping, mirroring Docker setup path
53+ try :
54+ from eval_protocol .log_utils .elasticsearch_index_manager import (
55+ ElasticsearchIndexManager ,
4956 )
50- else :
51- print (
52- f"⚠️ Could not verify/create mapping for index '{ elasticsearch_config .index_name } '. Searches may behave unexpectedly."
57+
58+ index_manager = ElasticsearchIndexManager (
59+ elasticsearch_config .url ,
60+ elasticsearch_config .index_name ,
61+ elasticsearch_config .api_key ,
5362 )
54- except Exception as e :
55- print (f"⚠️ Failed to ensure index mapping via IndexManager: { e } " )
56- elif not getattr (args , "disable_elasticsearch_setup" , False ):
57- # Default behavior: start or connect to local Elasticsearch via Docker helper
58- from eval_protocol .pytest .elasticsearch_setup import ElasticsearchSetup
63+ created = index_manager .create_logging_index_mapping ()
64+ if created :
65+ print (
66+ f"🧭 Verified Elasticsearch index '{ elasticsearch_config .index_name } ' mapping (created or already correct)"
67+ )
68+ else :
69+ print (
70+ f"⚠️ Could not verify/create mapping for index '{ elasticsearch_config .index_name } '. Searches may behave unexpectedly."
71+ )
72+ except Exception as e :
73+ print (f"⚠️ Failed to ensure index mapping via IndexManager: { e } " )
74+ elif not getattr (args , "disable_elasticsearch_setup" , False ):
75+ # Default behavior: start or connect to local Elasticsearch via Docker helper
76+ from eval_protocol .pytest .elasticsearch_setup import ElasticsearchSetup
5977
60- print ("🧰 Auto-configuring local Elasticsearch (Docker)" )
61- elasticsearch_config = ElasticsearchSetup ().setup_elasticsearch ()
62- else :
63- print ("🚫 Elasticsearch setup disabled; running without Elasticsearch integration" )
78+ print ("🧰 Auto-configuring local Elasticsearch (Docker)" )
79+ elasticsearch_config = ElasticsearchSetup ().setup_elasticsearch ()
80+ else :
81+ print ("🚫 Elasticsearch setup disabled; running without Elasticsearch integration" )
6482 except Exception as e :
6583 print (f"❌ Failed to configure Elasticsearch: { e } " )
6684 return 1
6785
6886 try :
69- serve_logs (port = args .port , elasticsearch_config = elasticsearch_config , debug = args .debug )
87+ serve_logs (
88+ port = args .port ,
89+ elasticsearch_config = elasticsearch_config ,
90+ debug = args .debug ,
91+ backend = "fireworks" if use_fireworks else "elasticsearch" ,
92+ fireworks_base_url = fireworks_base_url if use_fireworks else None ,
93+ )
7094 return 0
7195 except KeyboardInterrupt :
7296 print ("\n 🛑 Server stopped by user" )
0 commit comments