@opencensus/web-all
Version:
OpenCensus Web All combines all the main OpenCensus Web packages to provide distributions for easy use in web applications via <script> tags.
2 lines • 16.6 kB
JavaScript
!function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=6)}([,,function(t,e,n){"use strict";n.r(e);var r,o,i,a,s=function(){function t(){}return t.prototype.publish=function(t){return Promise.resolve()},t.prototype.onStartSpan=function(t){},t.prototype.onEndSpan=function(t){},t}();!function(t){t[t.OK=0]="OK",t[t.CANCELLED=1]="CANCELLED",t[t.UNKNOWN=2]="UNKNOWN",t[t.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",t[t.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",t[t.NOT_FOUND=5]="NOT_FOUND",t[t.ALREADY_EXISTS=6]="ALREADY_EXISTS",t[t.PERMISSION_DENIED=7]="PERMISSION_DENIED",t[t.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",t[t.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",t[t.ABORTED=10]="ABORTED",t[t.OUT_OF_RANGE=11]="OUT_OF_RANGE",t[t.UNIMPLEMENTED=12]="UNIMPLEMENTED",t[t.INTERNAL=13]="INTERNAL",t[t.UNAVAILABLE=14]="UNAVAILABLE",t[t.DATA_LOSS=15]="DATA_LOSS",t[t.UNAUTHENTICATED=16]="UNAUTHENTICATED"}(r||(r={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.SENT=1]="SENT",t[t.RECEIVED=2]="RECEIVED"}(o||(o={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.SERVER=1]="SERVER",t[t.CLIENT=2]="CLIENT"}(i||(i={})),function(t){t[t.UNSPECIFIED=0]="UNSPECIFIED",t[t.CHILD_LINKED_SPAN=1]="CHILD_LINKED_SPAN",t[t.PARENT_LINKED_SPAN=2]="PARENT_LINKED_SPAN"}(a||(a={}));var u=8;function p(){return c()+c()}function c(){var t=window.crypto||window.msCrypto,e="",n=new Uint8Array(u);t.getRandomValues(n);for(var r=0;r<u;r++){var o=n[r].toString(16);1===o.length&&(e+="0"),e+=o}return e}var f=0;function d(){return performance.timeOrigin?performance.timeOrigin:(f||(f=Date.now()-performance.now()),f)}function h(t){return new Date(d()+t)}function l(t){var e=m(d()),n=e[0],r=e[1],o=m(t),i=o[0],a=m(r+o[1]),s=a[0],u=a[1];return""+new Date(n+i+s).toISOString().replace("Z","")+u.toFixed(6).substring(2)+"Z"}function m(t){var e=Math.floor(t);return[e,t-e]}var g,E="unnamed",S=function(){function t(t){void 0===t&&(t=c()),this.id=t,this.remoteParent=!1,this.parentSpanId="",this.traceId="",this.traceState="",this.name=E,this.kind=i.UNSPECIFIED,this.logger=console,this.status={code:r.OK},this.attributes={},this.annotations=[],this.messageEvents=[],this.links=[],this.startPerfTime=0,this.spans=[],this.droppedAttributesCount=0,this.droppedLinksCount=0,this.droppedAnnotationsCount=0,this.droppedMessageEventsCount=0,this.activeTraceParams={},this.started=!0,this.endPerfTime=0,this.numberOfChildrenLocal=0}return Object.defineProperty(t.prototype,"isRootSpan",{get:function(){return""===this.parentSpanId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"startTime",{get:function(){return h(this.startPerfTime)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"numberOfChildren",{get:function(){return this.numberOfChildrenLocal},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"endTime",{get:function(){return h(this.endPerfTime)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"ended",{get:function(){return this.endPerfTime>0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"duration",{get:function(){return this.endPerfTime-this.startPerfTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"spanContext",{get:function(){return{traceId:this.traceId,spanId:this.id,options:1,traceState:this.traceState}},enumerable:!0,configurable:!0}),t.prototype.allDescendants=function(){return this.spans.reduce(function(t,e){t.push(e);var n=e.allDescendants();return t=t.concat(n)},[])},t.prototype.startChildSpan=function(e){this.numberOfChildrenLocal++;var n=new t;return n.traceId=this.traceId,n.traceState=this.traceState,e&&e.name&&(n.name=e.name),e&&e.kind&&(n.kind=e.kind),n.start(),n.parentSpanId=this.id,this.spans.push(n),n},t.prototype.addAttribute=function(t,e){var n="object"==typeof e?JSON.stringify(e):e;this.attributes[t]=n},t.prototype.addAnnotation=function(t,e,n){void 0===e&&(e={}),void 0===n&&(n=performance.now()),this.annotations.push({description:t,attributes:e,timestamp:n})},t.prototype.addLink=function(t,e,n,r){void 0===r&&(r={}),this.links.push({traceId:t,spanId:e,type:n,attributes:r})},t.prototype.addMessageEvent=function(t,e,n,r,o){void 0===n&&(n=performance.now()),this.messageEvents.push({type:t,id:e,timestamp:n,uncompressedSize:r,compressedSize:o})},t.prototype.setStatus=function(t,e){this.status={code:t,message:e}},t.prototype.start=function(){this.startPerfTime=performance.now()},t.prototype.end=function(){0===this.endPerfTime&&(this.endPerfTime=performance.now())},t.prototype.truncate=function(){this.end()},t}(),v=(g=function(t,e){return(g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}g(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),y=function(t){function e(e,n){var r=t.call(this)||this;if(r.tracer=e,n){r.name=n.name,r.kind=n.kind||i.UNSPECIFIED;var o=n.spanContext;o&&(r.parentSpanId=o.spanId||"",r.traceId=o.traceId,r.traceState=o.traceState||"")}else r.traceId=p();return r}return v(e,t),e.prototype.start=function(){t.prototype.start.call(this),this.tracer.onStartSpan(this)},e.prototype.end=function(){t.prototype.end.call(this),this.tracer.onEndSpan(this)},e}(S),I=function(){function t(){}return t.prototype.extract=function(t){return null},t.prototype.inject=function(t,e){},t.prototype.generate=function(){return{traceId:p(),spanId:c()}},t}(),T=function(){function t(){this.description="always"}return t.prototype.shouldSample=function(t){return!0},t}(),b=new I,N=function(){function t(){this.sampler=new T,this.logger=console,this.propagation=b,this.eventListeners=[],this.active=!0,this.activeTraceParams={},this.config={}}return t.prototype.start=function(t){return this.logger=t.logger||console,this.propagation=t.propagation||b,this.config=t,this},t.prototype.stop=function(){return this},t.prototype.startRootSpan=function(t,e){var n=new y(this,t),r=this.config&&this.config.defaultAttributes;if(r)for(var o=0,i=Object.keys(r);o<i.length;o++){var a=i[o];n.addAttribute(a,r[a])}return n.start(),e(n)},t.prototype.onStartSpan=function(t){for(var e=0,n=this.eventListeners;e<n.length;e++){n[e].onStartSpan(t)}},t.prototype.onEndSpan=function(t){for(var e=0,n=this.eventListeners;e<n.length;e++){n[e].onEndSpan(t)}},t.prototype.registerSpanEventListener=function(t){this.eventListeners.push(t)},t.prototype.unregisterSpanEventListener=function(t){this.eventListeners=this.eventListeners.filter(function(e){return e!==t})},t.prototype.startChildSpan=function(t){var e=new S;t&&t.childOf&&(e=t.childOf);var n=e.startChildSpan(t),r=this.config&&this.config.defaultAttributes;if(r)for(var o=0,i=Object.keys(r);o<i.length;o++){var a=i[o];e.addAttribute(a,r[a])}return n},t.prototype.setCurrentRootSpan=function(t){},t}(),O=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),P=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.currentRootSpan=new y(e),e}return O(e,t),e.prototype.startRootSpan=function(e,n){var r=this;return t.prototype.startRootSpan.call(this,e,function(t){return r.currentRootSpan=t,n(t)})},e.prototype.clearCurrentTrace=function(){this.currentRootSpan=new y(this)},e.prototype.startChildSpan=function(e){return t.prototype.startChildSpan.call(this,Object.assign({childOf:this.currentRootSpan},e))},e.prototype.wrap=function(t){return t},e.prototype.wrapEmitter=function(t){},e}(N),A=new s,_=new(function(){function t(){this.tracer=new P,this.exporter=A,this.active=!0}return t.prototype.start=function(t){return this.tracer.start(t||{}),t&&t.exporter&&this.registerExporter(t.exporter),this},t.prototype.stop=function(){},t.prototype.registerExporter=function(t){return this.tracer.unregisterSpanEventListener(this.exporter),this.exporter=t,this.tracer.registerSpanEventListener(t),this},t.prototype.unregisterExporter=function(t){return this.registerExporter(A),this},t}()),w=1;var L=15e11;function D(t){return{value:t}}function C(t){for(var e=t.length,n="",r=0;r<e;r+=2){var o=t.substring(r,r+2),i=parseInt(o,16);n+=String.fromCharCode(i)}return btoa(n)}function R(t){if(!t||!t.length)return{};for(var e={},n=0,r=t.split(",");n<r.length;n++){var o=r[n].split("="),i=o[0],a=o[1];e[i]=a}return e}function x(t){for(var e,n,r={},o=0,i=Object.keys(t);o<i.length;o++){var a=i[o];r[a]=(e=t[a],n=void 0,"boolean"===(n=typeof e)?{boolValue:e}:"number"===n?{doubleValue:e}:{stringValue:D(String(e))})}return{attributeMap:r}}function k(t){return{time:U(t.timestamp),annotation:{description:D(t.description),attributes:x(t.attributes)}}}function U(t){return t>L?new Date(t).toISOString():l(t)}function j(t){return{time:U(t.timestamp),messageEvent:{id:t.id,type:t.type,uncompressedSize:t.uncompressedSize,compressedSize:t.compressedSize}}}function M(t){return{traceId:C(t.traceId),spanId:C(t.spanId),type:t.type,attributes:x(t.attributes)}}function z(t,e){return void 0===t?e.toISOString():l(t)}function F(t){return{traceId:C(t.traceId),spanId:C(t.id),tracestate:R(t.traceState),parentSpanId:C(t.parentSpanId),name:D(t.name),kind:t.kind,startTime:z(t.startPerfTime,t.startTime),endTime:z(t.endPerfTime,t.endTime),attributes:x(t.attributes),timeEvents:(n=t.annotations,r=t.messageEvents,{timeEvent:n.map(k).concat(r.map(j))}),links:(e=t.links,{link:e.map(M)}),status:t.status,sameProcessAsParentSpan:!t.remoteParent};var e,n,r}var B=function(){function t(t,e){this.exporter=t,this.config=e,this.queue=[]}return t.prototype.addToBuffer=function(t){var e=this;return this.queue.push(t),this.config.bufferSize&&this.queue.length>this.config.bufferSize?(this.flush(),this):(setTimeout(function(){e.queue.length&&e.flush()},this.config.bufferTimeout),this)},t.prototype.flush=function(){this.exporter.publish(this.queue),this.queue=[]},t}(),H=function(){function t(t){this.config=t,this.buffer=new B(this,t)}return t.prototype.publish=function(t){var e=new XMLHttpRequest;e.open("POST",this.config.agentEndpoint),e.setRequestHeader("Content-Type","application/json");var n=this.getExportSpansRequest(t);return e.send(JSON.stringify(n)),new Promise(function(t){e.onreadystatechange=function(){4===e.readyState&&t(e.status)}})},t.prototype.onStartSpan=function(t){},t.prototype.onEndSpan=function(t){this.buffer.addToBuffer(t)},t.prototype.getExportSpansRequest=function(t){for(var e,n,r=[],o=0,i=t;o<i.length;o++){var a=i[o];r=r.concat((n=void 0,(n=(e=a).spans.map(F)).unshift(F(e)),n))}return{spans:r,node:this.getNodeForExport()}},t.prototype.getNodeForExport=function(){return{identifier:{hostName:location.host},serviceInfo:{name:this.config.serviceName},libraryInfo:{language:10,exporterVersion:"0.0.1",coreLibraryVersion:"0.0.1"},attributes:this.config.attributes}},t}(),V=window;function q(t){var e=document.createElement("a");return e.href=t,e}var K="http.host",X="http.method",G="http.path",J="http.user_agent",W="http.url",Y="http.next_hop_protocol",Z="http.initiator_type",$="http.resp_size",Q="http.resp_encoded_body_size",tt="http.resp_decoded_body_size",et="nav.type",nt="long_task.attribution";function rt(t,e){for(var n=[],r=0,o=e;r<o.length;r++){var i=o[r],a=t[i];a&&n.push({timestamp:a,description:i,attributes:{}})}return n}var ot=["workerStart","fetchStart","domainLookupStart","domainLookupEnd","connectStart","connectEnd","secureConnectionStart","redirectStart","redirectEnd","requestStart","responseStart","responseEnd"];function it(t,e,n,r){var o=new S(r);o.traceId=e,o.parentSpanId=n;var a=q(t.name);return o.name=a.pathname,o.startPerfTime=t.startTime,o.kind=i.CLIENT,o.endPerfTime=t.responseEnd,o.attributes=function(t,e){var n={};n[W]=t.name,n[K]=e.host,n[G]=e.pathname,n[J]=navigator.userAgent,t.nextHopProtocol&&(n[Y]=t.nextHopProtocol);var r=t.initiatorType;r&&("xmlhttprequest"!==r&&"fetch"!==r&&(n[X]="GET"),n[Z]=r);t.transferSize&&(n[$]=t.transferSize);t.encodedBodySize&&(n[Q]=t.encodedBodySize);t.decodedBodySize&&(n[tt]=t.decodedBodySize);return n}(t,a),o.annotations=rt(t,ot),o}var at=["domLoading","domInteractive","domContentLoaded","domComplete","loadEventStart","loadEventEnd","unloadEventStart","unloadEventEnd"];function st(t,e,n,r){void 0===n&&(n=c()),void 0===r&&(r=p());var o=e.navigationTiming,a=o?o.name:location.href,s=q(a).pathname,u=new y(t,{name:"Nav."+s,spanContext:{traceId:r,spanId:""},kind:i.UNSPECIFIED});if(u.startPerfTime=0,u.annotations=function(t){var e=t.navigationTiming;if(!e)return[];for(var n=rt(e,at),r=0,o=t.paintTimings;r<o.length;r++){var i=o[r];n.push({timestamp:i.startTime,description:i.name,attributes:{}})}return n}(e),u.attributes[W]=a,u.attributes[J]=navigator.userAgent,o){u.endPerfTime=o.loadEventEnd,u.attributes[et]=o.type;var f=function(t,e,n,r,o){var i=it(t,n,r,o);return i.startPerfTime=t.fetchStart,i}(o,0,r,u.id,n);u.spans.push(f)}var d=e.resourceTimings.map(function(t){return it(t,r,u.id)}),h=e.longTaskTimings.map(function(t){return function(t,e,n){var r=new S;return r.traceId=e,r.parentSpanId=n,r.name="Long JS task",r.startPerfTime=t.startTime,r.endPerfTime=t.startTime+t.duration,r.attributes[nt]=JSON.stringify(t.attribution),r}(t,r,u.id)});return u.spans=u.spans.concat(d,h),u}var ut=0,pt=/^[\da-f]{2}-[\da-f]{32}-[\da-f]{16}-[\da-f]{2}$/;function ct(t){if(!t.match(pt))return null;var e=t.split("-"),n=e[1];return n.match(/^0*$/)?null:{traceId:n,spanId:e[2],options:parseInt(e[3],16)}}!function(){function t(){}t.prototype.extract=function(t){var e=t.getHeader("traceparent");if(!e)return null;var n=ct(Array.isArray(e)?e[0]:e);if(!n)return null;var r=t.getHeader("tracestate");return r&&(n.traceState=Array.isArray(r)?r.join(","):r),n},t.prototype.inject=function(t,e){t.setHeader("traceparent",function(t){return"00-"+t.traceId+"-"+t.spanId+"-0"+(t.options||ut).toString(16)}(e)),e.traceState&&t.setHeader("tracestate",e.traceState)},t.prototype.generate=function(){return{traceId:p(),spanId:c(),options:ut}}}();var ft=window,dt=1e-4;function ht(){var t=ft.ocSampleRate||dt;return{traceId:p(),spanId:c(),options:Math.random()<t?1:0}}var lt=window,mt=2e3,gt="/v1/trace";function Et(){setTimeout(function(){var t=function(){if(!ft.traceparent)return ht();var t=ct(ft.traceparent);return t||(console.log("Invalid traceparent: "+ft.traceparent),ht())}();if(function(t){var e=t.options;return!!e&&!!(e&w)}(t)){var e=function(){if(!window.performance)return{resourceTimings:[],longTaskTimings:[],paintTimings:[]};var t=window.performance,e=V.ocLt,n={resourceTimings:t.getEntriesByType("resource"),paintTimings:t.getEntriesByType("paint"),longTaskTimings:e?e.slice():[]},r=t.getEntriesByType("navigation");return r.length&&(n.navigationTiming=r[0]),n}(),n=st(_.tracer,e,t.spanId,t.traceId);window.performance&&(V.ocLt=[],performance.clearResourceTimings(),performance.clearMarks(),performance.clearMeasures()),_.tracer.onEndSpan(n)}},mt)}lt.ocAgent?(_.registerExporter(new H({agentEndpoint:""+lt.ocAgent+gt})),"complete"===document.readyState?Et():window.addEventListener("load",function(){Et()})):console.log("Not configured to export page load spans.")},function(t,e,n){"use strict";n.r(e);var r=window;function o(t){var e;(e=r.ocLt).push.apply(e,t.getEntries())}window.performance&&(performance.setResourceTimingBufferSize&&performance.setResourceTimingBufferSize(1e3),r.performance&&(r.PerformanceObserver&&new r.PerformanceObserver(o).observe({entryTypes:["longtask"]}),r.ocLt=[]))},,,function(t,e,n){"use strict";n.r(e);n(3),n(2)}]);
//# sourceMappingURL=initial-load-all.js.map