@picked/telemetry 0.0.1-dev.1787788898336 → 0.0.1-dev.1788925875333
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -17
- package/dist/cjs/index.js +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
# @picked/telemetry
|
|
2
2
|
|
|
3
|
-
A minimal OTLP/HTTP-JSON span emitter shared by the Picked SDK surfaces
|
|
4
|
-
client's telemetry plugin, `@picked/vite-plugin-picked` and `@picked/cli`.
|
|
5
|
-
|
|
6
|
-
It is deliberately not built on the OpenTelemetry SDKs. `@picked/client` has an 18 kB
|
|
7
|
-
budget for its main entry and `@opentelemetry/sdk-trace-web` plus an OTLP exporter is an
|
|
8
|
-
order of magnitude larger than the headroom, while on the Node side `@opentelemetry/sdk-node`
|
|
9
|
-
adds startup cost to `picked generate types`, which runs on every `vite dev`. The span set
|
|
10
|
-
across all three surfaces is a handful of known shapes, so the wire format is written out
|
|
11
|
-
directly.
|
|
3
|
+
A minimal OTLP/HTTP-JSON span emitter shared by the Picked SDK surfaces.
|
|
12
4
|
|
|
13
5
|
## Usage
|
|
14
6
|
|
|
@@ -44,11 +36,3 @@ await emitter.flush()
|
|
|
44
36
|
dropped rather than retried, which is what bounds the buffer on a long-lived page.
|
|
45
37
|
- **`fetch` with `keepalive`, never `sendBeacon`.** `sendBeacon` cannot set request headers,
|
|
46
38
|
and the ingest-channel marker has to travel on the request.
|
|
47
|
-
|
|
48
|
-
## Two details of the wire format worth knowing
|
|
49
|
-
|
|
50
|
-
64-bit integers are carried as **strings** in the proto3 JSON mapping, which is why
|
|
51
|
-
timestamps and integer attributes are rendered rather than passed through as numbers.
|
|
52
|
-
Nanoseconds since the epoch also sit far past `Number.MAX_SAFE_INTEGER`, so `toUnixNano`
|
|
53
|
-
scales the whole-millisecond part through `BigInt`; multiplying a millisecond float by 1e6
|
|
54
|
-
lands on a double whose neighbours are hundreds of nanoseconds apart.
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`@picked/telemetry`,t={unset:0,ok:1,error:2};function n(){return`0.0.1-dev.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`@picked/telemetry`,t={unset:0,ok:1,error:2};function n(){return`0.0.1-dev.1788925875333`}function r(e){return typeof e==`string`?{stringValue:e}:typeof e==`boolean`?{boolValue:e}:Number.isInteger(e)?{intValue:e.toString()}:{doubleValue:e}}function i(e){return Object.entries(e).map(([e,t])=>({key:e,value:r(t)}))}function a(e){return{traceId:e.traceId,spanId:e.spanId,...e.parentSpanId?{parentSpanId:e.parentSpanId}:{},name:e.name,kind:1,startTimeUnixNano:e.startTimeUnixNano,endTimeUnixNano:e.endTimeUnixNano,attributes:i(e.attributes),status:{code:t[e.status]}}}function o(t,r){return{resourceSpans:[{resource:{attributes:i(t)},scopeSpans:[{scope:{name:e,version:n()},spans:r.map(a)}]}]}}var s=`https://production.otel.picked.app/v1/traces`,c=50,l=3e3;function u(e){let t=e.endpoint??`https://production.otel.picked.app/v1/traces`,n=e.maxBatchSize??c,r=[];async function i(){if(r.length===0)return;let n=r;r=[];let i=globalThis.fetch;if(typeof i==`function`)try{await i(t,{method:`POST`,keepalive:!0,headers:{"Content-Type":`application/json`,...e.headers},body:JSON.stringify(o(e.resource,n)),signal:AbortSignal.timeout(l)})}catch{}}return{record:e=>{r.push(e),r.length>=n&&i()},flush:i,bufferedCount:()=>r.length}}var d=16,f=8;function p(e){let t=new Uint8Array(e);return crypto.getRandomValues(t),t.every(e=>e===0)&&(t[0]=1),t}function m(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}function h(){return m(p(d))}function g(){return m(p(f))}function _(e,t,n){return`00-${e}-${t}-${n?`01`:`00`}`}var v=1000000n;function y(e){let t=Math.trunc(e),n=Math.round((e-t)*Number(v));return(BigInt(t)*v+BigInt(n)).toString()}exports.DEFAULT_TELEMETRY_ENDPOINT=s,exports.createSpanId=g,exports.createTelemetryEmitter=u,exports.createTraceId=h,exports.formatTraceparent=_,exports.toUnixNano=y;
|
package/dist/esm/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var e = {
|
|
|
5
5
|
error: 2
|
|
6
6
|
};
|
|
7
7
|
function t() {
|
|
8
|
-
return "0.0.1-dev.
|
|
8
|
+
return "0.0.1-dev.1788925875333";
|
|
9
9
|
}
|
|
10
10
|
function n(e) {
|
|
11
11
|
return typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : Number.isInteger(e) ? { intValue: e.toString() } : { doubleValue: e };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/telemetry",
|
|
3
3
|
"description": "Minimal OTLP/HTTP-JSON span emitter shared by the Picked SDK surfaces",
|
|
4
|
-
"version": "0.0.1-dev.
|
|
4
|
+
"version": "0.0.1-dev.1788925875333",
|
|
5
5
|
"dependencies": {},
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@repo/eslint-config": "workspace:*",
|