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.
TypeScript
const instrument = getInstrument('event-name');
instrument.start({
tier: user.tier,
});
Let's review the code above.
- First, we create a new instrument using the
getInstrument()
method. - Next, we call the
start()
method of the instrument and provide an object with custom metadata.
Add Metadata when Completing a Measurement
You can also add metadata when invoking the done()
or fail()
methods on the Instrument
.
TypeScript
const instrument = getInstrument('event-name');
try {
instrument.start({
tier: user.tier,
});
// code we want to measure
instrument.done({
attribute3: 'value3',
attribute4: 'value4',
});
} catch (error) {
instrument.fail(error, {
attribute5: 'value5',
attribute6: 'value6',
});
}
Let's review the code above.
- First, we create a new instrument using the
getInstrument()
method. - Next, we invoke the
start()
method of the instrument and provide an object with custom metadata. - Then, we invoke the
done()
method of the instrument and provide an object with custom metadata. - Finally, we call the
fail()
method of the instrument and provide an object with custom metadata.