Skip to content

Instantly share code, notes, and snippets.

namespace Integration.Observability.Constants
{
/// <summary>
/// Constants used for Logging and Tracing
/// </summary>
public class LoggingConstants
{
/// <summary>
/// To identify the tracing span checkpoints (e.g. start or finish of each span)
/// Enum values follow the structure spanId + checkPoint
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using ServerlessRequestBin.DurableFunctions.Models;
namespace ServerlessRequestBin.DurableFunctions
{
traces
| sort by timestamp desc
| where customDimensions.EventId > 1
| where customDimensions.LogLevel == 'Error'
| project EventId = tostring(customDimensions.EventId)
| summarize Count = count(EventId) by EventId
//Change the pEntityId to get the traces for a particular business document
let pEntityId = "2000";
traces
| sort by timestamp desc
| where customDimensions.EventId > 1
| where customDimensions.prop__CheckPoint == 'Publisher'
| where customDimensions.prop__EntityId == pEntityId
| project Level = customDimensions.LogLevel
, PublisherEventId = customDimensions.EventId
, PublisherEventDescription = customDimensions.prop__EventDescription
//Properties used with Azure Functions structure logging are logged as customDimensions.prop__{name}
//To filter events created by our custom structured logging, get only those traces where EventId > 1
//To correlate different checkpoints, we use the CorrelationId
traces
| sort by timestamp desc
| where customDimensions.EventId > 1
| where customDimensions.prop__CheckPoint == 'Publisher'
| project Level = customDimensions.LogLevel
, PublisherEventId = customDimensions.EventId
, PublisherEventDescription = customDimensions.prop__EventDescription
//Properties used with Azure Functions structure logging are logged as customDimensions.prop__{name}
//To filter events created by our custom structured logging, get only those traces where EventId > 1
traces
| sort by timestamp desc
| where customDimensions.EventId > 1
| project Level = customDimensions.LogLevel
, EventId = customDimensions.EventId
, CheckPoint = customDimensions.prop__CheckPoint
, CorrelationId = customDimensions.prop__CorrelationId
, Description = customDimensions.prop__Description
{
"version": "2.0",
"logging": {
"logLevel": {
"default": "Information"
},
"aggregator": {
"batchSize": 100,
"flushTimeout": "00:00:10"
},
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.IO;
namespace PacodelaCruz.AzureFunctions.Logging
{
public static class ProcessOrder
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.IO;
namespace PacodelaCruz.AzureFunctions.Logging
{
/// <summary>
/// Contains constants and enums for consistent structured logging
/// </summary>
internal static class LoggingConstants
{
// Template for consisted structured logging accross multiple functions, each field is described below:
// EventDescription is a short description of the Event being logged.
// EntityType: Business Entity Type being processed: e.g. Order, Shipment, etc.