Ejemplo n.º 1
0
        private static IStatsd CreateDogStatsdClient(TracerSettings settings, string serviceName, int port)
        {
            try
            {
                var frameworkDescription = FrameworkDescription.Create();

                var constantTags = new List <string>
                {
                    "lang:.NET",
                    $"lang_interpreter:{frameworkDescription.Name}",
                    $"lang_version:{frameworkDescription.ProductVersion}",
                    $"tracer_version:{TracerConstants.AssemblyVersion}",
                    $"service:{serviceName}"
                };

                if (settings.Environment != null)
                {
                    constantTags.Add($"env:{settings.Environment}");
                }

                if (settings.Environment != null)
                {
                    constantTags.Add($"version:{settings.ServiceVersion}");
                }

                var statsdUdp = new StatsdUDP(settings.AgentUri.DnsSafeHost, port, StatsdConfig.DefaultStatsdMaxUDPPacketSize);
                return(new Statsd(statsdUdp, new RandomGenerator(), new StopWatchFactory(), prefix: string.Empty, constantTags.ToArray()));
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"Unable to instantiate {nameof(Statsd)} client.");
                return(new NoOpStatsd());
            }
        }
Ejemplo n.º 2
0
        private static IStatsd CreateDogStatsdClient(TracerSettings settings)
        {
            var frameworkDescription = FrameworkDescription.Create();

            string[] constantTags =
            {
                "lang:.NET",
                $"lang_interpreter:{frameworkDescription.Name}",
                $"lang_version:{frameworkDescription.ProductVersion}",
                $"tracer_version:{TracerConstants.AssemblyVersion}"
            };

            var statsdUdp = new StatsdUDP(settings.AgentUri.DnsSafeHost, settings.DogStatsdPort, StatsdConfig.DefaultStatsdMaxUDPPacketSize);

            return(new Statsd(statsdUdp, new RandomGenerator(), new StopWatchFactory(), prefix: string.Empty, constantTags));
        }
Ejemplo n.º 3
0
        private static IDogStatsd CreateDogStatsdClient(TracerSettings settings, string serviceName, int port)
        {
            try
            {
                var frameworkDescription = FrameworkDescription.Create();

                var constantTags = new List <string>
                {
                    "lang:.NET",
                    $"lang_interpreter:{frameworkDescription.Name}",
                    $"lang_version:{frameworkDescription.ProductVersion}",
                    $"tracer_version:{TracerConstants.AssemblyVersion}",
                    $"service:{serviceName}"
                };

                if (settings.Environment != null)
                {
                    constantTags.Add($"env:{settings.Environment}");
                }

                if (settings.ServiceVersion != null)
                {
                    constantTags.Add($"version:{settings.ServiceVersion}");
                }

                var statsd = new DogStatsdService();
                statsd.Configure(new StatsdConfig
                {
                    StatsdServerName = settings.AgentUri.DnsSafeHost,
                    StatsdPort       = port,
                    ConstantTags     = constantTags.ToArray()
                });

                return(statsd);
            }
            catch (Exception ex)
            {
                Log.SafeLogError(ex, $"Unable to instantiate {nameof(Statsd)} client.");
                return(new NoOpStatsd());
            }
        }
Ejemplo n.º 4
0
        internal async Task WriteDiagnosticLog()
        {
            string agentError = null;

            try
            {
                var success = await _agentWriter.Ping().ConfigureAwait(false);

                if (!success)
                {
                    agentError = "An error occurred while sending traces to the agent";
                }
            }
            catch (Exception ex)
            {
                agentError = ex.Message;
            }

            try
            {
                var frameworkDescription = FrameworkDescription.Create();

                var stringWriter = new StringWriter();

                using (var writer = new JsonTextWriter(stringWriter))
                {
                    writer.WriteStartObject();

                    writer.WritePropertyName("date");
                    writer.WriteValue(DateTime.Now);

                    writer.WritePropertyName("os_name");
                    writer.WriteValue(frameworkDescription.OSPlatform);

                    writer.WritePropertyName("os_version");
                    writer.WriteValue(Environment.OSVersion.ToString());

                    writer.WritePropertyName("version");
                    writer.WriteValue(typeof(Tracer).Assembly.GetName().Version.ToString());

                    writer.WritePropertyName("platform");
                    writer.WriteValue(frameworkDescription.ProcessArchitecture);

                    writer.WritePropertyName("lang");
                    writer.WriteValue(frameworkDescription.Name);

                    writer.WritePropertyName("lang_version");
                    writer.WriteValue(frameworkDescription.ProductVersion);

                    writer.WritePropertyName("env");
                    writer.WriteValue(Settings.Environment);

                    writer.WritePropertyName("enabled");
                    writer.WriteValue(Settings.TraceEnabled);

                    writer.WritePropertyName("service");
                    writer.WriteValue(DefaultServiceName);

                    writer.WritePropertyName("agent_url");
                    writer.WriteValue(Settings.AgentUri);

                    writer.WritePropertyName("debug");
                    writer.WriteValue(GlobalSettings.Source.DebugEnabled);

                    writer.WritePropertyName("analytics_enabled");
                    writer.WriteValue(Settings.AnalyticsEnabled);

                    writer.WritePropertyName("sample_rate");
                    writer.WriteValue(Settings.GlobalSamplingRate);

                    writer.WritePropertyName("sampling_rules");
                    writer.WriteValue(Settings.CustomSamplingRules);

                    writer.WritePropertyName("tags");

                    writer.WriteStartArray();

                    foreach (var entry in Settings.GlobalTags)
                    {
                        writer.WriteValue(string.Concat(entry.Key, ":", entry.Value));
                    }

                    writer.WriteEndArray();

                    writer.WritePropertyName("log_injection_enabled");
                    writer.WriteValue(Settings.LogsInjectionEnabled);

                    writer.WritePropertyName("runtime_metrics_enabled");
                    writer.WriteValue(Settings.TracerMetricsEnabled);

                    writer.WritePropertyName("disabled_integrations");
                    writer.WriteStartArray();

                    foreach (var integration in Settings.DisabledIntegrationNames)
                    {
                        writer.WriteValue(integration);
                    }

                    writer.WriteEndArray();

                    writer.WritePropertyName("netstandard_enabled");
                    writer.WriteValue(Settings.IsNetStandardFeatureFlagEnabled());

                    writer.WritePropertyName("agent_reachable");
                    writer.WriteValue(agentError == null);

                    writer.WritePropertyName("agent_error");
                    writer.WriteValue(agentError ?? string.Empty);

                    writer.WriteEndObject();
                }

                Log.Information("DATADOG TRACER CONFIGURATION - {0}", stringWriter.ToString());
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "DATADOG TRACER DIAGNOSTICS - Error fetching configuration");
            }
        }