Skip to content

Commit

Permalink
More information regarding sample in the user guide
Browse files Browse the repository at this point in the history
  • Loading branch information
martinothamar committed May 30, 2024
1 parent 813ee98 commit 11d8a88
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
19 changes: 18 additions & 1 deletion content/altinn-studio/guides/monitor-and-instrument/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ and to Azure monitor when running in an environment.

The most straightforward way of getting familiar with the Altinn.App instrumentation APIs is by creating
a simple *IHostedService* implemented in *Program.cs*. This way we can get some code running which we can experiment with.
An *IHostedService* that is registered with *AddHostedService* will ensure that its' *StartAsync* is invoked
during startup for the process/container. The goal of this example is to get acquainted with the telemetry API and monitoring
solution. In practice, we will get a counter that increments by 1 when the app starts, and a trace containing a child-span
and a related log-message.

We recommend experimenting more with this example - add different types of metric, add attributes to traces etc.

The telemetry and instrumentation APIs of the Altinn.App library are exposed through the *Telemetry* class.
It is a thread-safe singleton object available in the dependency injection container.
Expand Down Expand Up @@ -80,8 +86,19 @@ sealed class StartupService(ILogger<StartupService> logger, Telemetry telemetry)
}
```

Now we can register this class in the .NET dependency injection container, which will ensure
that *StartAsync* is called when the process starts up.

```csharp
void RegisterCustomAppServices(IServiceCollection services, IConfiguration config, IWebHostEnvironment env)
{
services.AddHostedService<StartupService>();
}
```

Now you can run the app. Below in the next section we will take a look at visualisation of the telemetry above.

[Read more about instrumentation on the instrumentation reference page](/altinn-studio/reference/monitoring/instrumentation).
[You can also read more about instrumentation on the instrumentation reference page](/altinn-studio/reference/monitoring/instrumentation).

## Visualisation

Expand Down
25 changes: 23 additions & 2 deletions content/altinn-studio/guides/monitor-and-instrument/_index.nb.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ og til Azure Monitor ved kjøring i et miljø.

## Egendefinert instrumentering

Vi illustrerer egendefinert instrumentering med et eksempel. I *Program.cs* legger vi til en simpel *IHostedService* implementasjon
Vi illustrerer egendefinert instrumentering med et enkelt eksempel.

I *Program.cs* legger vi til en simpel *IHostedService* implementasjon
som kan instrumenteres til å eksponere telemetri.
En *IHostedService* som registreres med *AddHostedService* vil sørge for at *StartAsync* kjøres
som del av oppstarts-prosedyren i prosessen/containeren. Målet med dette eksempelet
er å få ut noe telemetri som man kan se i visualiseringverktøy lokalt og bli kjent med løsningen.
I praksis vil vi få et tall som økes med 1 når appen startes, og en trace som inneholder en child-span og relateres til en
logg-melding.

Vi anbefaler å eksperimentere mer med dette eksempelet - test ut andre types metrikker, legg til attributter på traces o.l.

Telemetri- og instrumentering-APIene i Altinn.App biblioteket blir eksponert gjennom *Telemetry*-klassen. Det er
et trådsikkert singleton-objekt tilgjengelig i dependency injection containeren.
Expand Down Expand Up @@ -79,7 +88,19 @@ sealed class StartupService(ILogger<StartupService> logger, Telemetry telemetry)
}
```

[Les mer om instrumenteringsmuligheter på referansesiden for instrumentering](/nb/altinn-studio/reference/monitoring/instrumentation).
Nå kan vi registrere klassen i .NET sin dependency injection container, some vil sørge for at
*StartAsync* blir kjørt når prosessen starter opp.

```csharp
void RegisterCustomAppServices(IServiceCollection services, IConfiguration config, IWebHostEnvironment env)
{
services.AddHostedService<StartupService>();
}
```

Nå kan du kjøre appen. Under i neste seksjon skal vi se på visualisering av telemetrien over.

[Du kan også lese mer om instrumentering på referansesiden for instrumentering](/nb/altinn-studio/reference/monitoring/instrumentation).

## Visualisering

Expand Down

0 comments on commit 11d8a88

Please sign in to comment.