#
HoneycombInstrumentationClient
A lightweight client providing access to Honeycomb instrumentation utilities.
#
Methods
setGlobalSpanAttribute(key, value): Set a single global attribute to be included in all traces.setGlobalSpanAttributes(attributes): Set a single or multiple global attributes to be included in all traces.registerFetchRequestHook(hook): Dynamically registers fetch request hook at the end of the pipeline.registerFetchRequestHookAtStart(hook): Dynamically registers a fetch request hook at the start of the pipeline.
#
Usage
#
Register global attributes
import { useHoneycombInstrumentationClient } from "@workleap/telemetry/react";
const client = useHoneycombInstrumentationClient();
client.setGlobalSpanAttributes({
"app.user_id": "123"
});
#
Register a dynamic request hook
import { useHoneycombInstrumentationClient } from "@workleap/telemetry/react";
const client = useHoneycombInstrumentationClient();
client.registerFetchRequestHook((requestSpan, request) => {
let headers: Headers;
if (request instanceof Request) {
const moduleId = request.headers.get("x-module-id");
if (moduleId) {
requestSpan.setAttribute("app.module_id", moduleId);
}
}
});
#
Register a dynamic request hook to be executed first
import { useHoneycombInstrumentationClient } from "@workleap/telemetry/react";
const client = useHoneycombInstrumentationClient();
client.registerFetchRequestHookAtStart((requestSpan, request) => {
let headers: Headers;
if (request instanceof Request) {
const moduleId = request.headers.get("x-module-id");
if (moduleId) {
requestSpan.setAttribute("app.module_id", moduleId);
}
}
});
#
Prevent the execution of subsequent request hooks
A dynamic request hook can stop the execution of subsequent request hooks by returning true.
import { useHoneycombInstrumentationClient } from "@workleap/telemetry/react";
const client = useHoneycombInstrumentationClient();
client.registerFetchRequestHookAtStart((requestSpan, request) => {
let headers: Headers;
if (request instanceof Request) {
const moduleId = request.headers.get("x-module-id");
if (moduleId) {
requestSpan.setAttribute("app.module_id", moduleId);
// Indicates to not propagate the requests to the subsequent hooks.
return true;
}
}
});
See also
If telemetry hasn't been set up for your project yet, please refer to the setup guide before continuing.
To migrate to the new @workleap/telemetry umbrella package, follow these steps 👇
This major version remove the global variables deprecated in the previous versions of the standalone libraries and introduce a productFamily argument.
This major version introduces several important changes. registerHoneycombInstrumentation now returns a client instance. The standalone
This major version remove the global variables deprecated in v7.0.
initializeTelemetry
Don't create your own instance of TelemetryClient, use the initializeTelemetry function instead.
Retrieve a HoneycombInstrumentationClient instance.