Skip to content

Latest commit

 

History

History
85 lines (56 loc) · 2.13 KB

logging.md

File metadata and controls

85 lines (56 loc) · 2.13 KB

Logging with Application Insights

  • Page views will be tracked by default when router changes occur. Note that this doesn't include overlays (see trackPageView).

  • Uncaught browser exceptions will also be tracked by default. For manually logging exceptions (see trackException).

  • HTTP requests will also be tracked by default, so no manually tracking is nesecary.

⚠️ Note: traceparent header won't be added on outgoing requests in the mocking environment due to the usage of MSW (Mock Service Worker). To see the traceparent header, run the development environment instead.

bun dh:dev

Getting started

To send telemetry to Application Insights, you must import the DhApplicationInsights service from @energinet-datahub/dh/shared/util-application-insights.

import { DhApplicationInsights } from  '@energinet-datahub/dh/shared/util-application-insights';

// ...
private readonly appInsights = inject(DhApplicationInsights);

trackEvent

Log a user action or other occurrence.

DhApplicationInsights.trackEvent('some event');

trackTrace

Log a diagnostic scenario such as entering or leaving a function.

DhApplicationInsights.trackTrace('some message');

trackPageView

Logs that a page or similar container was displayed to the user. Use this for tracking overlays.

DhApplicationInsights.trackPageView('name of overlay');

trackException

Log an exception that you have caught.

DhApplicationInsights.trackException({
  exception: new Error('some error'),
  severityLevel: 3, // Severity level of error
});

Common queries for Application Insights in Azure Portal

The best way to get started learning to write log queries using KQL is leveraging available tutorials and samples.

Page views

pageViews
| where client_Type == 'Browser'

Events

customEvents
| where name == 'Custom event'

Exceptions

exceptions
| where itemType == 'exception'
| where client_Type == 'Browser'