Giter Site home page Giter Site logo

aresundnes / azure-service-fabric-logging-and-monitoring Goto Github PK

View Code? Open in Web Editor NEW

This project forked from expecho/azure-service-fabric-logging-and-monitoring

0.0 0.0 0.0 1.24 MB

This repository contains an Azure Service Fabric application that integrates Application Insights with Service Fabric using structured logging.

License: MIT License

Batchfile 0.11% C# 80.97% PowerShell 18.92%

azure-service-fabric-logging-and-monitoring's Introduction

Overview

This repository contains an Azure Service Fabric application that provides some guidance and examples on how to setup and configure logging and demonstrates some approaches. It is probably not production ready but it gives a working overview on how things are working together. Please see it as a good starting point for your own integration.

The application consist of two stateless services, one hosting an ASP.Net Core application that acts as an Web Api and a stateless service that is being called from the Web Api using Service Remoting.

Application Overview

It uses a structured logging framework called Serilog to log events. The logged events are then written to Application Insights using this Serilog sink. By using Serilog to capture the events instead of logging directly to Application Insights using the SDK it is easy to add different outputs for the logged events.

Also this repository contains the NuGet package ServiceFabric.Logging.

You can directly install this library from Nuget

PM> Install-Package ServiceFabric.Logging

NuGet package NuGet

How it works

.Net Core provides a logging abstraction that provides support for structured logging. Since Serilog is supported by the .Net Core logging abstraction we can seperate the calls to the logger from the actual implementation. (For more background about this, read this excellent blog post)

By using custom Middleware in the ASP.Net Core pipeline we can capture the trace id of the request and use that in the logging to correlate log events. Calls from the Web Api to the other stateless service are intercepted and logged.

Most other logging frameworks provide Application Insights sinks that are only capable of writing Trace entities to Application Insights. Using structured logging gives the advantage to transform the log events to specific Application Insights entities like Requests, Dependencies, Metrics and Exceptions. This is done by the TelemetryBuilder class.

Features

  • Full Application Insights Integration
  • Structured Logging
  • Easy to add other sinks
  • Integration with .Net Core logging framework

Getting started

This source is build and tested using Azure Service Fabric 6.2 and SDK 3.1, with Visual Studio 2017 v15.1

Before running the sample create a new Application Insights resource and copy the Instrumentation Key to the application parameter in the Service Fabric Application manifest file:

<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="AzureServiceFabric.Demo.DiagnosticsType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
  <Parameters>
    <Parameter Name="WebApi_InstanceCount" DefaultValue="-1" />
    <Parameter Name="MyStateless_InstanceCount" DefaultValue="-1" />
    <Parameter Name="ApplicationInsightsKey" DefaultValue="[YOUR_KEY-HERE]" />
  </Parameters>

Deploy the application, wait for all services to be up and running and point the browser to the web api at http://localhost:8700/api/values?a=1&b=2

Application Insights integration

Observe the events written to application insights:

Application Insights

All telemetry includes service fabric specific metadata:

Application Insights

Live telemetry like cluster load (per node) and traffic can be viewed in the Live Metrics Stream:

Application Insights Live Metrics Stream

Additional Resources

This repository is focused on using structured logging using Serilog in order to provide rich en detailed logging output. If you are not familiar with structured logging these links provide some insights about the what and why:

azure-service-fabric-logging-and-monitoring's People

Contributors

expecho avatar marusyk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.