Exemple #1
0
            public Tracer Build()
            {
                if (_loggerFactory == null)
                {
                    _loggerFactory = NullLoggerFactory.Instance;
                }

                _registry = new PropagationRegistry(_loggerFactory);
                foreach (var configureRegistry in _registryActions)
                {
                    configureRegistry(_registry);
                }

                if (_metrics == null)
                {
                    _metrics = new MetricsImpl(NoopMetricsFactory.Instance);
                }

                if (_reporter == null)
                {
                    _reporter = new RemoteReporter.Builder()
                                .WithLoggerFactory(_loggerFactory)
                                .WithMetrics(_metrics)
                                .Build();
                }
                if (_sampler == null)
                {
                    _sampler = new RemoteControlledSampler.Builder(_serviceName)
                               .WithLoggerFactory(_loggerFactory)
                               .WithMetrics(_metrics)
                               .Build();
                }

                return(new Tracer(_serviceName, _reporter, _sampler, _registry, _clock, _metrics, _loggerFactory,
                                  _tags, _zipkinSharedRpcSpan, _scopeManager, _baggageRestrictionManager, _expandExceptionLogs));
            }
Exemple #2
0
            public Tracer Build()
            {
                if (LoggerFactory == null)
                {
                    LoggerFactory = NullLoggerFactory.Instance;
                }

                _registry = new PropagationRegistry(LoggerFactory);
                foreach (var configureRegistry in _registryActions)
                {
                    configureRegistry(_registry);
                }

                if (Metrics == null)
                {
                    Metrics = new MetricsImpl(NoopMetricsFactory.Instance);
                }

                if (Reporter == null)
                {
                    Reporter = new RemoteReporter.Builder()
                               .WithLoggerFactory(LoggerFactory)
                               .WithMetrics(Metrics)
                               .Build();
                }
                if (Sampler == null)
                {
                    Sampler = new RemoteControlledSampler.Builder(ServiceName)
                              .WithLoggerFactory(LoggerFactory)
                              .WithMetrics(Metrics)
                              .Build();
                }

                return(new Tracer(ServiceName, Reporter, Sampler, _registry, Clock, Metrics, LoggerFactory,
                                  _tags, ZipkinSharedRpcSpan, ScopeManager, BaggageRestrictionManager, ExpandExceptionLogs, UseTraceId128Bit));
            }
Exemple #3
0
        private Tracer(
            string serviceName,
            IReporter reporter,
            ISampler sampler,
            PropagationRegistry registry,
            IClock clock,
            IMetrics metrics,
            ILoggerFactory loggerFactory,
            Dictionary <string, object> tags,
            bool zipkinSharedRpcSpan,
            IScopeManager scopeManager,
            IBaggageRestrictionManager baggageRestrictionManager,
            bool expandExceptionLogs)
        {
            ServiceName         = serviceName;
            Reporter            = reporter;
            Sampler             = sampler;
            Registry            = registry;
            Clock               = clock;
            Metrics             = metrics;
            Logger              = loggerFactory.CreateLogger <Tracer>();
            ZipkinSharedRpcSpan = zipkinSharedRpcSpan;
            ScopeManager        = scopeManager;
            _baggageSetter      = new BaggageSetter(baggageRestrictionManager, metrics);
            ExpandExceptionLogs = expandExceptionLogs;

            Version = LoadVersion();
            tags[Constants.JaegerClientVersionTagKey] = Version;

            string hostname = GetHostName();

            if (!tags.ContainsKey(Constants.TracerHostnameTagKey))
            {
                if (hostname != null)
                {
                    tags[Constants.TracerHostnameTagKey] = hostname;
                }
            }

            if (tags.TryGetValue(Constants.TracerIpTagKey, out object ipTag))
            {
                try
                {
                    IPv4 = Utils.IpToInt(ipTag as string);
                }
                catch
                {
                }
            }
            else
            {
                try
                {
                    IPAddress hostIPv4 = Dns.GetHostAddresses(hostname).First(ip => ip.AddressFamily == AddressFamily.InterNetwork);

                    tags[Constants.TracerIpTagKey] = hostIPv4.ToString();
                    IPv4 = Utils.IpToInt(hostIPv4);
                }
                catch
                {
                }
            }

            Tags = tags;
        }