Observability
Observability
Observability
Net |
Observability
What is observability?
.Net |
Observability
Logs
Metric Tracing
.Net |
Observability
• Timestamp
• Message
• Level
• Class name
• Method name
• Formatted Message
.Net |
Observability
Metric
Low impact on performance
• CPU utilization
• Queue Count
• Error Count
• Request latency
• Number of HTTP requests
.Net |
Observability
SDK
Concept
Tracing
Data
Tracing
Data Metric
Logging Application
Metric Performance
Logging Exported Monitoring
Data
Java (APM)
Virtualization
Charts
.Net Alert
Searching
Tracing
Data
Metric
Logging
Go
.Net |
Observability
SDK
Concept
Tracing
Data
Tracing
Data Metric
Logging
Metric Application
Logging Exported
Performance
Java Data Monitoring
(APM)
.Net
Tracing
Data
Metric
Logging
Independent
Go
.Net |
Observability
OpenTelemetry
• OpenTelemetry is an open source specification
• OpenTelemetry is backed by the Cloud Native Computing Foundation (CNCF)
• OpenTelemetry is a collection of APIs, SDKs, and tools. Use it to instrument, generate, collect, and export
telemetry data (metrics, logs, and traces) to help you analyze your software’s performance and behavior.
• OpenTelemetry became an industry standard for tracing
• OpenTelemetry protocol (OTLP)
.Net |
Observability
Jeager Components
Jeager Agent
Jeager Client (The Jaeger agent is a network
daemon that listens for spans sent
Collector Jeager Query
over UDP)
Jeager UI
(you visualise the distributed
tracing data)
.Net |
Tracing
What is tracing?
Traces give us the big picture of what happens an application
Tracing is a specialized form of logging that helps you localize failures and performance issues ( by
Microsoft)
System.Diagnostics.DiagnosticSource Nuget Package is required ( Older versions of .Net 5)
.Net |
Tracing
What is tracing?
Endpoint
Call Database
Request Response
Call Another Method
What is resource?
• Service name
• Version
• Namespace
• Instance
• Static property ( for example : dev/preprod/prod)
.Net |
Tracing
What is activitySource?
Provides APIs to create and start Activity objects and to register ActivityListener
objects to listen to the Activity events.
• Activity Source is initialized once ( static or singleton )
What is span?
Span = operation ( such as http request,database call, File I/O call )
Span = Activity ( .Net Ecosytem - System.Diagnostics Namespace ) Span ( http request)
• Timestamp
• Message
• Tags( key:value)
.Net |
Tracing
Correlations ( In-Process )
App
2. Span ( Database Call/Query ) spanID ParentspanID TraceID
Jaeger
Docker compose
.Net | Jaeger
Jaeger
Zipkin
Extra Lesson
Activity Listener
.Net |
Instrumentation
Instrumentation
• AspNetCore
• HttpClients
• Entity Framework
• Redis
• RabbitMQ(MassTransit Library)
.Net |
Instrumentation
Instrumentation
OpenTelemetry.Instrumentation.AspNetCore
incoming request
API
Asp.Net
Core MVC
outgoing request
.Net |
Instrumentation
AspNetCore Instrumentation
Tracing only endpoints
.Net |
Instrumentation
AspNetCore Instrumentation
Jeager tracing platform
.Net |
Instrumentation
AspNetCore Instrumentation
Exception
.Net |
Instrumentation
AspNetCore Instrumentation
Tag / Event
.Net |
Instrumentation
AspNetCore Instrumentation
Refactoring
.Net |
Instrumentation
AspNetCore Instrumentation
Request and Response body
.Net | Instrumantation
Instrumentation
OpenTelemetry.Instrumentation.EntityFrameworkCore
transaction
API
.Net | Instrumantation
Instrumentation
OpenTelemetry.Instrumentation.EntityFrameworkCore (2.ders)
transaction
API
.Net | Instrumantation
Instrumentation
OpenTelemetry.Instrumentation.Http ( Ders 1)
External
API API
.Net | Instrumantation
Instrumentation
OpenTelemetry.Instrumentation.Http ( Ders 2)
External
API API
.Net | Instrumantation
Instrumentation
OpenTelemetry.Instrumentation.Http ( Ders 3)
External
API API
.Net | Instrumentation
Instrumentation
OpenTelemetry.Instrumentation.Redis ( ders 2)
transaction
API
.Net | Instrumantation
Instrumentation
OpenTelemetry.Instrumentation.Redis
transaction
API
.Net | Distributed Tracing
Request
Tracing
.Net | Distributed Tracing Microservice Apps
Request Header
X-correlation-id
X-request-id
Microservice Microservice
Gateway
2 2
Response 6
Service 1
Request 1 Response 5
Request 2
G
a
Correlation ID:Unique Value
(Request tHeader) Service 2
e
Client w
a
y Request 3
Service 3 Response 4
Trace Context
• W3C standard ( built-in with .Net 5+ )
Request Header
traceparent 00-2a8ee37903e657e3a95b41178dafc56e-91b02006afcf3133- 01
• version
• trace Id (16 bytes) ( extract incoming requet header)
• Parent span Id
Tracestate • Trace Flag (01= true, 00=false. whether save trace )
• Default Format since .Net 5
.Net |
Observability Microservice Apps
Distributed tracing
Payment API
.Net | Distributed Tracing
Distributed tracing
Stock API => Payment API
.Net | Distributed Tracing
Distributed tracing
Jaeger
.Net |
Observability Microservice Apps
Request
Baggage traceparent
Tracestate
Key=value
Example : UserId=1234
Message Broker
Header
Payload
Message Broker
.Net | Message Broker
TraceContext
Header
Dictionary<string,string> Header
string Payload
Payload
.Net | Message Broker
MassTransit
MassTransit provides a developer-focused, modern platform for
creating distributed applications without complexity.
RabbitMQ
Docker Compose
.Net | Message Broker
RabbitMQ
Order API ( Producer )
.Net | Message Broker
RabbitMQ
Stock API ( Consumer )
.Net | Message Broker
RabbitMQ
OpenTelemetry.Instrumentation.MassTransit
.Net | Logs
Logs
Logging is a technique
a record of interesting events that occurred while the program was running ( by Microsoft)
• Timestamp
• Level
• ClassName
• MethodName
• Formatted Message
.Net | Logs
Log Levels
• Trace=0
• Debug=1 Trace or Debug messages when troubleshooting
• Information=2
• Warning=3
• Error=4
• Critical=5
.Net | Logs
Log Event ID
public EventId Create = new(100, "Created");
public EventId Update = new(101, “Updated");
For Example : all logs related to reading values from a repository might be 100
.Net | Logs
Log Template
Log
Ne ( örnek:sipariş oluşmadı)
Niçin ( örnek : sipariş olmadı. Şu sebeple )
.Net | Logs
Practical Senario -1
Jeager/Zipkin
Logs
Elasticsearch/
Kibana
Exceptions
.Net | Logs
Senario -1
Senario -1
Serilog Library
.Net | Logs
Senario -1
Senario -1
Senario -1
Senario -1
Bug fixed
.Net | Logs
Senario -2
Logs
.Net | Logs
Scenario -2
OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs package
.Net | Logs
Scenario -2
What is collector
The OpenTelemetry Collector offers a vendor-agnostic implementation of how to
receive, process and export telemetry data ( by OpenTelemetry)
App
Collector configuration
App
Open
Telemetry Backends
SDK (Console,Prometheus,Jeager,zipkin)
.Net | Deployment
Agent For production app
App
App
OpenTelemetry
Collector
Backends
Load OpenTelemetry
Open balancer Collector
(Console,Prometheus,Jeager,zi
pkin)
Telemetry OpenTelemetry
Collector
SDK
.Net | Best
Practice
Naming attributes/tags
Naming is known to be one of the hardest problems in computer science.
App
What is metric?
A metric is a measurement about a service
Metrics are numerical measurements reported over time ( by Microsoft )
They are used to monitor the health of an app
The key difference between traces and metrics is aggregation
Metrics are aggregated in memory before they are exported
Trace Metric
.Net | Metric
Example metrics
• Resource comsuption
• Open connection count
• Requests it received per second. Request-response time > 500 ms
• Milliseconds it took to respond.
Alert
• Error responses sent.
• Count of send message
• Count of send email
App Prometheus
yaml
Metric data
.Net | Metric
Prometheus
Prometheus is an open-source systems monitoring and alerting toolkit
.Net | Metric
OpenTelemetry metrics
System.Diagnostics.DiagnosticSource Nuget Package
System.Diagnostics.Metrics Namespace
Create the Meter once, store it in a static variable or DI container
• Counter
• UpDownCounter
• Gauge
• Histogram
.Net | Metric
Counter metrics
this instrument tracks a value that increases over time
Calculate rate of change and total count
• Sold item
• Enqueue Message count
Counter metrics
• Metric App Container
• Prometheus Container
• Prometheus.yaml
.Net | Metric
Counter metrics
Asp.Net Core Configuration
.Net | Metric
CounterObservable metrics
Meter.CreateObservableCounter("orders-canceled",
() => new Measurement<int>(10), "count", "amounts of cancelled orders");
UpDownCounter metrics
this instrument tracks a value(negative or positive) that increases over time
Calculate rate of change and total count
CounterUpDownObservable metrics
Meter.CreateObservableUpDownCounter("current_stock_observable_count",
()=> new Measurement<int>(new Random().Next(-10,10)),"count", "current stock
count (totally)");
Gauge metrics
current value of a non-additive metric
Meter.CreateObservableGauge("room_kitchen_temperature",
() => new Measurement<int>(new Random().Next(10, 30)), "celcius",
"room_kitchen temperature");
Metric Instrumantation
OpenTelemetry.Instrumentation.Runtime
process-level metrics for CPU and memory utilization
OpenTelemetry.Instrumentation.Process