static object StartServer(string host, int port, ICartStore cartStore) { // Run the server in a separate thread and make the main thread busy waiting. // The busy wait is because when we run in a container, we can't use techniques such as waiting on user input (Console.Readline()) Task serverTask = Task.Run(async() => { try { await cartStore.InitializeAsync(); var redisCartStore = cartStore as RedisCartStore; if (redisCartStore != null) { tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder() .AddRedisInstrumentation(redisCartStore.ConnectionMultiplexer) .AddSource(CartServiceImpl.ActivitySourceName) .SetResource(Resources.CreateServiceResource("CartService")) .AddNewRelicExporter(options => { options.ApiKey = Environment.GetEnvironmentVariable("NEW_RELIC_API_KEY"); options.EndpointUrl = new Uri(Environment.GetEnvironmentVariable("NEW_RELIC_TRACE_URL")); }) .Build(); } Console.WriteLine($"Trying to start a grpc server at {host}:{port}"); Server server = new Server { Services = { // Cart Service Endpoint Hipstershop.CartService.BindService(new CartServiceImpl(cartStore)), // Health Endpoint Grpc.Health.V1.Health.BindService(new HealthImpl(cartStore)) }, Ports = { new ServerPort(host, port, ServerCredentials.Insecure) } }; Console.WriteLine($"Cart server is listening at {host}:{port}"); server.Start(); Console.WriteLine("Initialization completed"); // Keep the server up and running while (true) { Thread.Sleep(TimeSpan.FromMinutes(10)); } } catch (Exception ex) { Console.WriteLine(ex); } }); return(Task.WaitAny(new[] { serverTask })); }
public void Activate_SpanMustBeShim() { var tracer = TracerProvider.GetTracer(TracerName); var shim = new ScopeManagerShim(tracer); Assert.Throws <ArgumentException>(() => shim.Activate(new Mock <global::OpenTracing.ISpan>().Object, true)); }
public async Task SuccessfulTemplateControllerCallGeneratesASpan() { var expectedResource = Resources.Resources.CreateServiceResource("test-service"); var activityProcessor = new Mock <ActivityProcessor>(); void ConfigureTestServices(IServiceCollection services) { this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation() .SetResource(expectedResource) .AddProcessor(activityProcessor.Object) .Build(); } // Arrange using (var client = this.factory .WithWebHostBuilder(builder => builder.ConfigureTestServices(ConfigureTestServices)) .CreateClient()) { // Act var response = await client.GetAsync("/api/values"); // Assert response.EnsureSuccessStatusCode(); // Status Code 200-299 WaitForProcessorInvocations(activityProcessor, 2); } Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; ValidateAspNetCoreActivity(activity, "/api/values", expectedResource); }
public void CtorArgumentValidation() { var tracer = TracerProvider.GetTracer(TracerName); Assert.Throws <ArgumentNullException>(() => new SpanBuilderShim(null, "foo")); Assert.Throws <ArgumentNullException>(() => new SpanBuilderShim(tracer, null)); }
internal static object Run(OpenTracingShimOptions options) { // Enable OpenTelemetry for the source "MyCompany.MyProduct.MyWebServer" // and use Console exporter. using var openTelemetry = OpenTelemetrySdk.EnableOpenTelemetry( (builder) => builder.AddActivitySource("MyCompany.MyProduct.MyWebServer") .SetResource(Resources.CreateServiceResource("MyServiceName")) .UseConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson)); // The above line is required only in applications // which decide to use OpenTelemetry. // Following shows how to use the OpenTracing shim var tracer = new TracerShim(TracerProvider.GetTracer("MyCompany.MyProduct.MyWebServer"), new TraceContextFormat()); using (IScope parentScope = tracer.BuildSpan("Parent").StartActive(finishSpanOnDispose: true)) { parentScope.Span.SetTag("my", "value"); parentScope.Span.SetOperationName("parent span new name"); // The child scope will automatically use parentScope as its parent. using (IScope childScope = tracer.BuildSpan("Child").StartActive(finishSpanOnDispose: true)) { childScope.Span.SetTag("Child Tag", "Child Tag Value").SetTag("ch", "value").SetTag("more", "attributes"); } } System.Console.WriteLine("Press Enter key to exit."); return(null); }
public CurrentSpanTests() { Activity.DefaultIdFormat = ActivityIdFormat.W3C; Activity.ForceDefaultIdFormat = true; this.tracer = TracerProvider.GetTracer(null); }
private static async Task <int> Main() { var builder = Sdk .CreateTracerProviderBuilder() .AddHttpClientInstrumentation() .AddSqlClientInstrumentation() .SetSampler(new AlwaysOnSampler()) .AddSource("OpenTelemetry.AutoInstrumentation.*", "ConsoleApp.SelfBootstrap") .AddConsoleExporter() .AddZipkinExporter(options => { options.Endpoint = new Uri("http://localhost:9411/api/v2/spans"); options.ExportProcessorType = ExportProcessorType.Simple; }); _tracerProvider = builder.Build(); using (var activity = MyActivitySource.StartActivity("Main")) { activity?.SetTag("foo", "bar"); var baseAddress = new Uri("https://www.example.com/"); var regularHttpClient = new HttpClient { BaseAddress = baseAddress }; await regularHttpClient.GetAsync("default-handler"); await regularHttpClient.GetAsync("http://127.0.0.1:8080/api/mongo"); await regularHttpClient.GetAsync("http://127.0.0.1:8080/api/redis"); return(0); } }
internal static object Run(OpenTelemetryShimOptions options) { // Enable OpenTelemetry for the source "MyCompany.MyProduct.MyWebServer" // and use a single pipeline with a custom MyProcessor, and Console exporter. using var openTelemetry = OpenTelemetrySdk.EnableOpenTelemetry( (builder) => builder.AddActivitySource("MyCompany.MyProduct.MyWebServer") .SetResource(Resources.CreateServiceResource("MyServiceName")) .UseConsoleExporter(opt => opt.DisplayAsJson = options.DisplayAsJson)); // The above line is required only in applications // which decide to use Open Telemetry. var tracer = TracerProvider.GetTracer("MyCompany.MyProduct.MyWebServer"); var span = tracer.StartSpan("parent span"); span.SetAttribute("my", "value"); span.UpdateName("parent span new name"); var spanChild = tracer.StartSpan("child span"); spanChild.AddEvent("sample event").SetAttribute("ch", "value").SetAttribute("more", "attributes"); spanChild.End(); span.End(); System.Console.WriteLine("Press Enter key to exit."); return(null); }
public async Task SuccessfulTemplateControllerCallGeneratesASpan() { var expectedResource = Resources.Resources.CreateServiceResource("test-service"); var spanProcessor = new Mock <ActivityProcessor>(); void ConfigureTestServices(IServiceCollection services) { this.openTelemetrySdk = OpenTelemetrySdk.CreateTracerProvider( (builder) => builder.AddRequestInstrumentation() .SetResource(expectedResource) .AddProcessorPipeline(p => p.AddProcessor(n => spanProcessor.Object))); } // Arrange using (var client = this.factory .WithWebHostBuilder(builder => builder.ConfigureTestServices(ConfigureTestServices)) .CreateClient()) { // Act var response = await client.GetAsync("/api/values"); // Assert response.EnsureSuccessStatusCode(); // Status Code 200-299 WaitForProcessorInvocations(spanProcessor, 2); } Assert.Equal(2, spanProcessor.Invocations.Count); // begin and end was called var span = (Activity)spanProcessor.Invocations[1].Arguments[0]; Assert.Equal(ActivityKind.Server, span.Kind); Assert.Equal("/api/values", span.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.HttpPathKey).Value); Assert.Equal(expectedResource, span.GetResource()); }
public static TracerProvider EnableTracing(Jaeger config) { TracerProvider tracing = null; if (config.Enabled) { tracing = Sdk.CreateTracerProviderBuilder() .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("p2g")) .AddHttpClientInstrumentation(config => { config.RecordException = true; config.Enrich = (activity, name, rawEventObject) => { activity.SetTag(TagKey.App, TagValue.P2G); activity.SetTag("SpanId", activity.SpanId); activity.SetTag("TraceId", activity.TraceId); }; }) .AddSource("P2G") .AddJaegerExporter(o => { o.AgentHost = config.AgentHost; o.AgentPort = config.AgentPort.GetValueOrDefault(); }) .Build(); Log.Information("Tracing started and exporting to: http://{@Host}:{@Port}", config.AgentHost, config.AgentPort); } return(tracing); }
public async Task RequestNotCollectedWhenFilterThrowException() { var activityProcessor = new Mock <BaseProcessor <Activity> >(); void ConfigureTestServices(IServiceCollection services) { this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation((opt) => opt.Filter = (ctx) => { if (ctx.Request.Path == "/api/values/2") { throw new Exception("from InstrumentationFilter"); } else { return(true); } }) .AddProcessor(activityProcessor.Object) .Build(); } // Arrange using (var testFactory = this.factory .WithWebHostBuilder(builder => builder.ConfigureTestServices(ConfigureTestServices))) { using var client = testFactory.CreateClient(); // Act using (var inMemoryEventListener = new InMemoryEventListener(AspNetCoreInstrumentationEventSource.Log)) { var response1 = await client.GetAsync("/api/values"); var response2 = await client.GetAsync("/api/values/2"); response1.EnsureSuccessStatusCode(); // Status Code 200-299 response2.EnsureSuccessStatusCode(); // Status Code 200-299 Assert.Single(inMemoryEventListener.Events.Where((e) => e.EventId == 3)); } WaitForProcessorInvocations(activityProcessor, 3); } // As InstrumentationFilter threw, we continue as if the // InstrumentationFilter did not exist. // List of invocations on the processor // 1. SetParentProvider for TracerProviderSdk // 2. OnStart for the activity created by AspNetCore for "/api/values" with the OperationName: Microsoft.AspNetCore.Hosting.HttpRequestIn // 3. OnEnd for the activity created by AspNetCore for "/api/values" with the OperationName: Microsoft.AspNetCore.Hosting.HttpRequestIn // 4. OnStart for the activity created by AspNetCore for "/api/values/2" with the OperationName: Microsoft.AspNetCore.Hosting.HttpRequestIn // we should only call Processor.OnEnd for the "/api/values" request Assert.Single(activityProcessor.Invocations, invo => invo.Method.Name == "OnEnd"); var activity = activityProcessor.Invocations.FirstOrDefault(invo => invo.Method.Name == "OnEnd").Arguments[0] as Activity; Assert.Equal(ActivityKind.Server, activity.Kind); Assert.Equal("/api/values", activity.GetTagValue(SpanAttributeConstants.HttpPathKey) as string); }
/// <summary> /// <para>Configures common static providers with values from given <paramref name="environment"/>.</para> /// <para>Following static providers are configured:</para> /// <list type="bullet"> /// <item><description><see cref="LogProvider"/></description></item> /// <item><description><see cref="TracerProvider"/></description></item> /// <item><description><see cref="HerculesSinkProvider"/></description></item> /// <item><description><see cref="DatacentersProvider"/></description></item> /// <item><description>ClusterConfigClient.<see cref="ClusterConfigClient.Default"/> (if not configured earlier)</description></item> /// <item><description>ConfigurationProvider.<see cref="ConfigurationProvider.Default"/> (if not configured earlier)</description></item> /// </list> /// </summary> public static void Configure([NotNull] IVostokHostingEnvironment environment) { if (environment == null) { throw new ArgumentNullException(nameof(environment)); } ClusterClientDefaults.ClientApplicationName = environment.ApplicationIdentity.FormatServiceName(); LogProvider.Configure(environment.Log, true); TracerProvider.Configure(environment.Tracer, true); HerculesSinkProvider.Configure(environment.HerculesSink, true); DatacentersProvider.Configure(environment.Datacenters, true); var log = environment.Log.ForContext(typeof(StaticProvidersHelper)); if (environment.ClusterConfigClient is ClusterConfigClient clusterConfigClient) { if (!ClusterConfigClient.TrySetDefaultClient(clusterConfigClient) && !ReferenceEquals(ClusterConfigClient.Default, environment.ClusterConfigClient)) { log.Warn("ClusterConfigClient.Default has already been configured."); } } if (environment.ConfigurationProvider is ConfigurationProvider configurationProvider && !ReferenceEquals(ConfigurationProvider.Default, environment.ConfigurationProvider)) { if (!ConfigurationProvider.TrySetDefault(configurationProvider)) { log.Warn("ConfigurationProvider.Default has already been configured."); } } }
public void FinishSpan() { var tracer = TracerProvider.GetTracer(TracerName); var shim = new SpanShim(tracer.StartSpan(SpanName)); shim.Finish(); Assert.NotEqual(default, shim.Span.Activity.Duration);
public void Active_IsNull() { var tracer = TracerProvider.GetTracer(TracerName); var shim = new ScopeManagerShim(tracer); Assert.Null(Activity.Current); Assert.Null(shim.Active); }
public void BuildSpan_NotNull() { var tracer = TracerProvider.GetTracer(TracerName); var shim = new TracerShim(tracer, new TraceContextFormat()); // Internals of the SpanBuilderShim tested elsewhere Assert.NotNull(shim.BuildSpan("foo") as SpanBuilderShim); }
public void ScopeManager_NotNull() { var tracer = TracerProvider.GetTracer(TracerName); var shim = new TracerShim(tracer, new TraceContextFormat()); // Internals of the ScopeManagerShim tested elsewhere Assert.NotNull(shim.ScopeManager as ScopeManagerShim); }
public void Extract_ArgumentValidation() { var tracer = TracerProvider.GetTracer(TracerName); var shim = new TracerShim(tracer, new TraceContextFormat()); Assert.Throws <ArgumentNullException>(() => shim.Extract(null, new Mock <ITextMap>().Object)); Assert.Throws <ArgumentNullException>(() => shim.Extract(new Mock <IFormat <ITextMap> >().Object, null)); }
public void SpanContextIsNotNull() { var tracer = TracerProvider.GetTracer(TracerName); var shim = new SpanShim(tracer.StartSpan(SpanName)); // ISpanContext validation handled in a separate test class Assert.NotNull(shim.Context); }
public async Task ExtractContextIrrespectiveOfSamplingDecision(SamplingDecision samplingDecision) { try { var expectedTraceId = ActivityTraceId.CreateRandom(); var expectedParentSpanId = ActivitySpanId.CreateRandom(); var expectedTraceState = "rojo=1,congo=2"; var activityContext = new ActivityContext(expectedTraceId, expectedParentSpanId, ActivityTraceFlags.Recorded, expectedTraceState); var expectedBaggage = Baggage.SetBaggage("key1", "value1").SetBaggage("key2", "value2"); Sdk.SetDefaultTextMapPropagator(new ExtractOnlyPropagator(activityContext, expectedBaggage)); // Arrange using (var testFactory = this.factory .WithWebHostBuilder(builder => builder.ConfigureTestServices(services => { this.tracerProvider = Sdk.CreateTracerProviderBuilder() .SetSampler(new TestSampler(samplingDecision)) .AddAspNetCoreInstrumentation() .Build(); }))) { using var client = testFactory.CreateClient(); // Test TraceContext Propagation var request = new HttpRequestMessage(HttpMethod.Get, "/api/GetChildActivityTraceContext"); var response = await client.SendAsync(request); var childActivityTraceContext = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content.ReadAsStringAsync().Result); response.EnsureSuccessStatusCode(); Assert.Equal(expectedTraceId.ToString(), childActivityTraceContext["TraceId"]); Assert.Equal(expectedTraceState, childActivityTraceContext["TraceState"]); Assert.NotEqual(expectedParentSpanId.ToString(), childActivityTraceContext["ParentSpanId"]); // there is a new activity created in instrumentation therefore the ParentSpanId is different that what is provided in the headers // Test Baggage Context Propagation request = new HttpRequestMessage(HttpMethod.Get, "/api/GetChildActivityBaggageContext"); response = await client.SendAsync(request); var childActivityBaggageContext = JsonConvert.DeserializeObject <IReadOnlyDictionary <string, string> >(response.Content.ReadAsStringAsync().Result); response.EnsureSuccessStatusCode(); Assert.Single(childActivityBaggageContext, item => item.Key == "key1" && item.Value == "value1"); Assert.Single(childActivityBaggageContext, item => item.Key == "key2" && item.Value == "value2"); } } finally { Sdk.SetDefaultTextMapPropagator(new CompositeTextMapPropagator(new TextMapPropagator[] { new TraceContextPropagator(), new BaggagePropagator(), })); } }
public AccommodationDataCorrector(NakijinContext context, AccommodationDataCorrectionManager accommodationDataCorrectionManager, IOptions <StaticDataLoadingOptions> options, ILoggerFactory loggerFactory, TracerProvider tracerProvider) { _context = context; _options = options.Value; _logger = loggerFactory.CreateLogger <AccommodationDataCorrector>(); _tracerProvider = tracerProvider; _accommodationDataCorrectionManager = accommodationDataCorrectionManager; }
public async Task SuccessfulTemplateControllerCallUsesParentContext() { var activityProcessor = new Mock <BaseProcessor <Activity> >(); var expectedTraceId = ActivityTraceId.CreateRandom(); var expectedSpanId = ActivitySpanId.CreateRandom(); // Arrange using (var testFactory = this.factory .WithWebHostBuilder(builder => builder.ConfigureTestServices(services => { this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder().AddAspNetCoreInstrumentation() .AddProcessor(activityProcessor.Object) .Build(); }))) { using var client = testFactory.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, "/api/values/2"); request.Headers.Add("traceparent", $"00-{expectedTraceId}-{expectedSpanId}-01"); // Act var response = await client.SendAsync(request); // Assert response.EnsureSuccessStatusCode(); // Status Code 200-299 WaitForProcessorInvocations(activityProcessor, 3); } // List of invocations // 1. SetParentProvider for TracerProviderSdk // 2. OnStart for the activity created by AspNetCore with the OperationName: Microsoft.AspNetCore.Hosting.HttpRequestIn // 3. OnStart for the sibling activity created by the instrumentation library with the OperationName: ActivityCreatedByHttpInListener // 4. OnEnd for the sibling activity created by the instrumentation library with the OperationName: ActivityCreatedByHttpInListener // we should only call Processor.OnEnd once for the sibling activity with the OperationName ActivityCreatedByHttpInListener Assert.Single(activityProcessor.Invocations, invo => invo.Method.Name == "OnEnd"); var activity = activityProcessor.Invocations.FirstOrDefault(invo => invo.Method.Name == "OnEnd").Arguments[0] as Activity; #if !NETCOREAPP2_1 // ASP.NET Core after 2.x is W3C aware and hence Activity created by it // must be used. Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", activity.OperationName); #else // ASP.NET Core before 3.x is not W3C aware and hence Activity created by it // is always ignored and new one is created by the Instrumentation Assert.Equal("ActivityCreatedByHttpInListener", activity.OperationName); #endif Assert.Equal(ActivityKind.Server, activity.Kind); Assert.Equal("api/Values/{id}", activity.DisplayName); Assert.Equal("/api/values/2", activity.GetTagValue(SpanAttributeConstants.HttpPathKey) as string); Assert.Equal(expectedTraceId, activity.Context.TraceId); Assert.Equal(expectedSpanId, activity.ParentSpanId); }
public async Task CustomPropagator() { var activityProcessor = new Mock <BaseProcessor <Activity> >(); var expectedTraceId = ActivityTraceId.CreateRandom(); var expectedSpanId = ActivitySpanId.CreateRandom(); var propagator = new Mock <TextMapPropagator>(); propagator.Setup(m => m.Extract(It.IsAny <PropagationContext>(), It.IsAny <HttpRequest>(), It.IsAny <Func <HttpRequest, string, IEnumerable <string> > >())).Returns( new PropagationContext( new ActivityContext( expectedTraceId, expectedSpanId, ActivityTraceFlags.Recorded), default)); // Arrange using (var testFactory = this.factory .WithWebHostBuilder(builder => builder.ConfigureTestServices(services => { Sdk.SetDefaultTextMapPropagator(propagator.Object); this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation() .AddProcessor(activityProcessor.Object) .Build(); }))) { using var client = testFactory.CreateClient(); var response = await client.GetAsync("/api/values/2"); response.EnsureSuccessStatusCode(); // Status Code 200-299 WaitForProcessorInvocations(activityProcessor, 2); } // begin and end was called once each. Assert.Equal(2, activityProcessor.Invocations.Count); var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; Assert.Equal("ActivityCreatedByHttpInListener", activity.OperationName); Assert.Equal(ActivityKind.Server, activity.Kind); Assert.True(activity.Duration != TimeSpan.Zero); Assert.Equal("api/Values/{id}", activity.DisplayName); Assert.Equal("/api/values/2", activity.GetTagValue(SpanAttributeConstants.HttpPathKey) as string); Assert.Equal(expectedTraceId, activity.Context.TraceId); Assert.Equal(expectedSpanId, activity.ParentSpanId); Sdk.SetDefaultTextMapPropagator(new CompositeTextMapPropagator(new TextMapPropagator[] { new TraceContextPropagator(), new BaggagePropagator(), })); }
private static void OnFunctionStop(Activity activity, TracerProvider tracerProvider) { if (activity != null) { activity.Stop(); } // force flush before function quit in case of Lambda freeze. tracerProvider.ForceFlush(); }
static Function() { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); tracerProvider = Sdk.CreateTracerProviderBuilder() .AddAWSInstrumentation() .AddOtlpExporter() .AddAWSLambdaConfigurations() .Build(); }
public ActivitySourceAdapterBenchmark() { this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddInstrumentation((adapter) => { this.testInstrumentation = new TestInstrumentation(adapter); return(this.testInstrumentation); }) .Build(); }
public void GlobalSetup() { this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddDiagnosticSourceInstrumentation((adapter) => { this.testInstrumentation = new TestInstrumentation(adapter); return(this.testInstrumentation); }) .Build(); }
public SimpleActivityProcessorTest() { this.activityExporter = new TestActivityExporter(null); this.openTelemetry = OpenTelemetrySdk.CreateTracerProvider(b => b .AddActivitySource(ActivitySourceName) .AddProcessorPipeline(p => p .SetExporter(this.activityExporter) .SetExportingProcessor(e => new SimpleActivityProcessor(e))) .SetSampler(new AlwaysOnSampler())); this.activitySource = new ActivitySource(ActivitySourceName); }
public async Task RequestNotCollectedWhenFilterThrowException() { var activityProcessor = new Mock <ActivityProcessor>(); void ConfigureTestServices(IServiceCollection services) { this.openTelemetrySdk = Sdk.CreateTracerProviderBuilder() .AddAspNetCoreInstrumentation((opt) => opt.Filter = (ctx) => { if (ctx.Request.Path == "/api/values/2") { throw new Exception("from InstrumentationFilter"); } else { return(true); } }) .AddProcessor(activityProcessor.Object) .Build(); } // Arrange using (var testFactory = this.factory .WithWebHostBuilder(builder => builder.ConfigureTestServices(ConfigureTestServices))) { using var client = testFactory.CreateClient(); // Act using (var inMemoryEventListener = new InMemoryEventListener(AspNetCoreInstrumentationEventSource.Log)) { var response1 = await client.GetAsync("/api/values"); var response2 = await client.GetAsync("/api/values/2"); response1.EnsureSuccessStatusCode(); // Status Code 200-299 response2.EnsureSuccessStatusCode(); // Status Code 200-299 Assert.Single(inMemoryEventListener.Events.Where((e) => e.EventId == 3)); } WaitForProcessorInvocations(activityProcessor, 2); } // As InstrumentationFilter threw, we continue as if the // InstrumentationFilter did not exist. Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; Assert.Equal(ActivityKind.Server, activity.Kind); Assert.Equal("/api/values", activity.GetTagValue(SpanAttributeConstants.HttpPathKey) as string); }
public WindowedStreamConsumer([NotNull] WindowedStreamConsumerSettings <T, TKey> settings, [CanBeNull] ILog log) : base(settings, log) { this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); this.log = (log ?? LogProvider.Get()).ForContext <WindowedStreamConsumer <T, TKey> >(); tracer = settings.Tracer ?? TracerProvider.Get(); windows = new Dictionary <TKey, Windows <T, TKey> >(); var applicationMetricContext = settings.ApplicationMetricContext ?? new DevNullMetricContext(); eventLagMetric = applicationMetricContext.CreateHistogram("eventLag", new HistogramConfig { Buckets = HistogramHelper.CreateDefaultBuckets(), Unit = WellKnownUnits.Milliseconds }); var instanceMetricContext = settings.InstanceMetricContext ?? new DevNullMetricContext(); stateMetric = instanceMetricContext.CreateIntegerGauge("state", "type"); var settingsOnBatchEnd = settings.OnBatchEnd; settings.OnBatchEnd = c => { FlushWindows(); Task.Run(() => settings.LeftCoordinatesStorage.AdvanceAsync(leftCoordinates)); settingsOnBatchEnd?.Invoke(c); }; var settingsOnEvent = settings.OnEvent; settings.OnEvent = (e, c) => { AddEvent(e, c); settingsOnEvent?.Invoke(e, c); }; var settingsOnRestart = settings.OnRestart; settings.OnRestart = c => { Restart(c).GetAwaiter().GetResult(); settingsOnRestart?.Invoke(c); }; var settingsOnStop = settings.OnStop; settings.OnStop = c => { Stop(c).GetAwaiter().GetResult(); settingsOnStop?.Invoke(c); }; }
public AccommodationPreloader(NakijinContext context, IConnectorClient connectorClient, ILoggerFactory loggerFactory, IOptions <StaticDataLoadingOptions> options, ILocationNameNormalizer locationNameNormalizer, TracerProvider tracerProvider, ISupplierOptionsClient supplierOptionsClient) { _context = context; _logger = loggerFactory.CreateLogger <AccommodationPreloader>(); _options = options.Value; _connectorClient = connectorClient; _locationNameNormalizer = locationNameNormalizer; _tracerProvider = tracerProvider; _supplierOptionsClient = supplierOptionsClient; }