-
Notifications
You must be signed in to change notification settings - Fork 13
Gather telemetry
| Main > Using Liquid for building your application > Gather telemetry |
|---|
In software, telemetry is used to gather data on the use of applications and application components, e.g. how often certain features are used, measurements of start-up time and processing time, hardware, application crashes, and general usage statistics.
| Take a look at related key concepts of Liquid |
|---|
| Business Logic Separation |
| Leveling up Platform Providers |
##From back-end
In the project StartUp file it is necessary to define that Liquid will use the telemertry, in this case, Azure AppInsights.
WorkBench.UseTelemetry<AppInsights>();
##appsettings.json It is also necessary to set in the appsettings, the instrumentation key of AppInsights to Liquid load the configuration.
"AppInsights": {
"InstrumentationKey": "3de84743-7611-4768-95c7-250c54546257"
}
| See how this is done in Liquid Hotel360 sample application. |
|---|
##Generate custom events and metrics
Now it's possible to use Telemetry anywhere in the code
public async Task<DomainResponse> AddAsync(BasketModel basket)
{
Telemetry.TrackEvent("New Basket");
//Persist data on database
var data = await Repository.AddOrUpdateAsync(basket);
//Then it sends to AppInsights a metric of how much time was spent for inserting data.
Telmetry.TrackMetric("time-save-database", Convert.ToDouble(stopWatch.Elapsed));
}
| See how this is done in Liquid Hotel360 sample application. |
|---|
##Generate computed (aggregated) metrics
public async Task<DomainResponse> ItemProcess()
{
//Declaration of dictionary key that will be used for begin count the timestamp.
Telemetry.BeginMetricComputation("item-process-basket");
//Create values for input aggregate metrics on AppInsights
var fibNumbers = new List<int> { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 };
foreach (int item in fibNumbers)
{
//Just for check a final timestamp
Thread.Sleep(10000);
//Track values for generate aggregation.
Telemetry.ComputeMetric("item-process-basket", item);
}
//Finishing aggregating metrics and submitting to AppInsights
Telemetry.EndMetricComputation("item-process-basket");
return new DomainResponse() { };
}
| See how this is done in Liquid Hotel360 sample application. |
|---|
##Management of Telemetry Hierarchies
public IActionResult Post([FromBody] BasketViewModel basket)
{
Telemetry.EnqueueContext("Basket", basket.BasketId, "Add");
//When call another method, all telemetry events could be visualized on the same tree.
var data = Factory<BasketService>().AddAsync(basket);
//After executing all calls we cause the telemetry client to lose the context.
Telemetry.DequeueContext();
}
| See how this is done in Liquid Hotel360 sample application. |
|---|
##Telemetry on Kubernates
public override void Initialize()
{
AppInsightsConfiguration appInsightsConfiguration = LightConfigurator.Config<AppInsightsConfiguration>("AppInsights");
TelemetryConfiguration aiConfig = new TelemetryConfiguration(appInsightsConfiguration.InstrumentationKey);
if(appInsightsConfiguration.EnableKubernetes)
{
aiConfig.EnableKubernetes();
}
TelemetryClient = TelemetryClient ?? new TelemetryClient(aiConfig) { InstrumentationKey = aiConfig.InstrumentationKey } ;
}
| See how this is done in Liquid Hotel360 sample application. |
|---|
#From front-end
For the configuration in FrontEnd it is necessary to set the instrumentation key in the environment.ts file.
appInsights: {
instrumentationKey: '5af50bad-3bb6-4504-b353-45cae74a416a'
}
In the project module, in this case, app.module.ts is necessary to tell which class will be injected at runtime.
providers: [
WorkBench,
AuthenticationService,
{ provide: 'ILightTelemetry', useClass: AppInsightsTelemetry }
]
| See how this is done in Liquid Hotel360 sample application. |
|---|
##Generate custom events and metrics
export class CreateComponent implements OnInit {
basketId = 2;
constructor(private api: APIService, @Inject('ILightTelemetry') private telemetryService: ILightTelemetry,
private auth: AuthenticationService) { }
ngOnInit() {
this.telemetryService.TrackEvent('New view in Basket page');
this.telemetryService.TrackMetric('time-load-page', OnInit.pageRender.Elapsed);
}
| See how this is done in Liquid Hotel360 sample application. |
|---|