public RuntimeEventListener(IDogStatsd statsd, TimeSpan delay) { _statsd = statsd; _delayInSeconds = ((int)delay.TotalSeconds).ToString(); EventSourceCreated += (_, e) => EnableEventSource(e.EventSource); }
private static IImmutableList <MockSpan> SendSpan(bool tracerMetricsEnabled, IDogStatsd statsd) { IImmutableList <MockSpan> spans; var agentPort = TcpPortProvider.GetOpenPort(); using (var agent = new MockTracerAgent(agentPort)) { var settings = new TracerSettings { Exporter = new ExporterSettings() { AgentUri = new Uri($"http://127.0.0.1:{agent.Port}"), }, TracerMetricsEnabled = tracerMetricsEnabled, StartupDiagnosticLogEnabled = false, }; var tracer = new Tracer(settings, agentWriter: null, sampler: null, scopeManager: null, statsd); using (var scope = tracer.StartActive("root")) { scope.Span.ResourceName = "resource"; Thread.Sleep(5); } spans = agent.WaitForSpans(1); } return(spans); }
public ModerationService( IDiscordClient discordClient, IAuthorizationService authorizationService, IChannelService channelService, IUserService userService, IModerationActionRepository moderationActionRepository, IDesignatedRoleMappingRepository designatedRoleMappingRepository, IInfractionRepository infractionRepository, IDeletedMessageRepository deletedMessageRepository, IDeletedMessageBatchRepository deletedMessageBatchRepository, IRoleService roleService, IDesignatedChannelService designatedChannelService, IDogStatsd dogStatsd) { _discordClient = discordClient; _authorizationService = authorizationService; _channelService = channelService; _userService = userService; _moderationActionRepository = moderationActionRepository; _designatedRoleMappingRepository = designatedRoleMappingRepository; _infractionRepository = infractionRepository; _deletedMessageRepository = deletedMessageRepository; _deletedMessageBatchRepository = deletedMessageBatchRepository; _roleService = roleService; _designatedChannelService = designatedChannelService; _dogStatsd = dogStatsd; }
/// <summary> /// Creates a new <see cref="ModerationService"/>, with the given injected dependencies. /// </summary> public ModerationService( IDiscordClient discordClient, IAuthorizationService authorizationService, IChannelService channelService, IUserService userService, IModerationActionRepository moderationActionRepository, IDesignatedRoleMappingRepository designatedRoleMappingRepository, IInfractionRepository infractionRepository, IDeletedMessageRepository deletedMessageRepository, IDeletedMessageBatchRepository deletedMessageBatchRepository, IRoleService roleService, IDesignatedChannelService designatedChannelService, IDogStatsd stats = null) { DiscordClient = discordClient; AuthorizationService = authorizationService; ChannelService = channelService; UserService = userService; ModerationActionRepository = moderationActionRepository; DesignatedRoleMappingRepository = designatedRoleMappingRepository; InfractionRepository = infractionRepository; DeletedMessageRepository = deletedMessageRepository; DeletedMessageBatchRepository = deletedMessageBatchRepository; RoleService = roleService; DesignatedChannelService = designatedChannelService; Stats = stats; }
public DataDogMetricsPublisher(IDogStatsd dogStatsdService, StatsdConfig config) { this.dogStatsdService = dogStatsdService ?? throw new ArgumentNullException(nameof(dogStatsdService)); dogStatsdService.Configure(config ?? throw new ArgumentNullException(nameof(config))); }
public AgentWriter(IApi api, IDogStatsd statsd, bool automaticFlush = true, int queueSize = 1000) { _tracesBuffer = new AgentWriterBuffer <Span[]>(queueSize); _api = api; _statsd = statsd; _flushTask = automaticFlush ? Task.Run(FlushTracesTaskLoopAsync) : Task.FromResult(true); }
public Api(Uri baseEndpoint, IApiRequestFactory apiRequestFactory, IDogStatsd statsd) { Log.Debug("Creating new Api"); _tracesEndpoint = new Uri(baseEndpoint, TracesPath); _statsd = statsd; _containerId = ContainerMetadata.GetContainerId(); _apiRequestFactory = apiRequestFactory ?? CreateRequestFactory(); }
public MessageLogBehavior(DiscordSocketClient discordClient, ILogger <MessageLogBehavior> logger, IServiceProvider serviceProvider, IDogStatsd stats) : base(serviceProvider) { _discordClient = discordClient; Log = logger; _stats = stats; }
/// <summary> /// Constructs a new <see cref="DiscordSocketListeningBehavior"/> with the given dependencies. /// </summary> public DiscordSocketListeningBehavior( IDiscordSocketClient discordSocketClient, IMessageDispatcher messageDispatcher, IDogStatsd stats = null) { DiscordSocketClient = discordSocketClient; MessageDispatcher = messageDispatcher; _stats = stats; }
/// <summary> /// Create a test instance of the Tracer, that doesn't used any shared instances /// </summary> public static Tracer Create( TracerSettings settings = null, IAgentWriter agentWriter = null, ISampler sampler = null, IScopeManager scopeManager = null, IDogStatsd statsd = null) { return(new Tracer(settings, agentWriter, sampler, scopeManager, statsd)); }
private static IRuntimeMetricsListener InitializeListener(IDogStatsd statsd, TimeSpan delay) { #if NETCOREAPP return(new RuntimeEventListener(statsd, delay)); #elif NETFRAMEWORK return(AzureAppServices.Metadata.IsRelevant ? new AzureAppServicePerformanceCounters(statsd) : new PerformanceCountersListener(statsd)); #else return(null); #endif }
private static IRuntimeMetricsListener InitializeListener(IDogStatsd statsd, TimeSpan delay) { #if NETCOREAPP return(new RuntimeEventListener(statsd, delay)); #elif NETFRAMEWORK return(new PerformanceCountersListener(statsd)); #else return(null); #endif }
public UserMetricsBehavior( IDesignatedChannelService designatedChannelService, IDesignatedRoleService designatedRoleService, IDogStatsd dogStatsd, ILogger <UserMetricsBehavior> logger) { _designatedChannelService = designatedChannelService; _designatedRoleService = designatedRoleService; _dogStatsd = dogStatsd; _logger = logger; }
public MessageTrackingBehavior( ICommandPrefixParser commandPrefixParser, IDogStatsd dogStatsd, ILogger <MessageTrackingBehavior> logger, IMessageRepository messageRepository) { _commandPrefixParser = commandPrefixParser; _dogStatsd = dogStatsd; _logger = logger; _messageRepository = messageRepository; }
public PerformanceCountersListener(IDogStatsd statsd) { _statsd = statsd; ProcessHelpers.GetCurrentProcessInformation(out _processName, out _, out _processId); // To prevent a potential deadlock when hosted in a service, performance counter initialization must be asynchronous // That's because performance counters may rely on wmiApSrv being started, // and the windows service manager only allows one service at a time to be starting: https://docs.microsoft.com/en-us/windows/win32/services/service-startup _initializationTask = Task.Run(InitializePerformanceCounters); }
public StatsBehavior( DiscordSocketClient discordClient, IDogStatsd stats, ILogger <StatsBehavior> log, IServiceProvider serviceProvider) : base(serviceProvider) { _discordClient = discordClient; _stats = stats; _log = log; }
protected override TracerManager CreateTracerManagerFrom( ImmutableTracerSettings settings, IAgentWriter agentWriter, ISampler sampler, IScopeManager scopeManager, IDogStatsd statsd, RuntimeMetricsWriter runtimeMetrics, DirectLogSubmissionManager logSubmissionManager, ITelemetryController telemetry, string defaultServiceName) { return(new CITracerManager(settings, agentWriter, sampler, scopeManager, statsd, runtimeMetrics, logSubmissionManager, telemetry, defaultServiceName)); }
public TrackingResponder( IDogStatsd dogStatsd, ILogger <TrackingResponder> logger, IMessageRepository messageRepository, IChannelService channelService, IThreadService threadSvc ) { _dogStatsd = dogStatsd; _logger = logger; _messageRepository = messageRepository; _channelService = channelService; _threadService = threadSvc; }
public static void Warning(this IDogStatsd statsd, string source, string message, string[] tags = null) { if (statsd != null) { string[] warningTags = { $"source:{source}", $"message:{message}" }; string[] allTags = warningTags.Concat(tags ?? Enumerable.Empty <string>()).ToArray(); statsd.Counter(TracerMetricNames.Health.Warnings, value: 1, sampleRate: 1, allTags); } }
private List <string> ReceiveData(IDogStatsd dogStatsdInstance, string testServerName, int testPort, Action sendData) { using (var udpListener = new UdpListener(testServerName, testPort)) { var listenThread = new Thread(udpListener.ListenAndWait); listenThread.Start(); sendData(); udpListener.Shutdown(); listenThread.Join(); return(udpListener.GetAndClearLastMessages()); } }
/// <summary> /// Constructs a new <see cref="CommandListeningBehavior"/>, with the given dependencies. /// </summary> public CommandListeningBehavior( IServiceProvider serviceProvider, CommandService commandService, CommandErrorHandler commandErrorHandler, IDiscordClient discordClient, IAuthorizationService authorizationService, IDogStatsd stats = null) { ServiceProvider = serviceProvider; CommandService = commandService; CommandErrorHandler = commandErrorHandler; DiscordClient = discordClient; AuthorizationService = authorizationService; _stats = stats; }
public PerformanceCountersListener(IDogStatsd statsd) { _statsd = statsd; ProcessHelpers.GetCurrentProcessInformation(out _processName, out _, out _processId); _memoryCategory = new PerformanceCounterCategory(MemoryCategoryName); var instanceName = GetInstanceName(); _fullInstanceName = instanceName.Item2; _instanceName = instanceName.Item1; InitializePerformanceCounters(_instanceName); }
public static void Exception(this IDogStatsd statsd, Exception exception, string source, string message, string[] tags = null) { if (statsd != null) { string[] exceptionTags = { $"source:{source}", $"message:{message}", $"exception-type:{exception.GetType().FullName}", $"exception-message:{exception.Message}", }; string[] allTags = exceptionTags.Concat(tags ?? Enumerable.Empty <string>()).ToArray(); statsd.Counter(TracerMetricNames.Health.Exceptions, value: 1, sampleRate: 1, allTags); } }
private List <string> ReceiveData(IDogStatsd dogStatsdInstance, string testServerName, int testPort, Action sendData) { using (var udpListener = new UdpListener(testServerName, testPort)) { var listenThread = new Thread(udpListener.Listen); listenThread.Start(); sendData(); while (listenThread.IsAlive) { ; } return(udpListener.GetAndClearLastMessages()); } }
private static ITraceWriter CreateTraceWriter(TracerSettings settings, IDogStatsd statsd) { IMetrics metrics = statsd != null ? new DogStatsdMetrics(statsd) : new NullMetrics(); switch (settings.Exporter) { case ExporterType.Zipkin: return(new ExporterWriter(new ZipkinExporter(settings.AgentUri), metrics)); case ExporterType.Jaeger: return(new ExporterWriter(new JaegerExporter(JaegerOptions.FromTracerSettings(settings)), metrics)); default: return(new AgentWriter(new Api(settings.AgentUri, TransportStrategy.Get(settings), statsd), metrics, maxBufferSize: settings.TraceBufferSize)); } }
public Api( IApiRequestFactory apiRequestFactory, IDogStatsd statsd, Action <Dictionary <string, float> > updateSampleRates, bool isPartialFlushEnabled, IDatadogLogger log = null) { // optionally injecting a log instance in here for testing purposes _log = log ?? StaticLog; _log.Debug("Creating new Api"); _updateSampleRates = updateSampleRates; _statsd = statsd; _containerId = ContainerMetadata.GetContainerId(); _apiRequestFactory = apiRequestFactory; _isPartialFlushEnabled = isPartialFlushEnabled; _tracesEndpoint = _apiRequestFactory.GetEndpoint(TracesPath); _log.Debug("Using traces endpoint {TracesEndpoint}", _tracesEndpoint.ToString()); }
internal AgentWriter(IApi api, IDogStatsd statsd, IKeepRateCalculator traceKeepRateCalculator, bool automaticFlush, int maxBufferSize, int batchInterval) { _api = api; _statsd = statsd; _batchInterval = batchInterval; _traceKeepRateCalculator = traceKeepRateCalculator; var formatterResolver = SpanFormatterResolver.Instance; _forceFlush = new TaskCompletionSource <bool>(TaskOptions); _frontBuffer = new SpanBuffer(maxBufferSize, formatterResolver); _backBuffer = new SpanBuffer(maxBufferSize, formatterResolver); _activeBuffer = _frontBuffer; _serializationTask = automaticFlush ? Task.Factory.StartNew(SerializeTracesLoop, TaskCreationOptions.LongRunning) : Task.FromResult(true); _serializationTask.ContinueWith(t => Log.Error(t.Exception, "Error in serialization task"), TaskContinuationOptions.OnlyOnFaulted); _flushTask = automaticFlush ? Task.Run(FlushBuffersTaskLoopAsync) : Task.FromResult(true); _flushTask.ContinueWith(t => Log.Error(t.Exception, "Error in flush task"), TaskContinuationOptions.OnlyOnFaulted); }
internal RuntimeMetricsWriter(IDogStatsd statsd, TimeSpan delay, Func <IDogStatsd, TimeSpan, IRuntimeMetricsListener> initializeListener) { _delay = delay; _statsd = statsd; _timer = new Timer(_ => PushEvents(), null, delay, delay); try { AppDomain.CurrentDomain.FirstChanceException += FirstChanceException; } catch (Exception ex) { Log.Warning(ex, "First chance exceptions won't be monitored"); } try { ProcessHelpers.GetCurrentProcessRuntimeMetrics(out var userCpu, out var systemCpu, out _, out _); _previousUserCpu = userCpu; _previousSystemCpu = systemCpu; _enableProcessMetrics = true; } catch (Exception ex) { Log.Warning(ex, "Unable to get current process information"); _enableProcessMetrics = false; } try { _listener = initializeListener(statsd, delay); } catch (Exception ex) { Log.Warning(ex, "Unable to initialize runtime listener, some runtime metrics will be missing"); } }
public ModixBot( DiscordSocketClient discordClient, DiscordRestClient restClient, IOptions <ModixConfig> modixConfig, CommandService commandService, DiscordSerilogAdapter serilogAdapter, IApplicationLifetime applicationLifetime, IServiceProvider serviceProvider, ILogger <ModixBot> logger, IHostingEnvironment env, IDogStatsd stats) { _client = discordClient ?? throw new ArgumentNullException(nameof(discordClient)); _restClient = restClient ?? throw new ArgumentNullException(nameof(restClient)); _config = modixConfig?.Value ?? throw new ArgumentNullException(nameof(modixConfig)); _commands = commandService ?? throw new ArgumentNullException(nameof(commandService)); _provider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); _serilogAdapter = serilogAdapter ?? throw new ArgumentNullException(nameof(serilogAdapter)); _applicationLifetime = applicationLifetime ?? throw new ArgumentNullException(nameof(applicationLifetime)); Log = logger ?? throw new ArgumentNullException(nameof(logger)); _env = env; _stats = stats; }
public RuntimeMetricsWriter(IDogStatsd statsd, int delay) { _delay = delay; _statsd = statsd; _timer = new Timer(_ => PushEvents(), null, delay, delay); try { AppDomain.CurrentDomain.FirstChanceException += FirstChanceException; } catch (Exception ex) { Log.Warning(ex, "First chance exceptions won't be monitored"); } try { ProcessHelpers.GetCurrentProcessRuntimeMetrics(out var userCpu, out var systemCpu, out _, out _); _previousUserCpu = userCpu; _previousSystemCpu = systemCpu; _enableProcessMetrics = true; } catch (Exception ex) { Log.Warning(ex, "Unable to get current process information"); _enableProcessMetrics = false; } #if NETCOREAPP _listener = new RuntimeEventListener(); _listener.GcHeapStats += GcHeapStats; _listener.GcPauseTime += GcPauseTime; _listener.GcHeapHistory += GcHeapHistory; _listener.Contention += Contention; #endif }