@embrace-io/web-sdk
Version:
3 lines (2 loc) • 2.67 kB
JavaScript
import{__extends as e}from"tslib";import{EmbraceInstrumentationBase as n}from"../../EmbraceInstrumentationBase/EmbraceInstrumentationBase.js";import{EMB_TYPES as t,KEY_EMB_TYPE as o,KEY_VIEW_NAME as r,KEY_EMB_INSTRUMENTATION as a}from"../../../constants/attributes.js";var s=/\(.*?\)/g,u=function(n){function u(e){var u=e.diag,i=e.shouldCleanupPathOptionsFromRouteName,d=void 0===i||i,_=n.call(this,{instrumentationName:"NavigationInstrumentation",instrumentationVersion:"1.0.0",diag:u,config:{}})||this;return _._shouldCleanupPathOptionsFromRouteName=!0,_._currentRoute=null,_._currentRouteSpan=null,_._instrumentationType=null,_._removeSessionStartedFn=null,_._removeSessionEndedFn=null,_.setInstrumentationType=function(e){_._instrumentationType=e},_.setCurrentRoute=function(e){var n;_._config.enabled&&e.url!==(null===(n=_._currentRoute)||void 0===n?void 0:n.url)&&(_._endRouteSpan(),_._startRouteSpan(e),_._currentRoute=e)},_._setupSessionListeners=function(){_._removeSessionStartedFn||(_._removeSessionStartedFn=_.sessionManager.addSessionStartedListener((function(){_._currentRoute&&!_._currentRouteSpan&&(_._diag.debug("Session started, starting route span."),_._startRouteSpan(_._currentRoute))}))),_._removeSessionEndedFn||(_._removeSessionEndedFn=_.sessionManager.addSessionEndedListener((function(){_._currentRouteSpan&&(_._diag.debug("Session ended, ending route span."),_._endRouteSpan())})))},_._cleanUpSessionListeners=function(){_._removeSessionStartedFn&&(_._removeSessionStartedFn(),_._removeSessionStartedFn=null),_._removeSessionEndedFn&&(_._removeSessionEndedFn(),_._removeSessionEndedFn=null)},_._startRouteSpan=function(e){var n;_._diag.debug("Starting route span for url: ".concat(e.url)),_._setupSessionListeners();var u=_._shouldCleanupPathOptionsFromRouteName?e.path.replace(s,""):e.path;return _._currentRouteSpan=_.tracer.startSpan(u,{attributes:(n={},n[o]=t.View,n[r]=u,n)}),_._instrumentationType&&_._currentRouteSpan.setAttribute(a,_._instrumentationType),_._currentRouteSpan},_._endRouteSpan=function(){_._currentRouteSpan&&_._currentRoute&&(_._diag.debug("Ending route span for url: ".concat(_._currentRoute.url)),_._currentRouteSpan.end(),_._currentRouteSpan=null)},_.enable=function(){_._diag.debug("NavigationInstrumentation enabled, listening for navigation events.")},_.disable=function(){_._cleanUpSessionListeners(),_.setConfig({enabled:!1}),_._diag.debug("NavigationInstrumentation disabled, stopped listening for navigation events.")},_._shouldCleanupPathOptionsFromRouteName=d,_._config.enabled&&_.enable(),_}return e(u,n),u}(n);export{u as NavigationInstrumentation};
//# sourceMappingURL=NavigationInstrumentation.js.map