@embrace-io/react-native-navigation
Version:
A React Native wrapper for the OTel Navigation instrumentation library that creates telemetry data representing Navigation changes
35 lines (34 loc) • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const api_1 = require("@opentelemetry/api");
const version_1 = require("../../version");
const useConsole_1 = require("./useConsole");
const useTracerRef = (provider, config) => {
const { debug, tracerOptions } = config !== null && config !== void 0 ? config : {};
const tracerRef = (0, react_1.useRef)(null);
const console = (0, useConsole_1.default)(!!debug);
(0, react_1.useEffect)(() => {
if (tracerRef.current === null) {
if (!provider) {
console.info("[Embrace] No TracerProvider found. Using global tracer instead.");
}
else {
console.info("[Embrace] TracerProvider. Using custom tracer.");
}
tracerRef.current = provider
? provider.getTracer(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, tracerOptions)
: // using global tracer provider
api_1.trace.getTracer(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION);
}
// this is useful in cases where the provider is passed but it's still `null` or `undefined` (given a re-render or something specific of the lifecycle of the app that implements the library)
if (tracerRef.current !== null &&
provider !== undefined &&
provider !== null) {
tracerRef.current = provider.getTracer(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, tracerOptions);
console.info("[Embrace] Updated TracerProvider. Switching to the new instance.");
}
}, [console, provider, tracerOptions]);
return tracerRef;
};
exports.default = useTracerRef;