Measurement Metadata
You can provide custom metadata when creating a new instrument or when invoking the done()
or fail()
methods of an instrument.
Providing metadata is useful for:
- Filtering measurements when creating indicators in Polaris.
- Providing additional context when debugging issues.
Let's take a look at an example of each.
Add Metadata
Let's add custom metadata to a measurement.
React
export function App() {
const instrument = useInstrument('event-name');
useEffect(() => {
instrument.start({
tier: user.tier
});
}, [instrument]);
}
Let's review the code above.
- We create a new instrument using the
useInstrument()
hook. - We start the measurement using the
start()
method of theInstrument
. - When starting the measurement we optionally provide the metadata object. In this case we are providing the
tier
of the user.
Add Metadata when Completing a Measurement
You can also add metadata when invoking the done()
or fail()
methods on the Instrument
.
React
export function App() {
useEffect(() => {
instrument.start();
authenticate()
.then(() => instrument.done({
attribute3: 'value3',
attribute4: 'value4',
}))
.catch((error) => instrument.error({ error, attribute5: 'value5', attribute6: 'value6' }));
}, [authenticate, instrument]);
}
Let's review the code above.
- We create a new instrument using the
useInstrument()
hook. - We start the measurement using the
start()
method of theInstrument
. - We invoke the
done()
method of theInstrument
when the authentication is successful. - We invoke the
fail()
method of theInstrument
when the authentication fails.