Skip to content

1. Diol backend service

Chingiz Olzhabaev edited this page Aug 14, 2024 · 4 revisions

Introduction

Still in progress! Don't use it for your production!

DiolBackendService is an aspnet application which contains a logic how to read, parse and group events from a dotnet application.

You may want to use the project in case if you need DIOL behavior but for your own UX.

The project is designed to be a web service, because an user may want to create their own UX on non-dotnet environment.

Basinc information

# Title Description
1 Name DiolBackendService
2 Link Project link
3 dotnet version net 8
4 Project type asp.net
5 Communication SignalR
6 Distribution as a dotnet tool

Dependencies

Internal

# Name Description
1 Diol.Share Contains DTO and basic contracts
2 Diol.Core Contains basic logic of logs processing
3 Diol.Aspnet Logic for asp.net related things

External

# Name License
1 Microsoft.Diagnostics.NETCore.Client MIT
2 Microsoft.Diagnostics.Tracing.TraceEvent MIT

DEMO run

DiolBackendService provides a page where you can be used as an example of using DiolBackendService.

To run a demo please follow next steps:

  1. Navigate to DiolBackendService
  2. Call dotnet build
  3. Call dotnet run
  4. New web app should opened in your browser
  5. Click connect
  6. Provide process id
  7. Click 'Start'
  8. Navigate to your project
  9. Make a request
  10. Check DiolBackendService page. In the table you should see your logs

How to use

Before starting please learn more information about aspnet signal r and chouse correct client version (js, C# and etc.). Documentation

We created an example for JS but it should be enough for implementing the same for other languages.

The whole source code of the example you may find here

1. Create a connection to LogsHub

const connection = new signalR.HubConnectionBuilder()
   .withUrl("/logsHub")
   .configureLogging(signalR.LogLevel.Information)
   .build();

2. Subscribe to LogRecieved

function logsReceivedHanndler(categoryName, eventName, dataAsJson) {
   // categoryName: ['HttpClient', 'AspnetCore', etc]
   // eventName: Dto name
   let data = JSON.parse(dataAsJson);
   console.info(categoryName, eventName, data );
}

connection.on('LogReceived', logsReceivedHanndler);

3. Connect to the SignalR hub

connection.start();

4. Start fetching logs from a dotnet process

let processId = <some_dotnet_process_id>;
connection.invoke('Subscribe', processId);

Hubs metadata

Hub info

Property Value Description
1 Name LogsHub
2 Type Hub
3 Url /logsHub
4 Link Link

Hub actions

# Name Arguments Description
1 GetProcesses message: string? Ask from the server a list with dotnet processes. The result will be sended as an event 'ProcessesReceived'
2 Subscribe processId: int Start processing a dotnet process. In client side you will recieve 'ProcessingStarted' event.

Hub events

You can find all events and dtos in the repo

# Name Result Description
1 ProcessesReceived x x
2 ProcessingStarted x x
3 ProcessingFinished x x
4 LogReceived x x
  • ProcessesReceived
  • ProcessingStarted
  • ProcessingFinished
  • LogReceived

ProcessesReceived

Result: list of dotnet processes.

ProcessingStarted

Result: id of process

ProcessingFinished

Result: id of process

LogReceived

This event happen every time when the process recieve logs.

result:

  1. CategoryName | Logs Events
  2. EventName | Dto name
  3. Data | data as string json

Logs Events

  • HttpClient
  • AspnetCore
  • Entity Framework
  • WebSockets

HttpClient

Order Name Dto
1 RequestPipelineStartDto RequestPipelineStartDto
2 RequestPipelineRequestHeaderDto RequestPipelineRequestHeaderDto
3 RequestPipelineEndDto RequestPipelineEndDto
4 RequestPipelineResponseHeaderDto RequestPipelineResponseHeaderDto

AspnetCore

Order Name Dto
1 RequestLogDto RequestLogDto
2 RequestBodyDto RequestBodyDto
3 ResponseLogDto ResponseLogDto
4 ResponseBodyDto ResponseBodyDto

Entity Framework

Order Name Dto
1 ConnectionOpeningDto ConnectionOpeningDto
2 CommandExecutingDto CommandExecutingDto
3 CommandExecutedDto ConnectionOpeningDto

WebSockets

Coming soon...

DTOs

RequestPipelineStartDto

Field Type Info
CategoryName string defaultValue: 'HttpClient'
EventName string defaultValue: 'RequestPipelineStartDto'
HttpMethod string Get, post, put and etc.
Uri string request url

RequestPipelineRequestHeaderDto

Field Type Info
CategoryName string defaultValue: 'HttpClient'
EventName string defaultValue: 'RequestPipelineRequestHeaderDto'
Headers Dictionary<string, string> Request headers. key - is header name, value is header value

RequestPipelineEndDto

Field Type Info
CategoryName string defaultValue: 'HttpClient'
StatusCode int 200, 404, 500 and etc.
ElapsedMilliseconds TimeSpan request duration

RequestPipelineResponseHeaderDto

Field Type Info
CategoryName string defaultValue: 'HttpClient'
EventName string defaultValue: 'RequestPipelineRequestHeaderDto'
Headers Dictionary<string, string> Reponse headers. key - is header name, value is header value

RequestLogDto

Field Type Info
CategoryName string defaultValue: 'AspnetCore'
EventName string defaultValue: 'RequestLogDto'
Protocol string http1, http2 and etc.
Method string get, post, put and etc.
Scheme string http, https and etc.
Host string domain name
Path string paht. like api/some-resource
Metadata Dictionary<string, string> request headers.

RequestBodyDto

Field Type Info
CategoryName string defaultValue: 'AspnetCore'
EventName string defaultValue: 'RequestLogDto'
BodyAsString string request body as string
Metadata Dictionary<string, string>

ResponseLogDto

Field Type Info
CategoryName string defaultValue: 'AspnetCore'
EventName string defaultValue: 'RequestLogDto'
StatusCode int 200, 404 and etc.
ContentType string application/json or etc.
Metadata Dictionary<string, string> Response headers

ResponseBodyDto

Field Type Info
CategoryName string defaultValue: 'AspnetCore'
EventName string defaultValue: 'RequestLogDto'
BodyAsString string response body as string
Metadata Dictionary<string, string>

ConnectionOpeningDto

Field Type Info
Database string
Server string

CommandExecutingDto

Field Type Info
Parameters string
CommandText string SELECT * FROM YOUR_TABLE

CommandExecutedDto

Field Type Info
ElapsedMilliseconds TimeSpan Execution time

Clone this wiki locally