/// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return(new ServiceInstanceListener[]
            {
                new ServiceInstanceListener(serviceContext =>
                                            new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                    return new WebHostBuilder()
                    .UseKestrel()
                    .ConfigureAppConfiguration((builderContext, config) =>
                    {
                        config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
                    })
                    .ConfigureServices(
                        (context, services) => services
                        .AddSingleton <StatelessServiceContext>(serviceContext)
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))
                        .AddSingleton(context.Configuration)
                        )
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseApplicationInsights()
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                    .UseUrls(url)
                    .Build();
                }))
            });
        }
예제 #2
0
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return(new ServiceInstanceListener[]
            {
                new ServiceInstanceListener(
                    serviceContext =>
                    new KestrelCommunicationListener(
                        serviceContext,
                        "ServiceEndpoint",
                        (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                    return new WebHostBuilder()
                    .UseKestrel()
                    .ConfigureServices(
                        services => services

                        .AddSingleton <HttpClient>(new HttpClient())
                        .AddSingleton <FabricClient>(new FabricClient())
                        .AddSingleton <StatelessServiceContext>(serviceContext)
                        .AddSingleton <ITelemetryModule>(new ServiceRemotingDependencyTrackingTelemetryModule())
                        .AddSingleton <ITelemetryModule>(new ServiceRemotingRequestTrackingTelemetryModule())
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext)))

                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseApplicationInsights()
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                    .UseUrls(url)
                    .Build();
                }))
            });
        }
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return(new ServiceInstanceListener[]
            {
                new ServiceInstanceListener(serviceContext =>
                                            new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                    return new WebHostBuilder()
                    .UseKestrel()
                    .ConfigureServices(
                        services => services
                        .AddSingleton <StatelessServiceContext>(serviceContext)
                        .AddScoped <IUtility, Utility>()
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext)))
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseUnityServiceProvider()
                    .UseStartup <Startup>()
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                    .UseUrls(url)
                    .Build();
                }))
            });
        }
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return(new ServiceInstanceListener[]
            {
                new ServiceInstanceListener(
                    serviceContext =>
                    new KestrelCommunicationListener(
                        serviceContext,
                        "ServiceEndpoint",
                        (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}, PID: {Process.GetCurrentProcess().Id}, InstrumentationKey: {Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY")}");

                    return new WebHostBuilder()
                    .UseKestrel()
                    .ConfigureServices(
                        services => services
                        .AddSingleton <HttpClient>(new HttpClient())
                        .AddSingleton <FabricClient>(new FabricClient())
                        .AddSingleton <StatelessServiceContext>(serviceContext)
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext)))
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseApplicationInsights()
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                    .UseUrls(url)
                    .Build();
                }))
            });
        }
예제 #5
0
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return(new ServiceInstanceListener[]
            {
                new ServiceInstanceListener(serviceContext =>
                                            new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                    //Pull the ApplicationInsightsID from config
                    var config = serviceContext.CodePackageActivationContext.GetConfigurationPackageObject("Config");
                    var applicationInsightsID = config.Settings.Sections["Diagnostics"].Parameters["ApplicationInsightsID"].Value;

                    return new WebHostBuilder()
                    .UseKestrel()
                    .ConfigureServices(
                        services => services
                        .AddSingleton <StatelessServiceContext>(serviceContext)
                        //Add Application Insights for AspNet Core
                        .AddApplicationInsightsTelemetry(applicationInsightsID)
                        //Add telemetry extensions for service farbic & remoting tracking
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))
                        .AddSingleton <ITelemetryModule>(new ServiceRemotingDependencyTrackingTelemetryModule())
                        .AddSingleton <ITelemetryModule>(new ServiceRemotingRequestTrackingTelemetryModule())
                        )
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                    .UseUrls(url)
                    .Build();
                }))
            });
        }
예제 #6
0
 protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
 {
     return(new ServiceInstanceListener[]
     {
         new ServiceInstanceListener(serviceContext =>
                                     new KestrelCommunicationListener(serviceContext, "internal", (url, listener) =>
         {
             return new WebHostBuilder()
             .UseKestrel()
             .ConfigureServices(
                 services => services
                 .AddSingleton(serviceContext)
                 .AddSingleton <ITelemetryInitializer>((serviceProvider) => new FabricTelemetryInitializer())
                 .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))
                 .AddSingleton <ITelemetryModule>(new ServiceRemotingDependencyTrackingTelemetryModule())
                 .AddSingleton <ITelemetryModule>(new ServiceRemotingRequestTrackingTelemetryModule())
                 .AddSingleton <IActorProxyFactory>((sp) => new CorrelatingActorProxyFactory(serviceContext, callbackClient => new FabricTransportActorRemotingClientFactory(callbackClient)))
                 .AddSingleton <FabricClient>()
                 .AddTransient <IPartitionProxy, PartitionProxy>()
                 .AddTransient <IPoolProxy, PoolProxy>()
                 )
             .UseContentRoot(Directory.GetCurrentDirectory())
             .UseStartup <Startup>()
             .UseApplicationInsights()
             .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseReverseProxyIntegration)
             .UseUrls(url)
             .Build();
         }))
     });
 }
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return(new[]
            {
                new ServiceInstanceListener(serviceContext =>
                                            new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
                {
                    PlatformEventSource.GetInstance().ServiceMessage(serviceContext, $"Starting WebListener on {url}");

                    return
                    new WebHostBuilder()
                    .UseKestrel(opt => opt.AddServerHeader = false)
                    .ConfigureServices(services =>
                                       services
                                       .AddSingleton(serviceContext.CodePackageActivationContext)
                                       .AddSingleton(serviceContext.ServiceName)
                                       .AddSingleton <ITelemetryInitializer>(provider =>
                                                                             FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext)))
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseApplicationInsights()
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                    .UseUrls(url)
                    .Build();
                }))
            });
        }
예제 #8
0
        public static IServiceCollection AddApplicationInsightsServiceFabricEnricher(this IServiceCollection services, ServiceContext context)
        {
            services.AddSingleton <ITelemetryInitializer>(
                (serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(context));

            return(services);
        }
        protected override IEnumerable <ServiceReplicaListener> CreateServiceReplicaListeners()
        {
            return(new ServiceReplicaListener[1]
            {
                new ServiceReplicaListener(
                    context =>
                    new WebListenerCommunicationListener(
                        context,
                        "ServiceEndpoint",
                        (url, listener) =>
                {
                    // The idea is to create a listening port for each instance
                    // This application will never be called - the only purpose of this listener is

                    url += $"/eventsprocessor/router/{ServiceUniqueId}";

                    ServiceEventSource.Current.Message("Router Service Initialized on " + url + " - Dummy url not to be used");

                    return new WebHostBuilder()
                    .UseWebListener()
                    .ConfigureServices(
                        services => services
                        .AddSingleton <StatefulServiceContext>(this.Context)
                        .AddSingleton <IReliableStateManager>(this.StateManager)
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(context)))
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
                    .UseStartup <Startup>()
                    .UseApplicationInsights()
                    .UseUrls(url)
                    .Build();
                })
                    )
            });
        }
예제 #10
0
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceReplicaListener> CreateServiceReplicaListeners()
        {
            return(new ServiceReplicaListener[]
            {
                new ServiceReplicaListener(serviceContext =>
                                           new KestrelCommunicationListener(serviceContext, (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                    return new WebHostBuilder()
                    .UseKestrel()
                    .ConfigureServices(
                        services => services
                        .AddSingleton <HttpClient>(new HttpClient())
                        .AddSingleton <StatefulServiceContext>(serviceContext)
                        .AddSingleton <OrderBook>(this)
                        .AddSingleton <ITelemetryInitializer>(sp => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))
                        )
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseReverseProxyIntegration)
                    .UseUrls(url)
                    .Build();
                }))
            });
        }
예제 #11
0
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return(new ServiceInstanceListener[]
            {
                new ServiceInstanceListener(serviceContext =>
                                            new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                    return new WebHostBuilder()
                    .UseKestrel(options =>
                    {
                        var port = serviceContext.CodePackageActivationContext.GetEndpoint("ServiceEndpoint").Port;
                        options.Listen(IPAddress.IPv6Any, port, listenOptions =>
                        {
                            listenOptions.UseHttps(CertificateConfiguration.GetCertificate());
                            listenOptions.NoDelay = true;
                        });
                    })
                    .ConfigureServices(
                        services => services
                        .AddSingleton <StatelessServiceContext>(serviceContext)
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))
                        .AddSingleton <ITelemetryModule>(new ServiceRemotingDependencyTrackingTelemetryModule())
                        .AddSingleton <ITelemetryModule>(new ServiceRemotingRequestTrackingTelemetryModule()))
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                    .UseApplicationInsights()
                    .UseUrls(url)
                    .Build();
                }))
            });
        }
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceReplicaListener> CreateServiceReplicaListeners()
        {
            return(new ServiceReplicaListener[]
            {
                new ServiceReplicaListener(
                    serviceContext =>
                    new KestrelCommunicationListener(
                        serviceContext,
                        (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                    return new WebHostBuilder()
                    .UseKestrel()
                    .ConfigureServices(
                        services => services
                        .AddSingleton <IReliableStateManager>(this.StateManager)
                        .AddSingleton <StatefulServiceContext>(serviceContext)
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))
                        .AddSingleton <ITelemetryModule>((serviceProvider) => CreateEventSourceTelemetryModule()))
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
                    .UseStartup <Startup>()
                    .UseApplicationInsights()
                    .UseUrls(url)
                    .Build();
                }))
            });
        }
        protected AiTracedStatelessService(StatelessServiceContext serviceContext, string instrumentationKey)
            : base(serviceContext)
        {
            TelemetryConfiguration.Active.TelemetryInitializers.Add(
                FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(Context)
                );
            TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new HttpDependenciesParsingTelemetryInitializer());

            new DependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
            new ServiceRemotingRequestTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
            new ServiceRemotingDependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
        }
예제 #14
0
        public static void AddAppInsights(this IServiceCollection services, IConfiguration configuration, ServiceContext serviceContext)
        {
            services.AddApplicationInsightsTelemetry(configuration);

            var performanceCounterService = services.FirstOrDefault(t => t.ImplementationType == typeof(PerformanceCollectorModule));

            if (performanceCounterService != null)
            {
                services.Remove(performanceCounterService);
            }

            services.AddSingleton <ITelemetryInitializer>((serviceProvider) =>
                                                          FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext));
        }
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return(new ServiceInstanceListener[]
            {
                new ServiceInstanceListener(serviceContext =>
                                            new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                    return new WebHostBuilder()

                    .UseKestrel()
                    .ConfigureAppConfiguration((builderContext, config) =>
                    {
                        config.AddJsonFile(serviceContext, "appsettings.json")
                        .AddJsonFile(serviceContext, $"appsettings.{builderContext.HostingEnvironment.EnvironmentName}.json")
                        .AddEnvironmentVariables();

                        var builtConfig = config.Build();

                        if (builtConfig["AzureKeyVault:KeyVaultUri"] is var keyVaultUri && !string.IsNullOrWhiteSpace(keyVaultUri))
                        {
                            config.AddAzureKeyVault(keyVaultUri);
                        }
                    })
                    .ConfigureServices(
                        (context, services) => services
                        .AddSingleton(new HttpClient())
                        .AddSingleton(new FabricClient())
                        .AddSingleton(serviceContext)
                        .AddSingleton(context.Configuration)
                        .AddSingleton <IQueueClient>(c =>
                                                     new QueueClient(new ServiceBusConnectionStringBuilder(context.Configuration["ServiceBusQueue:SendConnectionString"]))
                                                     )
                        .AddSingleton <IDeliveryRequestRepository, DeliveryRequestRepository>()
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext)))
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseApplicationInsights()
                    .ConfigureLogging((hostingContext, logging) =>
                    {
                        logging.AddApplicationInsights(hostingContext.Configuration["ApplicationInsights:InstrumentationKey"]);
                    })
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                    .UseUrls(url)
                    .Build();
                }))
예제 #16
0
        public StatelessBackend(StatelessServiceContext context)
            : base(context)
        {
            var instrumentationKey = "<app insights instrumentation key>";

            TelemetryConfiguration.Active.TelemetryInitializers.Add(
                FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(this.Context)
                );

            TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;

            TelemetryConfiguration.Active.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new HttpDependenciesParsingTelemetryInitializer());
            new DependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
            new ServiceRemotingRequestTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
            new ServiceRemotingDependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
        }
        private static void Main()
        {
            try
            {
                ServiceRuntime.RegisterServiceAsync("MyStatelessType", context =>
                {
                    // Pull the configuration from the config package.
                    var cfg           = context.CodePackageActivationContext.GetConfigurationPackageObject("Config");
                    var appInsightsID = cfg.Settings.Sections["Diagnostics"].Parameters["ApplicationInsightsID"].Value;

                    // Create the telemetry configuration
                    var config = TelemetryConfiguration.CreateDefault();
                    config.InstrumentationKey = appInsightsID;

                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        config.TelemetryChannel.DeveloperMode = true;
                    }

                    // Add initializes for the basics
                    config.TelemetryInitializers.Add(new CodePackageVersionTelemetryInitializer());
                    config.TelemetryInitializers.Add(FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(context));

                    new AzureInstanceMetadataTelemetryModule().Initialize(config);
                    new ServiceRemotingDependencyTrackingTelemetryModule().Initialize(config);
                    new ServiceRemotingRequestTrackingTelemetryModule().Initialize(config);

                    // Pass the configuration for use
                    // Note this could benefit from Dependency Injection but this is not setup by default so to keep the example
                    // this is not used.
                    return(new MyStateless(context, new Microsoft.ApplicationInsights.TelemetryClient(config)));
                }).GetAwaiter().GetResult();

                ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(MyStateless).Name);

                // Prevents this host process from terminating so services keep running.
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceReplicaListener> CreateServiceReplicaListeners()
        {
            return(new ServiceReplicaListener[]
            {
                new ServiceReplicaListener(serviceContext =>
                                           new KestrelCommunicationListener(serviceContext, (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                    return new WebHostBuilder()
                    .UseKestrel()
                    .ConfigureAppConfiguration((builder, config) =>
                    {
                        config.AddJsonFile(serviceContext, "appsettings.json")
                        .AddJsonFile(serviceContext, $"appsettings.{builder.HostingEnvironment.EnvironmentName}.json")
                        .AddEnvironmentVariables();

                        var builtConfig = config.Build();

                        if (builtConfig["AzureKeyVault:KeyVaultUri"] is var keyVaultUri && !string.IsNullOrWhiteSpace(keyVaultUri))
                        {
                            config.AddAzureKeyVault(keyVaultUri);
                        }
                    })
                    .ConfigureServices(
                        services => services
                        .AddSingleton <StatefulServiceContext>(serviceContext)
                        .AddSingleton <IReliableStateManager>(this.StateManager)
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))
                        .AddSingleton <IDeliveryRepository, DeliveryRepository>())
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseApplicationInsights()
                    .ConfigureLogging((hostingContext, logging) =>
                    {
                        logging.AddApplicationInsights(hostingContext.Configuration["ApplicationInsights:InstrumentationKey"]);
                    })
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
                    .UseUrls(url)
                    .Build();
                }))
예제 #19
0
        public ActorBackendService(
            StatefulServiceContext context,
            ActorTypeInformation actorTypeInfo,
            Func <ActorService, ActorId, ActorBase> actorFactory = null,
            Func <ActorBase, IActorStateProvider, IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider = null,
            ActorServiceSettings settings     = null)
            : base(context, actorTypeInfo, actorFactory, stateManagerFactory, stateProvider, settings)
        {
            var instrumentationKey = "<app insights instrumentation key>";

            TelemetryConfiguration.Active.TelemetryInitializers.Add(
                FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(this.Context)
                );

            TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new HttpDependenciesParsingTelemetryInitializer());
            new DependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
            new ServiceRemotingRequestTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
            new ServiceRemotingDependencyTrackingTelemetryModule().Initialize(TelemetryConfiguration.Active);
        }
예제 #20
0
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceReplicaListener> CreateServiceReplicaListeners()
        {
            return(new ServiceReplicaListener[]
            {
                new ServiceReplicaListener(serviceContext =>
                                           new KestrelCommunicationListener(serviceContext, (url, listener) =>
                {
                    ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                    return new WebHostBuilder()
                    .UseKestrel()
                    .UseCommonConfiguration()
                    .ConfigureAppConfiguration(config => {
                        //TODO detect when MSI is available and use that
                        //webBuilder.ConfigureKeyvaultMSI()

                        var builtConfig = config.Build();

                        //TODO: these should be constants that map to environment variable config
                        config.ConfigureKeyvaultAppRegistration($"https://{builtConfig["KeyVaultName"]}.vault.azure.net/",
                                                                builtConfig["Secret"], builtConfig["AzureADApplicationId"]);

                        //config.ConfigureKeyvaultMSI($"https://{builtConfig["KeyVaultName"]}.vault.azure.net/",
                        //    builtConfig["AzureADApplicationId"]);
                    })
                    .ConfigureServices(
                        services => services
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))
                        .AddSingleton <StatefulServiceContext>(serviceContext)
                        .AddSingleton <IReliableStateManager>(this.StateManager))
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
                    .UseUrls(url)
                    .Build();
                }))
            });
        }
예제 #21
0
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return(new ServiceInstanceListener[1]
            {
                new ServiceInstanceListener(
                    context =>
                    new WebListenerCommunicationListener(
                        context,
                        "ServiceEndpoint",
                        (url, listener) =>
                {
                    // in this sample, target site application names always have the form "fabric:/Launchpad.Iot.Insight/<TargetSiteName>
                    // This extracts the target site name from the application name and uses it as the web application path.
                    string targetSiteName = new Uri(context.CodePackageActivationContext.ApplicationName).Segments.Last();
                    url += $"/{targetSiteName}";

                    ServiceEventSource.Current.Message($"Insight Service Listening on {url}");

                    return new WebHostBuilder()
                    .UseWebListener()
                    .ConfigureServices(
                        services => services
                        .AddSingleton <StatelessServiceContext>(context)
                        .AddSingleton <FabricClient>(new FabricClient())
                        .AddSingleton <HttpClient>(new HttpClient(new HttpServiceClientHandler()))
                        .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(context)))
                    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseApplicationInsights()
                    .UseUrls(url)
                    .Build();
                })
                    )
            });
        }
 protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
 {
     return(new ServiceInstanceListener[1]
     {
         new ServiceInstanceListener(
             context =>
         {
             return new WebListenerCommunicationListener(
                 context,
                 "ServiceEndpoint",
                 (url, listener) =>
             {
                 url += "/launchpad/iot";
                 ServiceEventSource.Current.Message($"Launchpad Admin WebService listening on {url}");
                 return new WebHostBuilder().UseWebListener()
                 .ConfigureServices(
                     services => services
                     .AddSingleton <FabricClient>(this.fabricClient)
                     .AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(context)))
                 .UseContentRoot(Directory.GetCurrentDirectory())
                 .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                 .UseStartup <Startup>()
                 .UseApplicationInsights()
                 .UseUrls(url)
                 .Build();
             });
         })
     });
 }
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return(new ServiceInstanceListener[]
            {
                new ServiceInstanceListener(serviceContext =>

                                            new KestrelCommunicationListener(serviceContext, Options.ServiceEndpointName, (url, listener) =>
                {
                    try {
                        _logger.LogInformation("building kestrel app for {url} in {gatewayKey}", url, Options.GatewayOptions.Key);



                        var context = serviceContext.CodePackageActivationContext;
                        var config = context.GetConfigurationPackageObject("Config");

                        var builder = new WebHostBuilder()
                                      .UseKestrel()
                                      .ConfigureServices(ConfigureServices)
                                      //   .UseCustomServiceFabricIntegration(listener as CustomKestrelCommunicationListener , ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
                                      //   .ConfigureServices((services)=>{ services.AddTransient<IStartupFilter, UseForwardedHeadersStartupFilter>(); })
                                      .UseContentRoot(Directory.GetCurrentDirectory());

                        if (Container.IsRegistered <IConfigureOptions <ApplicationInsights> >())
                        {
                            builder.UseApplicationInsights(Container.Resolve <ApplicationInsights>().InstrumentationKey);
                        }



                        builder.ConfigureServices((services) =>
                        {
                            services.AddSingleton(listener);
                            services.AddSingleton((sp) => new KestrelHostingAddresss {
                                Url = this.GetAddresses()["kestrel"]
                            });

                            services.AddSingleton <ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))
                            .AddSingleton <ITelemetryModule>(new ServiceRemotingDependencyTrackingTelemetryModule())
                            .AddSingleton <ITelemetryModule>(new ServiceRemotingRequestTrackingTelemetryModule());

                            services.AddSingleton(new CodePackageVersionTelemetryInitializer());

                            if (Container.IsRegistered <IConfiguration>())
                            {
                                services.AddSingleton((sp) => Container.Resolve <IConfiguration>());
                            }
                        });

                        if (Container.IsRegistered <IConfiguration>())
                        {
                            _logger.LogInformation("UseConfiguration for {gatewayKey}", Options.GatewayOptions.Key);
                            builder.UseConfiguration(Container.Resolve <IConfiguration>());
                        }


                        if (config.Settings.Sections.Contains("Environment"))
                        {
                            //http://stackoverflow.com/questions/39109666/asp-net-core-environment-variables-not-being-used-when-debugging-through-a-servi



                            var environments = config.Settings.Sections["Environment"];
                            if (environments.Parameters.Contains("ASPNETCORE_ENVIRONMENT"))
                            {
                                var environment = environments.Parameters["ASPNETCORE_ENVIRONMENT"].Value;
                                _logger.LogInformation("UseEnvironment {environment} for {gatewayKey}", environment, Options.GatewayOptions.Key);
                                builder = builder.UseEnvironment(environment);
                            }
                        }

//#if NETCORE10
//                            if (Container.IsRegistered<ILoggerFactory>())
//                            {
//                                _logger.LogInformation("UseLoggerFactory for {gatewayKey}", Options.GatewayOptions.Key);
//                                builder.UseLoggerFactory(Container.Resolve<ILoggerFactory>());
//                            }
//#endif

//#if NETCORE20

                        if (Container.IsRegistered <LoggerConfiguration>())
                        {
                            Container.RegisterType <SerilogLoggerProvider>(new ContainerControlledLifetimeManager(), new InjectionFactory((c) =>
                            {
                                var seriologger = new SerilogLoggerProvider(c.Resolve <Serilog.Core.Logger>(), false);
                                return seriologger;
                            }));


                            builder.ConfigureLogging((hostingContext, logging) =>
                            {
                                // logging.AddProvider(Container.Resolve<SerilogLoggerProvider>());
                                logging.AddFilter("System", LogLevel.Warning);
                                logging.AddFilter("Microsoft", LogLevel.Warning);
                                logging.AddFilter("Microsoft.AspNetCore.Authentication", LogLevel.Information);
                            });
                        }
//#endif


                        ConfigureBuilder(builder);

                        return builder.UseUrls(url).Build();
                    }catch (Exception ex)
                    {
                        _logger.LogWarning(new EventId(), ex, "failed to build app pipeline");
                        throw;
                    }
                }), "kestrel")
            });
        }