45
45
HTTPBasic ,
46
46
HTTPBasicCredentials ,
47
47
)
48
+ from opentelemetry .trace .propagation .tracecontext import TraceContextTextMapPropagator
48
49
from pydantic import BaseModel
49
50
50
51
from ert .config import QueueSystem
77
78
START_EXPERIMENT_ENDPOINT ,
78
79
STOP_ENDPOINT ,
79
80
)
81
+ from everest .trace import tracer , tracer_provider
80
82
from everest .util import makedirs_if_needed , version_info
81
83
82
84
@@ -424,13 +426,40 @@ def make_handler_config(
424
426
}
425
427
426
428
logging .config .dictConfig (logging_config )
427
- EverestPluginManager ().add_log_handle_to_root ()
429
+ plugin_manager = EverestPluginManager ()
430
+ plugin_manager .add_log_handle_to_root ()
431
+ plugin_manager .add_span_processor_to_trace_provider (tracer_provider )
432
+
433
+
434
+ def get_trace_context ():
435
+ arg_parser = argparse .ArgumentParser ()
436
+ arg_parser .add_argument (
437
+ "--traceparent" ,
438
+ type = str ,
439
+ help = "Trace parent id to be used by the storage root span" ,
440
+ default = None ,
441
+ )
442
+ options = arg_parser .parse_args ()
443
+ ctx = (
444
+ TraceContextTextMapPropagator ().extract (
445
+ carrier = {"traceparent" : options .traceparent }
446
+ )
447
+ if options .traceparent
448
+ else None
449
+ )
450
+ return ctx
428
451
429
452
430
453
def main () -> None :
431
454
arg_parser = argparse .ArgumentParser ()
432
455
arg_parser .add_argument ("--output-dir" , "-o" , type = str )
433
456
arg_parser .add_argument ("--logging-level" , "-l" , type = int , default = logging .INFO )
457
+ arg_parser .add_argument (
458
+ "--traceparent" ,
459
+ type = str ,
460
+ help = "Trace parent id to be used by the storage root span" ,
461
+ default = None ,
462
+ )
434
463
options = arg_parser .parse_args ()
435
464
436
465
output_dir = options .output_dir
@@ -441,77 +470,86 @@ def main() -> None:
441
470
host_file = ServerConfig .get_hostfile_path (output_dir )
442
471
msg_queue : SimpleQueue [EverestServerMsg ] = SimpleQueue ()
443
472
444
- try :
445
- _configure_loggers (
446
- detached_dir = Path (ServerConfig .get_detached_node_dir (output_dir )),
447
- log_dir = Path (output_dir ) / OPTIMIZATION_LOG_DIR ,
448
- logging_level = logging_level ,
473
+ ctx = (
474
+ TraceContextTextMapPropagator ().extract (
475
+ carrier = {"traceparent" : options .traceparent }
449
476
)
477
+ if options .traceparent
478
+ else None
479
+ )
450
480
451
- update_everserver_status (status_path , ServerStatus .starting )
452
- logging .getLogger (EVEREST ).info (version_info ())
453
- logging .getLogger (EVEREST ).info (f"Output directory: { output_dir } " )
481
+ with tracer .start_as_current_span ("everest.server" , context = ctx ):
482
+ try :
483
+ _configure_loggers (
484
+ detached_dir = Path (ServerConfig .get_detached_node_dir (output_dir )),
485
+ log_dir = Path (output_dir ) / OPTIMIZATION_LOG_DIR ,
486
+ logging_level = logging_level ,
487
+ )
454
488
455
- authentication = _generate_authentication ()
456
- cert_path , key_path , key_pw = _generate_certificate (
457
- ServerConfig .get_certificate_dir (output_dir )
458
- )
459
- host = _get_machine_name ()
460
- port = _find_open_port (host , lower = 5000 , upper = 5800 )
461
- _write_hostfile (host_file , host , port , cert_path , authentication )
462
-
463
- shared_data = {
464
- STOP_ENDPOINT : False ,
465
- "started" : False ,
466
- "events" : [],
467
- "subscribers" : {},
468
- }
489
+ update_everserver_status (status_path , ServerStatus .starting )
490
+ logging .getLogger (EVEREST ).info (version_info ())
491
+ logging .getLogger (EVEREST ).info (f"Output directory: { output_dir } " )
469
492
470
- server_config = {
471
- "optimization_output_dir" : optimization_output_dir ,
472
- "port" : port ,
473
- "cert_path" : cert_path ,
474
- "key_path" : key_path ,
475
- "key_passwd" : key_pw ,
476
- "authentication" : authentication ,
477
- }
478
- # Starting the server
479
- everserver_instance = threading .Thread (
480
- target = _everserver_thread ,
481
- args = (shared_data , server_config , msg_queue ),
482
- )
483
- everserver_instance .daemon = True
484
- everserver_instance .start ()
493
+ authentication = _generate_authentication ()
494
+ cert_path , key_path , key_pw = _generate_certificate (
495
+ ServerConfig .get_certificate_dir (output_dir )
496
+ )
497
+ host = _get_machine_name ()
498
+ port = _find_open_port (host , lower = 5000 , upper = 5800 )
499
+ _write_hostfile (host_file , host , port , cert_path , authentication )
500
+
501
+ shared_data = {
502
+ STOP_ENDPOINT : False ,
503
+ "started" : False ,
504
+ "events" : [],
505
+ "subscribers" : {},
506
+ }
507
+
508
+ server_config = {
509
+ "optimization_output_dir" : optimization_output_dir ,
510
+ "port" : port ,
511
+ "cert_path" : cert_path ,
512
+ "key_path" : key_path ,
513
+ "key_passwd" : key_pw ,
514
+ "authentication" : authentication ,
515
+ }
516
+ # Starting the server
517
+ everserver_instance = threading .Thread (
518
+ target = _everserver_thread ,
519
+ args = (shared_data , server_config , msg_queue ),
520
+ )
521
+ everserver_instance .daemon = True
522
+ everserver_instance .start ()
485
523
486
- # Monitoring the server
487
- while True :
488
- try :
489
- item = msg_queue .get (timeout = 1 ) # Wait for data
490
- match item :
491
- case ServerStarted ():
492
- update_everserver_status (status_path , ServerStatus .running )
493
- case ServerStopped ():
494
- update_everserver_status (status_path , ServerStatus .stopped )
495
- return
496
- case ExperimentFailed ():
497
- update_everserver_status (
498
- status_path , ServerStatus .failed , item .msg
499
- )
500
- return
501
- case ExperimentComplete ():
502
- status , message = _get_optimization_status (
503
- item .exit_code , item .data
504
- )
505
- update_everserver_status (status_path , status , message )
506
- return
507
- except Empty :
508
- continue
509
- except :
510
- update_everserver_status (
511
- status_path ,
512
- ServerStatus .failed ,
513
- message = traceback .format_exc (),
514
- )
524
+ # Monitoring the server
525
+ while True :
526
+ try :
527
+ item = msg_queue .get (timeout = 1 ) # Wait for data
528
+ match item :
529
+ case ServerStarted ():
530
+ update_everserver_status (status_path , ServerStatus .running )
531
+ case ServerStopped ():
532
+ update_everserver_status (status_path , ServerStatus .stopped )
533
+ return
534
+ case ExperimentFailed ():
535
+ update_everserver_status (
536
+ status_path , ServerStatus .failed , item .msg
537
+ )
538
+ return
539
+ case ExperimentComplete ():
540
+ status , message = _get_optimization_status (
541
+ item .exit_code , item .data
542
+ )
543
+ update_everserver_status (status_path , status , message )
544
+ return
545
+ except Empty :
546
+ continue
547
+ except :
548
+ update_everserver_status (
549
+ status_path ,
550
+ ServerStatus .failed ,
551
+ message = traceback .format_exc (),
552
+ )
515
553
516
554
517
555
def _get_optimization_status (
0 commit comments