public BlobFileConventionActor(NestBatchPusher pusher, ITelemetryProvider telemetryProvider) { _telemetryProvider = telemetryProvider; _pusher = pusher; _durationInstrumentor = telemetryProvider.GetInstrumentor <BlobFileConventionActor>(); }
public void InstrumentationSamplingRateLimitsForTwoStage() { int numberOfTimesInstrumented = 0; var ins = new SimpleInstrumentor(new InstrumentationInfo() { Counters = CounterTypes.StandardCounters, Description = "test", InstanceName = "Test instance", CategoryName = "DOESNOTEXISTDONTLOOKFORIT", PublishCounters = false, PublishEvent = true, RaisePublishErrors = false }) { PublishInstrumentationCallback = (a, b, c, d, e) => numberOfTimesInstrumented++ }; double samplingRate = 0.01; Enumerable.Range(0, 1000).ToList().ForEach(x => { Correlation.SetId(Guid.NewGuid().ToString()); ins.Finish(ins.Start(samplingRate)); }); Assert.InRange(numberOfTimesInstrumented, 1, 100); }
public BlobFileConventionActor(IElasticsearchBatchPusher pusher, ITempDownloadLocationProvider tempDownloadLocationProvider, ITelemetryProvider telemetryProvider) { _tempDownloadLocationProvider = tempDownloadLocationProvider; _telemetryProvider = telemetryProvider; _pusher = pusher; _durationInstrumentor = telemetryProvider.GetInstrumentor <BlobFileConventionActor>(); }
public void Intercept(IInvocation invocation) { if (!PublishCounters && !PublishEvent) { invocation.Proceed(); } else { try { string instrumentationContext = ""; if (_instrumentationContextProvider != null) { instrumentationContext = _instrumentationContextProvider.GetContext(invocation.MethodInvocationTarget); } if (!_inited) { lock (_lock) { if (!_inited) { Init(); } } } SimpleInstrumentor instrumentor = null; if (_instrumentors == null || !_instrumentors.TryGetValue(instrumentationContext, out instrumentor)) { instrumentor = (SimpleInstrumentor)InitInstrumentor(invocation.MethodInvocationTarget); } var returnType = invocation.Method.ReturnType; if (returnType != typeof(void) && ((returnType == typeof(Task) || (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task <>))))) { instrumentor.InstrumentAsync(async() => invocation.Proceed(), instrumentationContext: instrumentationContext, samplingRate: SamplingRate); } else { instrumentor.Instrument(invocation.Proceed, instrumentationContext: instrumentationContext, samplingRate: SamplingRate); } } catch (Exception exception) { Trace.TraceError(exception.ToString()); if (RaisePublishErrors) { throw; } } } }
public void HashCodeIsReliableForSamplingPurposes() { int total = 10 * 1000; double samplingRate = 0.3; int totalSampled = Enumerable.Range(0, total).Select(i => SimpleInstrumentor.ShouldInstrument(samplingRate, Guid.NewGuid().ToString())) .Count(x => x); Console.WriteLine(totalSampled); Assert.InRange(totalSampled, 2000, 4000); }
public void Writes() { string fileName = "shibi"; if (File.Exists(fileName)) { File.Delete(fileName); } var ins = new SimpleInstrumentor(new InstrumentationInfo() { Description = "test", InstanceName = "Test instance", CategoryName = "test" }); ins.Tracers.Add("File", new SeparatedFileTracer(fileName)); var ctx = new InstrumentationContext() { Text1 = "Text1", Text2 = "Text2", Numeric = 424242, Decimal = 0.420420420 }; ins.Instrument(() => Thread.Sleep(100), extraContext: ctx); Thread.Sleep(1000); ins.Dispose(); var lines = File.ReadAllLines(fileName); Assert.Equal(1, lines.Length); var segments = lines[0].Split('\t'); Assert.Equal(8, segments.Length); Assert.Equal("Test instance", segments[1]); Assert.Equal("test", segments[0]); Assert.Equal("Text1", segments[4]); Assert.Equal("Text2", segments[5]); Assert.Equal("424242", segments[6]); // INTENTIONAL // Assert.Equal("0.420420420", segments[7]); !!floating point numbers :/ // 1- Category // 2- Instance // 3- CorrelationId // 4- TimeTakenMilli // 5- Text1 // 6- Text2 // 7- Numberic // 8- Decimal }
public void CanPublishAspect() { var ins = new SimpleInstrumentor(new InstrumentationInfo() { Description = "test", InstanceName = "Test instance", CategoryName = TestCategory }); ins.Instrument(() => Thread.Sleep(100)); }
public void CanPublishAsyncAspect() { var ins = new SimpleInstrumentor(new InstrumentationInfo() { Description = "test", InstanceName = "Testinstance", CategoryName = TestCategory }); ins.InstrumentAsync(() => Task.Delay(100)).Wait(); }
private ITwoStageInstrumentor InitInstrumentor(MethodInfo methodInfo) { string instrumentationContext = ""; var instrumentationInfo = GetInstrumentationInfo(methodInfo); if (instrumentationInfo != null) { var instanceName = instrumentationInfo.InstanceName; PublishCounters = instrumentationInfo.PublishCounters; if (string.IsNullOrEmpty(instanceName) && _instanceNameProvider != null) { instanceName = _instanceNameProvider.GetInstanceName(methodInfo); } if (string.IsNullOrEmpty(instanceName)) { throw new InvalidOperationException("Either InstanceName or InstanceNameProviderType must be supplied."); } if (_instrumentationContextProvider != null) { instrumentationContext = _instrumentationContextProvider.GetContext(methodInfo); } else { throw new InvalidOperationException("The Instrumentation Context Cannot be Null. Define a InstrumentationContextProvider implementation."); } SetEventPolicy(); SetPublishCounterPolicy(); SetErrorPolicy(); var instrumentor = new SimpleInstrumentor(new InstrumentationInfo() { Description = instrumentationInfo.Description, Counters = instrumentationInfo.Counters, InstanceName = instanceName, CategoryName = string.IsNullOrEmpty(this.CategoryName) ? instrumentationInfo.CategoryName : this.CategoryName, SamplingRate = SamplingRate, PublishCounters = PublishCounters, PublishEvent = PublishEvent, RaisePublishErrors = RaisePublishErrors }); _instrumentors.AddOrUpdate(instrumentationContext, instrumentor, (key, inst) => instrumentor); return(instrumentor); } else { return(null); } }
public void CanTurnOffPublishingCounters() { var ins = new SimpleInstrumentor(new InstrumentationInfo() { Counters = CounterTypes.StandardCounters, Description = "test", InstanceName = "Test instance", CategoryName = "DOESNOTEXISTDONTLOOKFORIT" }, false, true, true); ins.InstrumentAsync(() => Task.Delay(100), "test...").Wait(); }
public void CanPublishAsyncAspect() { var ins = new SimpleInstrumentor(new InstrumentationInfo() { Counters = CounterTypes.StandardCounters, Description = "test", InstanceName = "Test instance", CategoryName = TestCategory }); ins.InstrumentAsync(() => Task.Delay(100), "test...").Wait(); }
public void CanPublishAsyncAspect() { var ins = new SimpleInstrumentor(new InstrumentationInfo() { Counters = CounterTypes.StandardCounters, Description = "test", InstanceName = "Test instance", CategoryName = TestCategory }); ins.InstrumentAsync( () => Task.Delay(100), "test...").Wait(); }
private void Init(ActionExecutingContext actionContext) { SetErrorPolicy(); SetSamplingRate(); if (SamplingRate == default(double)) { SamplingRate = Constants.DefaultSamplingRate; } if (InstanceNameProviderType != null) { _instanceNameProvider = (IInstanceNameProvider)Activator.CreateInstance(InstanceNameProviderType); } _instanceNameProvider = _instanceNameProvider ?? (IInstanceNameProvider)actionContext.HttpContext.RequestServices.GetService(typeof(IInstanceNameProvider)); if (InstrumentationContextProviderType != null) { _instrumentationContextProvider = (IInstrumentationContextProvider)Activator.CreateInstance(InstrumentationContextProviderType); } _instrumentationContextProvider = _instrumentationContextProvider ?? (IInstrumentationContextProvider)actionContext.HttpContext.RequestServices.GetService(typeof(IInstrumentationContextProvider)); var instanceName = InstanceName; if (_instanceNameProvider != null) { instanceName = _instanceNameProvider.GetInstanceName(actionContext); } if (instanceName == null) { instanceName = PerfItRuntime.GetCounterInstanceName(actionContext.Controller.GetType(), actionContext.ActionDescriptor.DisplayName); } var inst = new SimpleInstrumentor(new InstrumentationInfo() { Description = Description, InstanceName = instanceName, CategoryName = CategoryName, SamplingRate = SamplingRate, RaisePublishErrors = RaisePublishErrors }); _instrumentor = inst; }
public ShardKeyActor(IElasticsearchBatchPusher pusher, ITelemetryProvider telemetryProvider, IConfigurationValueProvider configurationValueProvider) { _pusher = pusher; _telemetryProvider = telemetryProvider; _durationInstrumentor = telemetryProvider.GetInstrumentor <ShardKeyActor>(); if (!int.TryParse( configurationValueProvider.GetValue(ConfigurationKeys.ShadKeyArrivalDelayWarningInSeconds), out _shardKeyDelayWarning)) { _shardKeyDelayWarning = 120; } }
public void CanTurnOffPublishingCounters() { var ins = new SimpleInstrumentor(new InstrumentationInfo { Counters = CounterTypes.StandardCounters.ToArray(), Description = "test", InstanceName = "Test instance", CategoryName = "DOESNOTEXISTDONTLOOKFORIT", PublishCounters = false, PublishEvent = true, RaisePublishErrors = true }); ins.InstrumentAsync(() => Task.Delay(100), "test...").Wait(); }
public async Task InstrumentorCreatesCorrIdIfNotExists() { var ins = new SimpleInstrumentor(new InstrumentationInfo() { Description = "test", InstanceName = "Test instance", CategoryName = "DOESNOTEXISTDONTLOOKFORIT", RaisePublishErrors = true }); await ins.InstrumentAsync(() => Task.Delay(100)); var idAfter = Correlation.GetId(setIfNotThere: false); Assert.NotNull(idAfter); }
public void WorksWithEnabledCounters() { var ins = new SimpleInstrumentor(new InstrumentationInfo() { Description = "test", InstanceName = "Testinstance", CategoryName = TestCategory, PublishCounters = true, RaisePublishErrors = true }); for (int i = 0; i < 100; i++) { ins.InstrumentAsync(() => Task.Delay(100)).Wait(); } }
public void DontRaiseErrorsDoesNotHideOriginalError() { var ins = new SimpleInstrumentor(new InstrumentationInfo() { Description = "test", InstanceName = "Test instance", CategoryName = "DOESNOTEXISTDONTLOOKFORIT", RaisePublishErrors = false }); var ex = Assert.Throws <AggregateException>(() => ins.InstrumentAsync(() => { throw new NotImplementedException(); }).Wait()); Assert.IsType <NotImplementedException>(ex.InnerExceptions[0]); }
public void CanPublishAspect() { var ins = new SimpleInstrumentor(new InstrumentationInfo() { Counters = CounterTypes.StandardCounters, Description = "test", InstanceName = "Test instance", CategoryName = TestCategory }); var listener = ConsoleLog.CreateListener(); listener.EnableEvents(InstrumentationEventSource.Instance, EventLevel.LogAlways, Keywords.All); ins.Instrument(() => Thread.Sleep(100), "test..."); listener.DisableEvents(InstrumentationEventSource.Instance); listener.Dispose(); }
protected async override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var instanceName = InstanceName ?? InstanceNameProvider(request); var instrumenter = _instrumenters.GetOrAdd(instanceName, (insName) => { var inst = new SimpleInstrumentor(new InstrumentationInfo() { Description = "Counter for " + insName, #if NET452 Counters = Counters, PublishCounters = PublishCounters, #endif InstanceName = insName, CategoryName = CategoryName, SamplingRate = SamplingRate, RaisePublishErrors = RaisePublishErrors, CorrelationIdKey = CorrelationIdKey, Name = Name ?? "HTTP" + "-" + insName }); foreach (var tracer in Tracers) { inst.Tracers.Add(tracer.GetType().FullName, tracer); } return(inst); } ); HttpResponseMessage response = null; Func <Task> t = async() => response = await base.SendAsync(request, cancellationToken); var ctx = new InstrumentationContext() { Text1 = request.RequestUri.AbsoluteUri }; await instrumenter.InstrumentAsync(t, SamplingRate, ctx); return(response); }
public async Task CorrelationIdStaysTheSameAfterBloodyAsyncCallsAndPublishEtwAndCallingAsync() { var id = Correlation.GetId(setIfNotThere: true); id = Correlation.GetId(setIfNotThere: false); var inst = new SimpleInstrumentor(new InstrumentationInfo() { CategoryName = "cat", InstanceName = "ins", RaisePublishErrors = true }); //InstrumentationEventSource.Instance.WriteInstrumentationEvent("blah", "ff", 12, "gfg", id.ToString()); await inst.InstrumentAsync(() => Task.Delay(100)); var id2 = Correlation.GetId(setIfNotThere: false); Assert.Equal(id, id2); }
public MasterScheduler(IEventQueueOperator eventQueueOperator, IConfigurationValueProvider configurationValueProvider, ISourceConfiguration sourceConfiguration, IElasticsearchClient elasticsearchClient, IServiceLocator locator, ILockStore lockStore, ITelemetryProvider telemetryProvider, IIndexNamer indexNamer, IKeyValueStore keyValueStore) { _keyValueStore = keyValueStore; _indexNamer = indexNamer; _lockStore = lockStore; _telemetryProvider = telemetryProvider; _sourceConfiguration = sourceConfiguration; _locator = locator; _elasticsearchClient = elasticsearchClient; _configurationValueProvider = configurationValueProvider; _eventQueueOperator = eventQueueOperator; _scheduleDurationInstrumentor = telemetryProvider.GetInstrumentor <MasterScheduler>(); }
public void InstrumentationSamplingRateLimitsForAsync() { int numberOfTimesInstrumented = 0; var ins = new SimpleInstrumentor(new InstrumentationInfo() { Counters = CounterTypes.StandardCounters, Description = "test", InstanceName = "Test instance", CategoryName = "DOESNOTEXISTDONTLOOKFORIT", PublishCounters = true, PublishEvent = true, RaisePublishErrors = false }) { PublishInstrumentationCallback = (a, b, c, d) => numberOfTimesInstrumented++ }; double samplingRate = 0.01; Enumerable.Range(0, 1000).ToList().ForEach(x => ins.InstrumentAsync(async() => { }, samplingRate: samplingRate).Wait()); Assert.InRange(numberOfTimesInstrumented, 1, 100); }
public void InstrumentationSamplingRateLimitsForTwoStage() { var numberOfTimesInstrumented = 0; var ins = new SimpleInstrumentor(new InstrumentationInfo { Counters = CounterTypes.StandardCounters.ToArray(), Description = "test", InstanceName = "Test instance", CategoryName = "DOESNOTEXISTDONTLOOKFORIT", PublishCounters = true, PublishEvent = true, RaisePublishErrors = false }) { PublishInstrumentationCallback = (a, b, c, d) => numberOfTimesInstrumented++ }; const double samplingRate = 0.01d; Enumerable.Range(0, 1000).ToList().ForEach(x => ins.Finish(ins.Start(samplingRate))); Assert.InRange(numberOfTimesInstrumented, 1, 100); }
public void InstrumentationSamplingRateLimitsForTwoStage() { int numberOfTimesInstrumented = 0; var ins = new SimpleInstrumentor(new InstrumentationInfo() { Description = "test", InstanceName = "Test instance", CategoryName = "DOESNOTEXISTDONTLOOKFORIT", RaisePublishErrors = false }); ins.Tracers.Add("a", new ActionTracer(() => numberOfTimesInstrumented++)); double samplingRate = 0.01; Enumerable.Range(0, 1000).ToList().ForEach(x => { Correlation.SetId(Guid.NewGuid().ToString()); ins.Finish(ins.Start(samplingRate)); }); Assert.InRange(numberOfTimesInstrumented, 1, 100); }
public void InstrumentationShouldCallIncludedCounters() { if (!PerfItRuntime.HandlerFactories.ContainsKey("CustomCounterStub")) { PerfItRuntime.HandlerFactories.Add("CustomCounterStub", (s, s1) => new CustomCounterStub(s, s1)); } CustomCounterStub.ClearCounters(); var ins = new SimpleInstrumentor(new InstrumentationInfo() { Counters = CounterTypes.StandardCounters.Union(new[] { "CustomCounterStub" }).ToArray(), Description = "test", InstanceName = "Test instance", CategoryName = TestCategory, PublishCounters = true, }); ins.Instrument(() => { }, "test..."); Assert.Equal(1, CustomCounterStub.RequestStartCount); Assert.Equal(1, CustomCounterStub.RequestEndCount); }
public void DontRaiseErrorsDoesNotHideOriginalError() { var ins = new SimpleInstrumentor(new InstrumentationInfo() { Counters = CounterTypes.StandardCounters, Description = "test", InstanceName = "Test instance", CategoryName = "DOESNOTEXISTDONTLOOKFORIT" }, true, true, false); var ex = Assert.Throws<AggregateException>(() => ins.InstrumentAsync(() => { throw new NotImplementedException(); } , "test...").Wait()); Assert.IsType<NotImplementedException>(ex.InnerExceptions[0]); }
private void Init(ActionExecutingContext actionContext) { SetPublishCounterPolicy(); SetErrorPolicy(); SetSamplingRate(); if (SamplingRate == default(double)) { SamplingRate = Constants.DefaultSamplingRate; } if (InstanceNameProviderType != null) { _instanceNameProvider = (IInstanceNameProvider)Activator.CreateInstance(InstanceNameProviderType); } if (InstrumentationContextProviderType != null) { _instrumentationContextProvider = (IInstrumentationContextProvider)Activator.CreateInstance(InstrumentationContextProviderType); } if (Counters == null || Counters.Length == 0) { Counters = CounterTypes.StandardCounters; } var instanceName = InstanceName; if (_instanceNameProvider != null) { instanceName = _instanceNameProvider.GetInstanceName(actionContext); } if (instanceName == null) { instanceName = PerfItRuntime.GetCounterInstanceName(actionContext.ActionDescriptor.ControllerDescriptor.ControllerType, actionContext.ActionDescriptor.ActionName); } var inst = new SimpleInstrumentor(new InstrumentationInfo() { Description = Description, Counters = Counters, InstanceName = instanceName, CategoryName = CategoryName, SamplingRate = SamplingRate, PublishCounters = PublishCounters, RaisePublishErrors = RaisePublishErrors }); _instrumentor = inst; if (TracerTypes != null) { foreach (var tt in TracerTypes) { inst.Tracers.Add(tt.FullName, (ITwoStageTracer)Activator.CreateInstance(tt)); } } }
public BlobFileActor(IElasticsearchBatchPusher pusher, ITelemetryProvider telemetryProvider) { _pusher = pusher; _telemetryProvider = telemetryProvider; _durationInstrumentor = telemetryProvider.GetInstrumentor <BlobFileActor>(); }