예제 #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));
            }
예제 #2
0
 public void Inject <TCarrier>(ISpanContext spanContext, IFormat <TCarrier> format, TCarrier carrier)
 {
     PropagationRegistry.Inject(spanContext, format, carrier);
 }
예제 #3
0
 public ISpanContext Extract <TCarrier>(IFormat <TCarrier> format, TCarrier carrier)
 {
     return(PropagationRegistry.Extract(format, carrier));
 }
예제 #4
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;
        }