Measurement Metadata
You can provide custom metadata when starting a new measurement or when completing a measurement using either the done()
or fail()
methods of the Instrument
.
Providing metadata is useful for:
- Filtering measurements when creating indicators in Polaris.
- Providing additional context when debugging issues.
Add Metadata
Let's add custom metadata to a measurement.
app.component.ts
export class AppComponent {
onAuthenticate() {
const instrument = inject(PolarisService).getInstrument('event-name');
instrument.start({
tier: user.tier,
})
}
}
Let's review the code above.
- First, we get an instrument using the
getInstrument()
method of thePolarisService
. - Next, we call the
start()
method of theInstrument
and pass in an object as the first parameter with our metadata.
Add Metadata when Completing a Measurement
You can also add metadata when invoking the done()
or fail()
methods on the Instrument
.
app.component.ts
export class AppComponent {
onAuthenticate() {
const instrument = inject(PolarisService).getInstrument('event-name');
// code you want to measure
instrument.done({
attribute1: 'value1',
attribute2: 'value2',
});
}
}
You can also add metadata when indicating a failure using the fail()
method.
Angular
export class AppComponent {
onAuthenticate() {
const instrument = inject(PolarisService).getInstrument('event-name');
try {
// code you want to measure
} catch (error) {
instrument.fail({
attribute1: 'value1',
attribute2: 'value2',
});
}
}
}