Beispiel #1
0
        public BTracingServiceZipkin(BLoggingServiceLoggerZipkin _Logger, string _ProgramUniqueID, string _ZipkinServerIP, int _ZipkinServerPort, Action <string> _ErrorMessageAction)
        {
            ProgramUniqueID = _ProgramUniqueID;
            try
            {
                TraceManager.SamplingRate = 1.0f;

                var HttpSender = new HttpZipkinSender("http://" + _ZipkinServerIP + ":" + _ZipkinServerPort, "application/json");
                var Tracer     = new ZipkinTracer(HttpSender, new JSONSpanSerializer());

                TraceManager.RegisterTracer(Tracer);
                bInitializationSucceed = TraceManager.Start(_Logger);
            }
            catch (Exception e)
            {
                bInitializationSucceed = false;
                _ErrorMessageAction?.Invoke("BTracingServiceZipkin->Constructor: " + e.Message + ", Trace: " + e.StackTrace);
            }
        }
Beispiel #2
0
        public bool WithTracingService()
        {
            /*
             * Tracing service initialization
             */
            if (!RequiredEnvironmentVariables.ContainsKey("ZIPKIN_SERVER_IP") ||
                !RequiredEnvironmentVariables.ContainsKey("ZIPKIN_SERVER_PORT"))
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "ZIPKIN_SERVER_IP, ZIPKIN_SERVER_PORT parameters must be provided and valid."), ProgramID, "Initialization");
                return(false);
            }

            var LoggingServiceLogger = new BLoggingServiceLoggerZipkin(
                LoggingService,
                PreLoggingServiceLogger,
                ProgramID);

            if (!int.TryParse(RequiredEnvironmentVariables["ZIPKIN_SERVER_PORT"], out int ZipkinServerPort))
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Given zipkin server port is invalid."), ProgramID, "Initialization");
                return(false);
            }

            TracingService = new BTracingServiceZipkin(
                LoggingServiceLogger,
                ProgramID,
                RequiredEnvironmentVariables["ZIPKIN_SERVER_IP"],
                ZipkinServerPort,
                (string Message) =>
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, Message), ProgramID, "Initialization");
            });

            if (TracingService == null || !TracingService.HasInitializationSucceed())
            {
                LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Critical, "Tracing service initialization has failed."), ProgramID, "Initialization");
                return(false);
            }

            return(true);
        }